Example #1
0
class HealthMonitor(MeteringDataMonitorBase):
    """Object processing metering data and validating them against defined rules

        Object connects publisher (ex. Queue - RabbitMq), pollsters (CPU, Disk, Network).
    """
    HEALTH_MONITOR_TOPIC = "health.topic"

    def __init__(self, context):
        """Initialize HealthMonitor

            :param context: pollsters and queuePublisher context
        """
        super(HealthMonitor, self).__init__(context)
        self.publisher = QueuePublisher(self.context, {QueuePublisher.QUEUE_TOPIC_ARG: self.HEALTH_MONITOR_TOPIC})

        def alert_message_from_data(data):
            #TODO: Implement
            pass

        self.publisher.message_from_data = alert_message_from_data
        pass

    def _periodic_refresh(self):
        """Foreach pollsters and fetch counters"""
        # TODO: Should I define different intervals for each pollster?
        for name, pollster in self.pollsters:
            self._process_metering_data(name, pollster.get_counter())

    def _process_metering_data(self, name, counter):
        """Check counters and rules. Send alert if it's needed.

            :param name: pollster's name
            :param counter: object with data collected by pollster
        """

        alert = self._check_constrains(name, counter)
        if alert:
            self._send_alert(alert)

            # Pass data to local database? Count Average, Min/Max etc...

    def _check_constrains(self, name, counter):
        """Check constrains and generate proper alert"""
        #TODO: Implement
        pass

    def _init_alerts(self):
        """Setup constrains"""
        #TODO: Implement
        pass

    def _send_alert(self, alert):
        """Send/Publish alert message"""
        self.publisher.publish_data(alert)
Example #2
0
class BillingMonitor(MeteringDataMonitorBase):
    """Simple billing processor. Pulls metering data from pollsters and sends them through publisher (ex. RabbitMq)
    """

    def __init__(self, context):
        super(BillingMonitor, self).__init__(context)
        self.publisher = QueuePublisher(self.context, {QueuePublisher.QUEUE_TOPIC_ARG: cfg.CONF.metering_topic})

    def periodic_tasks(self, context, raise_on_error=False):
        """Tasks to be run at a periodic interval."""
        for name, pollster in self.pollsters:
            try:
                LOG.info('polling %s', name)
                for counter in pollster.get_counters(self, context):
                    LOG.info('COUNTER: %s', counter)
                    self.publisher.publish_data(counter)
            except Exception as err:
                LOG.warning('Continuing after error from %s: %s', name, err)
                LOG.exception(err)
Example #3
0
    def test_publish_data(self):
        publisher = QueuePublisher(self.ctx)
        publisher.init_publisher(queue_topic='myTopic')

        TEST_COUNTER = counter.Counter(source='src',
            type='typ',
            volume=1,
            user_id='user',
            project_id='project',
            resource_id=2,
            timestamp='today',
            duration=3,
            resource_metadata={'key': 'value'},
        )

        publisher.publish_data(TEST_COUNTER, "message")

        assert len(self.notifications) == 2
        self.notifications = []
Example #4
0
    def __init__(self, context):
        """Initialize HealthMonitor

            :param context: pollsters and queuePublisher context
        """
        super(HealthMonitor, self).__init__(context)
        self.publisher = QueuePublisher(self.context, {QueuePublisher.QUEUE_TOPIC_ARG: self.HEALTH_MONITOR_TOPIC})

        def alert_message_from_data(data):
            #TODO: Implement
            pass

        self.publisher.message_from_data = alert_message_from_data
        pass
Example #5
0
 def __init__(self, context):
     super(BillingMonitor, self).__init__(context)
     self.publisher = QueuePublisher(self.context, {QueuePublisher.QUEUE_TOPIC_ARG: cfg.CONF.metering_topic})