Esempio n. 1
0
 def _publish_metrics(self):
     msg = MetricMessage()
     for metric in self._metrics:
         msg.append((metric.name, metric.aggs, metric.poll()))
     self.publish_message(msg)
     if self._on_publish is not None:
         self._on_publish(self)
Esempio n. 2
0
 def _publish_metrics(self):
     msg = MetricMessage()
     for metric in self._metrics:
         msg.append((metric.name, metric.aggs, metric.poll()))
     self.publish_message(msg)
     if self._on_publish is not None:
         self._on_publish(self)
Esempio n. 3
0
    def publish_metric(self, metric_name, aggregates, values):
        timestamp_buckets = {}
        for timestamp, value in values:
            ts_key = int(timestamp) / self.bucket_size
            ts_bucket = timestamp_buckets.get(ts_key)
            if ts_bucket is None:
                ts_bucket = timestamp_buckets[ts_key] = []
            ts_bucket.append((timestamp, value))

        for ts_key, ts_bucket in timestamp_buckets.iteritems():
            bucket = self.find_bucket(metric_name, ts_key)
            routing_key = self.ROUTING_KEY_TEMPLATE % bucket
            msg = MetricMessage()
            msg.append((metric_name, aggregates, ts_bucket))
            self.publish_message(msg, routing_key=routing_key)
Esempio n. 4
0
    def publish_metric(self, metric_name, aggregates, values):
        timestamp_buckets = {}
        for timestamp, value in values:
            ts_key = int(timestamp) / self.bucket_size
            ts_bucket = timestamp_buckets.get(ts_key)
            if ts_bucket is None:
                ts_bucket = timestamp_buckets[ts_key] = []
            ts_bucket.append((timestamp, value))

        for ts_key, ts_bucket in timestamp_buckets.iteritems():
            bucket = self.find_bucket(metric_name, ts_key)
            routing_key = self.ROUTING_KEY_TEMPLATE % bucket
            msg = MetricMessage()
            msg.append((metric_name, aggregates, ts_bucket))
            self.publish_message(msg, routing_key=routing_key)
Esempio n. 5
0
 def publish_metrics(self):
     """
     Publish all waiting metrics.
     """
     msg = MetricMessage()
     self._collect_oneshot_metrics(msg)
     self._collect_polled_metrics(msg)
     self.publish_message(msg)
     if self._on_publish is not None:
         self._on_publish(self)
Esempio n. 6
0
 def consume_message(self, vumi_message):
     msg = MetricMessage.from_dict(vumi_message.payload)
     for metric_name, aggregators, values in msg.datapoints():
         self.callback(metric_name, aggregators, values)
Esempio n. 7
0
 def recv_datapoints(self, exchange, queue):
     """Retrieve datapoints from a broker."""
     vumi_msgs = self._broker.get_messages(exchange, queue)
     msgs = [MetricMessage.from_dict(vm.payload) for vm in vumi_msgs]
     return [msg.datapoints() for msg in msgs]
Esempio n. 8
0
 def send_datapoints(self, exchange, queue, datapoints):
     """Publish datapoints to a broker."""
     msg = MetricMessage()
     msg.extend(datapoints)
     self._broker.publish_message(exchange, queue, msg)
Esempio n. 9
0
 def consume_message(self, vumi_message):
     msg = MetricMessage.from_dict(vumi_message.payload)
     for metric_name, aggregators, values in msg.datapoints():
         self.callback(metric_name, aggregators, values)
Esempio n. 10
0
 def publish_aggregate(self, metric_name, timestamp, value):
     # TODO: perhaps change interface to publish multiple metrics?
     msg = MetricMessage()
     msg.append((metric_name, (), [(timestamp, value)]))
     self.publish_message(msg)
Esempio n. 11
0
 def recv_datapoints(self, exchange, queue):
     """Retrieve datapoints from a broker."""
     contents = self._broker.get_dispatched(exchange, queue)
     vumi_msgs = [Message.from_json(content.body) for content in contents]
     msgs = [MetricMessage.from_dict(vm.payload) for vm in vumi_msgs]
     return [msg.datapoints() for msg in msgs]
Esempio n. 12
0
 def send_datapoints(self, exchange, queue, datapoints):
     """Publish datapoints to a broker."""
     msg = MetricMessage()
     msg.extend(datapoints)
     self._broker.publish_message(exchange, queue, msg)
Esempio n. 13
0
 def publish_aggregate(self, metric_name, timestamp, value):
     # TODO: perhaps change interface to publish multiple metrics?
     msg = MetricMessage()
     msg.append((metric_name, (), [(timestamp, value)]))
     self.publish_message(msg)
Esempio n. 14
0
 def recv_datapoints(self, exchange, queue):
     """Retrieve datapoints from a broker."""
     vumi_msgs = self._broker.get_messages(exchange, queue)
     msgs = [MetricMessage.from_dict(vm.payload) for vm in vumi_msgs]
     return [msg.datapoints() for msg in msgs]