Example #1
0
    def run_single_check(self, check):
        """Run a single check

        returns number of measurement collected, collection time
        """

        sub_timer = util.Timer()
        count = 0
        log.debug("Running plugin %s" % check.name)
        try:

            # Run the check.
            check.run()

            current_check_metrics = check.get_metrics()

            # Emit the metrics after each check
            self._emit(current_check_metrics)

            # Save the status of the check.
            count += len(current_check_metrics)

        except Exception:
            log.exception("Error running plugin %s" % check.name)

        sub_collect_duration = sub_timer.step()
        sub_collect_duration_mills = sub_collect_duration * 1000
        log.debug(
            "Finished plugin %s run. Collection time: %.2fms %d Metrics." %
            (check.name, round(sub_collect_duration_mills, 2), count))
        if sub_collect_duration > util.get_sub_collection_warn():
            log.warn("Collection time for check %s is high: %.2fs." %
                     (check.name, round(sub_collect_duration, 2)))
        return count, sub_collect_duration_mills
Example #2
0
    def run_checks_d(self):
        """Run defined checks_d checks.

        returns a list of Measurements.
        """
        sub_timer = util.Timer()
        measurements = 0
        for check in self.initialized_checks_d:
            if not self.continue_running:
                return
            log.debug("Running check %s" % check.name)
            try:
                # Run the check.
                check.run()

                current_check_metrics = check.get_metrics()

                # Emit the metrics after each check
                self._emit(current_check_metrics)

                # Save the status of the check.
                measurements += len(current_check_metrics)

            except Exception:
                log.exception("Error running check %s" % check.name)

            sub_collect_duration = sub_timer.step()
            sub_collect_duration_mills = sub_collect_duration * 1000
            log.debug("Finished run check %s. Collection time: %.2fms." % (
                check.name, round(sub_collect_duration_mills, 2)))
            if sub_collect_duration > util.get_sub_collection_warn():
                log.warn("Collection time for check %s is high: %.2fs." % (
                    check.name, round(sub_collect_duration, 2)))

        return measurements
Example #3
0
    def run_single_check(self, check):
        """Run a single check

        returns number of measurement collected, colleciton time
        """

        sub_timer = util.Timer()
        count = 0
        log.debug("Running plugin %s" % check.name)
        try:

            # Run the check.
            check.run()

            current_check_metrics = check.get_metrics()

            # Emit the metrics after each check
            self._emit(current_check_metrics)

            # Save the status of the check.
            count += len(current_check_metrics)

        except Exception:
            log.exception("Error running plugin %s" % check.name)

        sub_collect_duration = sub_timer.step()
        sub_collect_duration_mills = sub_collect_duration * 1000
        log.debug("Finished plugin %s run. Collection time: %.2fms %d Metrics." % (
                  check.name, round(sub_collect_duration_mills, 2), count))
        if sub_collect_duration > util.get_sub_collection_warn():
            log.warn("Collection time for check %s is high: %.2fs." % (
                     check.name, round(sub_collect_duration, 2)))
        return count, sub_collect_duration_mills
Example #4
0
    def run_checks_d(self):
        """Run defined checks_d checks.

        returns a list of Measurements, a dictionary of events and a list of check statuses.
        """
        sub_timer = util.Timer()
        measurements = []
        events = {}
        check_statuses = []
        for check in self.initialized_checks_d:
            if not self.continue_running:
                return
            log.debug("Running check %s" % check.name)
            instance_statuses = []
            metric_count = 0
            event_count = 0
            try:
                # Run the check.
                instance_statuses = check.run()

                # Collect the metrics and events.
                current_check_metrics = check.get_metrics()
                current_check_events = check.get_events()

                # Save them for the payload.
                measurements.extend(current_check_metrics)
                if current_check_events:
                    if check.name not in events:
                        events[check.name] = current_check_events
                    else:
                        events[check.name] += current_check_events

                # Save the status of the check.
                metric_count = len(current_check_metrics)
                event_count = len(current_check_events)
            except Exception:
                log.exception("Error running check %s" % check.name)

            status_check = check_status.CheckStatus(check.name, instance_statuses, metric_count, event_count,
                                                    library_versions=check.get_library_info())
            check_statuses.append(status_check)
            sub_collect_duration = sub_timer.step()
            sub_collect_duration_mills = sub_collect_duration * 1000
            log.debug("Finished run check %s. Collection time: %.2fms." % (
                check.name, round(sub_collect_duration_mills, 2)))
            if sub_collect_duration > util.get_sub_collection_warn():
                log.warn("Collection time for check %s is high: %.2fs." % (
                    check.name, round(sub_collect_duration, 2)))

        for check_name, info in self.init_failed_checks_d.iteritems():
            if not self.continue_running:
                return
            status_check = check_status.CheckStatus(check_name, None, None, None,
                                                    init_failed_error=info['error'],
                                                    init_failed_traceback=info['traceback'])
            check_statuses.append(status_check)

        return measurements, events, check_statuses