def _flush(self):
        """
        Flush items from the queue. Removes up to `flush_count` items.
        """
        self._logger.debug(
            f"Flushing metrics queue {metrics_queue} (size:{metrics_queue.qsize()})"
        )
        timeseries = {}
        for _ in range(self._flush_count):
            if not metrics_queue.empty():
                key = hashlib.sha256()
                timestamp, metric, tags = metrics_queue.get()
                key.update(str(timestamp).encode())
                key.update(str(metric).encode())
                key.update(str(tags).encode())
                key = key.hexdigest()
                if key not in timeseries:
                    timeseries[key] = {
                        "metric": metric,
                        "type": 1,
                        "points": [{"timestamp": timestamp, "value": 0}],
                        "tags": tags,
                    }
                timeseries[key]["points"][0]["value"] += 1
            else:
                break
        if timeseries:
            payload = {"series": []}
            for key, serie in timeseries.items():
                payload["series"].append(serie)
            try:
                response = self._session.post(
                    MetricsFlusher.METRIC_ENDPOINT, json=payload
                )
            except Exception:
                self._logger.exception("Failed to send metrics to Datadog")
            if response.status_code == 202:
                self._logger.info("Successfully sent metrics to Datadog")
            else:
                self._logger.warning(
                    f"Failed to send metrics to Datadog: {response.reason}"
                )

        Flush items from the queue. Removes up to `flush_count` items.
        
plugins/events/public/datadog_metrics.py