Exemple #1
0
    def _get_dsd6_stats(self, cfg={}):
        port = cfg.get('dogstatsd6_stats_port', 5000)
        try:
            dsd6_agg_stats = get_expvar_stats('aggregator', port=port)
            dsd6_stats = get_expvar_stats('dogstatsd', port=port)
        except Exception as e:
            log.info("Unable to collect dogstatsd6 statistics: %s", e)
            return None

        if dsd6_stats is not None and dsd6_agg_stats is not None:
            packet_count = dsd6_stats.get("ServiceCheckPackets", 0) + \
                dsd6_stats.get("EventPackets", 0) + \
                dsd6_stats.get("MetricPackets", 0)
            flush_counts = dsd6_agg_stats.get("FlushCount", {})

            dsd6_status = DogstatsdStatus(
                flush_count=dsd6_agg_stats.get('NumberOfFlush', 0),
                packet_count=packet_count,
                packets_per_second="N/A",  # unavailable
                metric_count=flush_counts.get("Series", {}).get("LastFlush", 0),
                event_count=flush_counts.get("Events", {}).get("LastFlush", 0),
                service_check_count=flush_counts.get("ServiceChecks", {}).get("LastFlush", 0))

            return dsd6_status

        return None
Exemple #2
0
    def flush(self):
        try:
            self.flush_count += 1
            packets_per_second = self.metrics_aggregator.packets_per_second(
                self.interval)
            packet_count = self.metrics_aggregator.total_count

            metrics = self.metrics_aggregator.flush()
            count = len(metrics)
            if not count:
                logger.info("Flush #%s: No metrics to flush." %
                            self.flush_count)
            else:
                logger.info("Flush #%s: flushing %s metrics" %
                            (self.flush_count, count))
                self.submit(metrics)

            # Persist a status message.
            packet_count = self.metrics_aggregator.total_count
            DogstatsdStatus(flush_count=self.flush_count,
                            packet_count=packet_count,
                            packets_per_second=packets_per_second,
                            metric_count=count).persist()

        except:
            logger.exception("Error flushing metrics")
Exemple #3
0
    def flush(self):
        try:
            self.flush_count += 1
            self.log_count += 1
            packets_per_second = self.metrics_aggregator.packets_per_second(
                self.interval)
            packet_count = self.metrics_aggregator.total_count

            metrics = self.metrics_aggregator.flush()
            count = len(metrics)
            if self.flush_count % FLUSH_LOGGING_PERIOD == 0:
                self.log_count = 0
            if count:
                self.submit(metrics)

            events = self.metrics_aggregator.flush_events()
            event_count = len(events)
            if event_count:
                self.submit_events(events)

            service_checks = self.metrics_aggregator.flush_service_checks()
            service_check_count = len(service_checks)
            if service_check_count:
                self.submit_service_checks(service_checks)

            should_log = self.flush_count <= FLUSH_LOGGING_INITIAL or self.log_count <= FLUSH_LOGGING_COUNT
            log_func = log.info
            if not should_log:
                log_func = log.debug
            log_func(
                "Flush #%s: flushed %s metric%s, %s event%s, and %s service check run%s"
                % (self.flush_count, count, plural(count), event_count,
                   plural(event_count), service_check_count,
                   plural(service_check_count)))
            if self.flush_count == FLUSH_LOGGING_INITIAL:
                log.info(
                    "First flushes done, %s flushes will be logged every %s flushes."
                    % (FLUSH_LOGGING_COUNT, FLUSH_LOGGING_PERIOD))

            # Persist a status message.
            packet_count = self.metrics_aggregator.total_count
            DogstatsdStatus(
                flush_count=self.flush_count,
                packet_count=packet_count,
                packets_per_second=packets_per_second,
                metric_count=count,
                event_count=event_count,
                service_check_count=service_check_count,
            ).persist()

        except Exception:
            if self.finished.isSet():
                log.debug(
                    "Couldn't flush metrics, but that's expected as we're stopping"
                )
            else:
                log.exception("Error flushing metrics")
