Esempio n. 1
0
    def get(self, kind):
        templist = []

        # the current 30 seconds
        templist += EventTrackQueue.take_current_snapshot()
        # the already stocked by side, until Stats dump them in 1hour
        templist += State.RecentEventQ

        templist.sort(key=operator.itemgetter('id'))

        if kind == 'details':
            return templist

        return self.get_summary(templist)
Esempio n. 2
0
    def get(self, kind):
        templist = []

        # the current 30 seconds
        templist += EventTrackQueue.take_current_snapshot()
        # the already stocked by side, until Stats dump them in 1hour
        templist += GLSettings.RecentEventQ

        templist.sort(key=operator.itemgetter('id'))

        if kind == 'details':
            self.finish(templist)
        else:  # kind == 'summary':
            self.finish(self.get_summary(templist))
    def get(self, kind):
        templist = []

        # the current 30 seconds
        templist += EventTrackQueue.take_current_snapshot()
        # the already stocked by side, until Stats dump them in 1hour
        templist += GLSettings.RecentEventQ

        templist.sort(key=operator.itemgetter('id'))

        if kind == 'details':
            self.finish(templist)
        else:  # kind == 'summary':
            self.finish(self.get_summary(templist))
Esempio n. 4
0
    def compute_activity_level(self):
        """
        This function update the Alarm level.

        """
        self.number_of_anomalies = 0

        current_event_matrix = {}

        requests_timing = []

        for _, event_obj in EventTrackQueue.iteritems():
            current_event_matrix.setdefault(event_obj.event_type, 0)
            current_event_matrix[event_obj.event_type] += 1
            requests_timing.append(event_obj.request_time)

        if len(requests_timing) > 2:
            log.info("In latest %d seconds: worst RTT %f, best %f" %
                     (10, round(max(requests_timing),
                                2), round(min(requests_timing), 2)))

        for event_name, threshold in self.ANOMALY_MAP.iteritems():
            if event_name in current_event_matrix:
                if current_event_matrix[event_name] > threshold:
                    self.number_of_anomalies += 1
                else:
                    log.debug(
                        "[compute_activity_level] %s %d < %d: it's OK (Anomalies recorded so far %d)"
                        % (event_name, current_event_matrix[event_name],
                           threshold, self.number_of_anomalies))

        previous_activity_sl = self.stress_levels['activity']

        # Behavior: once the activity has reach a peek, the stress level
        # is raised at RED (two), and then is decremented at YELLOW (one) in the
        # next evaluation.

        if self.number_of_anomalies >= 2:
            report_function = log.msg
            self.stress_levels['activity'] = 2
        elif self.number_of_anomalies == 1:
            report_function = log.info
            self.stress_levels['activity'] = 1
        else:
            report_function = log.debug
            self.stress_levels['activity'] = 0

        # slow downgrade, if something has triggered a two, next step to 1
        if previous_activity_sl == 2 and not self.stress_levels['activity']:
            self.stress_levels['activity'] = 1

        # if there are some anomaly or we're nearby, record it.
        if self.number_of_anomalies >= 1 or self.stress_levels['activity'] >= 1:
            update_AnomalyQ(current_event_matrix,
                            self.stress_levels['activity'])

        if previous_activity_sl or self.stress_levels['activity']:
            report_function(
                "in Activity stress level switch from %d => %d" %
                (previous_activity_sl, self.stress_levels['activity']))

        yield self.generate_admin_alert_mail(current_event_matrix)

        ret = self.stress_levels['activity'] - previous_activity_sl

        defer.returnValue(ret if ret > 0 else 0)
Esempio n. 5
0
    def compute_activity_level(self):
        """
        This function update the Alarm level.

        """
        self.number_of_anomalies = 0

        current_event_matrix = {}

        requests_timing = []

        for _, event_obj in EventTrackQueue.iteritems():
            current_event_matrix.setdefault(event_obj.event_type, 0)
            current_event_matrix[event_obj.event_type] += 1
            requests_timing.append(event_obj.request_time)

        if len(requests_timing) > 2:
            log.info("In latest %d seconds: worst RTT %f, best %f" %
                     (10,
                      round(max(requests_timing), 2),
                      round(min(requests_timing), 2)))

        for event_name, threshold in ANOMALY_MAP.iteritems():
            if event_name in current_event_matrix:
                if current_event_matrix[event_name] > threshold:
                    self.number_of_anomalies += 1
                else:
                    log.debug("[compute_activity_level] %s %d < %d: it's OK (Anomalies recorded so far %d)" %
                              (event_name,
                               current_event_matrix[event_name],
                               threshold, self.number_of_anomalies))

        previous_activity_sl = self.stress_levels['activity']

        # Behavior: once the activity has reach a peek, the stress level
        # is raised at RED (two), and then is decremented at YELLOW (one) in the
        # next evaluation.

        if self.number_of_anomalies >= 2:
            report_function = log.msg
            self.stress_levels['activity'] = 2
        elif self.number_of_anomalies == 1:
            report_function = log.info
            self.stress_levels['activity'] = 1
        else:
            report_function = log.debug
            self.stress_levels['activity'] = 0

        # slow downgrade, if something has triggered a two, next step to 1
        if previous_activity_sl == 2 and not self.stress_levels['activity']:
            self.stress_levels['activity'] = 1

        # if there are some anomaly or we're nearby, record it.
        if self.number_of_anomalies >= 1 or self.stress_levels['activity'] >= 1:
            update_AnomalyQ(current_event_matrix, self.stress_levels['activity'])

        if previous_activity_sl or self.stress_levels['activity']:
            report_function("in Activity stress level switch from %d => %d" %
                            (previous_activity_sl,
                             self.stress_levels['activity']))


        yield self.generate_admin_alert_mail(current_event_matrix)

        ret = self.stress_levels['activity'] - previous_activity_sl

        defer.returnValue(ret if ret > 0 else 0)