Exemplo n.º 1
0
    def _submit_metric(self, mtype, name, value, tags=None, hostname=None, device_name=None, raw=False):
        # type: (int, str, float, Sequence[str], str, str, bool) -> None
        if value is None:
            # ignore metric sample
            return

        tags = self._normalize_tags_type(tags or [], device_name, name)
        if hostname is None:
            hostname = ''

        if self.metric_limiter:
            if mtype in ONE_PER_CONTEXT_METRIC_TYPES:
                # Fast path for gauges, rates, monotonic counters, assume one set of tags per call
                if self.metric_limiter.is_reached():
                    return
            else:
                # Other metric types have a legit use case for several calls per set of tags, track unique sets of tags
                context = self._context_uid(mtype, name, tags, hostname)
                if self.metric_limiter.is_reached(context):
                    return

        try:
            value = float(value)
        except ValueError:
            err_msg = 'Metric: {} has non float value: {}. Only float values can be submitted as metrics.'.format(
                repr(name), repr(value)
            )
            if using_stub_aggregator:
                raise ValueError(err_msg)
            self.warning(err_msg)
            return

        aggregator.submit_metric(self, self.check_id, mtype, self._format_namespace(name, raw), value, tags, hostname)
Exemplo n.º 2
0
    def _submit_metric(self,
                       mtype,
                       name,
                       value,
                       tags=None,
                       hostname=None,
                       device_name=None):
        if value is None:
            # ignore metric sample
            return

        tags = self._normalize_tags(tags, device_name)
        if hostname is None:
            hostname = b''

        if self.metric_limiter:
            if mtype in ONE_PER_CONTEXT_METRIC_TYPES:
                # Fast path for gauges, rates, monotonic counters, assume one context per call
                if self.metric_limiter.is_reached():
                    return
            else:
                # Other metric types have a legit use case for several calls per context, track unique contexts
                context = self._context_uid(mtype, name, tags, hostname)
                if self.metric_limiter.is_reached(context):
                    return

        aggregator.submit_metric(self,
                                 self.check_id, mtype, ensure_bytes(name),
                                 float(value), tags, hostname)
Exemplo n.º 3
0
    def _submit_metric(self, mtype, name, value, tags=None, hostname=None, device_name=None):
        if value is None:
            # ignore metric sample
            return

        tags = self._normalize_tags(tags, device_name)
        if hostname is None:
            hostname = ""

        aggregator.submit_metric(self, self.check_id, mtype, name, float(value), tags, hostname)
Exemplo n.º 4
0
    def _submit_metric(self, mtype, name, value, tags=None, hostname=None, device_name=None):
        if value is None:
            # ignore metric sample
            return

        tags = self._normalize_tags(tags, device_name)
        if hostname is None:
            hostname = ""

        aggregator.submit_metric(self, self.check_id, mtype, name, float(value), tags, hostname)
Exemplo n.º 5
0
    def _submit_metric(self,
                       mtype,
                       name,
                       value,
                       tags=None,
                       hostname=None,
                       device_name=None):
        if value is None:
            # ignore metric sample
            return

        tags = self._normalize_tags(tags, device_name)
        if hostname is None:
            hostname = b''

        if self.metric_limiter:
            if mtype in ONE_PER_CONTEXT_METRIC_TYPES:
                # Fast path for gauges, rates, monotonic counters, assume one set of tags per call
                if self.metric_limiter.is_reached():
                    return
            else:
                # Other metric types have a legit use case for several calls per set of tags, track unique sets of tags
                context = self._context_uid(mtype, name, tags, hostname)
                if self.metric_limiter.is_reached(context):
                    return

        try:
            value = float(value)
        except ValueError:
            err_msg = "Metric: {} has non float value: {}. Only float values can be submitted as metrics".format(
                name, value)
            if using_stub_aggregator:
                raise ValueError(err_msg)
            self.warning(err_msg)
            return

        aggregator.submit_metric(self, self.check_id, mtype,
                                 ensure_bytes(name), value, tags, hostname)
Exemplo n.º 6
0
# Unless explicitly stated otherwise all files in this repository are licensed
# under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2019-present Datadog, Inc.
from __future__ import print_function

import aggregator
import tagger

if __name__ == "__main__":
    aggregator.submit_metric(None, 'id', aggregator.GAUGE, 'name', -99.0,
                             ['foo', 'bar'], 'myhost')
    print("tags returned by tagger: %s\n" % tagger.get_tags("21", True))