コード例 #1
0
ファイル: statsd.py プロジェクト: amar266/gnocchi
 def treat_metric(self, metric_name, metric_type, value, sampling):
     metric_name += "|" + metric_type
     if metric_type == "ms":
         if sampling is not None:
             raise ValueError(
                 "Invalid sampling for ms: `%d`, should be none"
                 % sampling)
         self.times[metric_name] = storage.Measure(
             utils.dt_in_unix_ns(utils.utcnow()), value)
     elif metric_type == "g":
         if sampling is not None:
             raise ValueError(
                 "Invalid sampling for g: `%d`, should be none"
                 % sampling)
         self.gauges[metric_name] = storage.Measure(
             utils.dt_in_unix_ns(utils.utcnow()), value)
     elif metric_type == "c":
         sampling = 1 if sampling is None else sampling
         if metric_name in self.counters:
             current_value = self.counters[metric_name].value
         else:
             current_value = 0
         self.counters[metric_name] = storage.Measure(
             utils.dt_in_unix_ns(utils.utcnow()),
             current_value + (value * (1 / sampling)))
     # TODO(jd) Support "set" type
     # elif metric_type == "s":
     #     pass
     else:
         raise ValueError("Unknown metric type `%s'" % metric_type)
コード例 #2
0
ファイル: amqp1d.py プロジェクト: aneeshkp/gnocchi
    def treat_metric(self, host, metric_name, metric_type,
                     value):
        """Collectd.

        Statistics in collectd consist of a value list. A value list includes:
        Values, can be one of:
        Derive: used for values where a change in the value since it's last
        been read is of interest. Can be used to calculate and store a rate.
        Counter: similar to derive values, but take the possibility of a
        counter wrap around into consideration.
        Gauge: used for values that are stored as is.
        Absolute: used for counters that are reset after reading.

        """

        if metric_type == "absolute":
            if host not in self.absolute:
                self.absolute[host] = {}
            self.absolute[host][metric_name] = incoming.Measure(
                utils.dt_in_unix_ns(utils.utcnow()), value)
        elif metric_type == "gauge":
            if host not in self.gauges:
                self.gauges[host] = {}
            self.gauges[host][metric_name] = incoming.Measure(
                utils.dt_in_unix_ns(utils.utcnow()), value)
        elif metric_type == "counter" or metric_type == "derive":
            if host not in self.counters:
                self.counters[host] = {}
            self.counters[host][metric_name] = incoming.Measure(
                utils.dt_in_unix_ns(utils.utcnow()), value)
        else:
            raise ValueError("Unknown metric type '%s'" % metric_type)
コード例 #3
0
    def todo():
        metric = index.create_metric(
            uuid.uuid4(),
            creator=conf.creator,
            archive_policy_name=conf.archive_policy_name)

        for _ in six.moves.range(conf.batch_of_measures):
            measures = [
                incoming.Measure(
                    utils.dt_in_unix_ns(utils.utcnow()), random.random())
                for __ in six.moves.range(conf.measures_per_batch)]
            instore.add_measures(metric, measures)
コード例 #4
0
ファイル: amqp1d.py プロジェクト: yungjinzhou/gnocchi
 def on_message(self, event):
     json_message = ujson.loads(event.message.body)
     timestamp = utils.dt_in_unix_ns(utils.utcnow())
     measures_by_host_and_name = sorted(
         ((message["host"], self._serialize_identifier(index,
                                                       message), value)
          for message in json_message
          for index, value in enumerate(message["values"])))
     for (host,
          name), values in itertools.groupby(measures_by_host_and_name,
                                             key=lambda x: x[0:2]):
         measures = (incoming.Measure(timestamp, v[2]) for v in values)
         self.processor.add_measures(host, name, measures)
コード例 #5
0
    def treat_metric(self, resource_id, metric_name, metric_type, value,
                     sampling):

        if metric_type == "absolute":
            if sampling is not None:
                raise ValueError(
                    "Invalid sampling for ms: `%d`, should be none" % sampling)

            if resource_id not in self.absolute:
                self.absolute[resource_id] = collections.defaultdict(list)

            self.absolute[resource_id][metric_name] = storage.Measure(
                utils.dt_in_unix_ns(utils.utcnow()), value)
        elif metric_type == "guage":
            if sampling is not None:
                raise ValueError(
                    "Invalid sampling for g: `%d`, should be none" % sampling)
            if resource_id not in self.gauges:
                self.gauges[resource_id] = collections.defaultdict(list)

            self.gauges[resource_id][metric_name] = storage.Measure(
                utils.dt_in_unix_ns(utils.utcnow()), value)
        elif metric_type == "counter":
            sampling = 1 if sampling is None else sampling
            if resource_id not in self.counters:
                self.counters[resource_id] = collections.defaultdict(list)
            if metric_name in self.counters[resource_id]:
                current_value = self.counters[resource_id][metric_name].value
            else:
                current_value = 0
            self.counters[resource_id][metric_name] = storage.Measure(
                utils.dt_in_unix_ns(utils.utcnow()),
                current_value + (value * (1 / sampling)))
        # TODO(jd) Support "set" type
        # elif metric_type == "s":
        #     pass
        else:
            raise ValueError("Unknown metric type `%s'" % metric_type)
コード例 #6
0
    def _test_create_metric_and_data(self, data, spacing):
        metric = storage.Metric(uuid.uuid4(), self.archive_policies['medium'])
        start_time = utils.datetime_utc(2014, 1, 1, 12)
        incr = datetime.timedelta(seconds=spacing)
        measures = [
            storage.Measure(utils.dt_in_unix_ns(start_time + incr * n), val)
            for n, val in enumerate(data)
        ]
        self.index.create_metric(metric.id, str(uuid.uuid4()), 'medium')
        self.storage.incoming.add_measures(metric, measures)
        metrics = tests_utils.list_all_incoming_metrics(self.storage.incoming)
        self.storage.process_background_tasks(self.index, metrics, sync=True)

        return metric