Exemple #4
0
    def flush(self):
        try:
            self.flush_count += 1
            packets_per_second = self.metrics_aggregator.packets_per_second(
                self.interval)
            packet_count = self.metrics_aggregator.total_count

            metrics = self.metrics_aggregator.flush()
            count = len(metrics)
            should_log = self.flush_count < LOGGING_INTERVAL or self.flush_count % LOGGING_INTERVAL == 0
            if not count:
                if should_log:
                    log.info("Flush #%s: No metrics to flush." %
                             self.flush_count)
            else:
                if should_log:
                    log.info("Flush #%s: flushing %s metrics" %
                             (self.flush_count, count))
                self.submit(metrics)

            events = self.metrics_aggregator.flush_events()
            event_count = len(events)
            if not event_count:
                if should_log:
                    log.info("Flush #%s: No events to flush." %
                             self.flush_count)
                else:
                    log.debug("Flush #%s: No events to flush." %
                              self.flush_count)
            else:
                if should_log:
                    log.info("Flush #%s: flushing %s events" %
                             (self.flush_count, len(events)))
                else:
                    log.debug("Flush #%s: flushing %s events" %
                              (self.flush_count, len(events)))
                self.submit_events(events)

            # Persist a status message.
            packet_count = self.metrics_aggregator.total_count
            DogstatsdStatus(
                flush_count=self.flush_count,
                packet_count=packet_count,
                packets_per_second=packets_per_second,
                metric_count=count,
                event_count=event_count,
            ).persist()

        except Exception, e:
            log.exception("Error flushing metrics")
Exemple #5
0
    def run(self):

        log.info("Reporting to %s every %ss" % (self.api_host, self.interval))
        log.debug("Watchdog enabled: %s" % bool(self.watchdog))

        # Persist a start-up message.
        DogstatsdStatus().persist()

        while not self.finished.isSet():  # Use camel case isSet for 2.4 support.
            self.finished.wait(self.interval)
            self.metrics_aggregator.send_packet_count('datadog.dogstatsd.packet.count')
            self.flush()
            if self.watchdog:
                self.watchdog.reset()

        # Clean up the status messages.
        log.debug("Stopped reporter")
        DogstatsdStatus.remove_latest_status()
Exemple #6
0
    def flush(self):
        try:
            self.flush_count += 1
            self.log_count += 1
            packets_per_second = self.metrics_aggregator.packets_per_second(
                self.interval)
            packet_count = self.metrics_aggregator.total_count

            metrics = self.metrics_aggregator.flush()
            count = len(metrics)
            if self.flush_count % FLUSH_LOGGING_PERIOD == 0:
                self.log_count = 0
            if count:
                self.submit(metrics)

            events = self.metrics_aggregator.flush_events()
            event_count = len(events)
            if event_count:
                self.submit_events(events)

            should_log = self.flush_count <= FLUSH_LOGGING_INITIAL or self.log_count <= FLUSH_LOGGING_COUNT
            log_func = log.info
            if not should_log:
                log_func = log.debug
            log_func("Flush #%s: flushed %s metric%s and %s event%s" %
                     (self.flush_count, count, plural(count), event_count,
                      plural(event_count)))
            if self.flush_count == FLUSH_LOGGING_INITIAL:
                log.info(
                    "First flushes done, %s flushes will be logged every %s flushes."
                    % (FLUSH_LOGGING_COUNT, FLUSH_LOGGING_PERIOD))

            # Persist a status message.
            packet_count = self.metrics_aggregator.total_count
            DogstatsdStatus(
                flush_count=self.flush_count,
                packet_count=packet_count,
                packets_per_second=packets_per_second,
                metric_count=count,
                event_count=event_count,
            ).persist()

        except Exception, e:
            log.exception("Error flushing metrics")