Beispiel #1
0
  def __append_timeseries_point(
        self, service, name,
        instance, metric_metadata, service_metadata, result):
    """Creates a post payload for a DataDog time series data point.

       See http://docs.datadoghq.com/api/?lang=python#metrics-post.

    Args:
      service: [string] The name of the service that the metric is from.
      name: [string] The name of the metric coming from the service.
      instance: [dict] The spectator entry for a specific metric value
         for a specific tag binding instance that we're going to append.
      metric_metadata: [dict] The spectator JSON object for the metric
         is used to get the kind and possibly other metadata.
      result: [list] The result list to append all the time series messages to.
    """
    # In practice this converts a Spinnaker Timer into either
    # <name>__count or <name>__totalTime and removes the "statistic" tag.
    name, tags = spectator_client.normalize_name_and_tags(
        name, instance, metric_metadata)
    if tags is None:
      return  # ignore metrics that had no tags because these are bogus.

    result.append({
        'metric': '{service}.{name}'.format(service=service, name=name),
        'host': service_metadata['__host'],
        'points': [(elem['t'] / 1000, elem['v'])
                   for elem in instance['values']],
        'tags': ['{0}:{1}'.format(tag['key'], tag['value']) for tag in tags]
    })
Beispiel #2
0
  def __append_timeseries_point(
        self, service, name,
        instance, metric_metadata, service_metadata, result):
    """Creates a post payload for a DataDog time series data point.

       See http://docs.datadoghq.com/api/?lang=python#metrics-post.

    Args:
      service: [string] The name of the service that the metric is from.
      name: [string] The name of the metric coming from the service.
      instance: [dict] The spectator entry for a specific metric value
         for a specific tag binding instance that we're going to append.
      metric_metadata: [dict] The spectator JSON object for the metric
         is used to get the kind and possibly other metadata.
      result: [list] The result list to append all the time series messages to.
    """
    # In practice this converts a Spinnaker Timer into either
    # <name>__count or <name>__totalTime and removes the "statistic" tag.
    name, tags = spectator_client.normalize_name_and_tags(
        name, instance, metric_metadata)
    if tags is None:
      return  # ignore metrics that had no tags because these are bogus.

    result.append({
        'metric': '{service}.{name}'.format(service=service, name=name),
        'host': service_metadata['host'],
        'points': [(elem['t'] / 1000, elem['v'])
                   for elem in instance['values']],
        'tags': ['{0}:{1}'.format(tag['key'], tag['value']) for tag in tags]
    })
  def add_metric_to_timeseries(self, service, name, instance,
                               metric_metadata, service_metadata, result):
    name, tags = spectator_client.normalize_name_and_tags(
        name, instance, metric_metadata)
    if tags is None:
      return

    metric = {
      'type': self.metric_type(service, name),
      'labels': {tag['key']: tag['value'] for tag in tags}
    }

    points = [{'interval': {'endTime': self.millis_to_time(e['t'])},
               'value': {'doubleValue': e['v']}}
              for e in instance['values']]

    if metric_metadata['kind'] in ['Counter', 'Timer']:
      # TODO(ewiseblatt): 20161115
      # startTime is in a newer spectator version that is not yet
      # available all over.
      start_time = self.millis_to_time(service_metadata.get('startTime', 0))
      metric_kind = 'CUMULATIVE'
      for elem in points:
        elem['interval']['startTime'] = start_time
    else:
      metric_kind = 'GAUGE'

    result.append({
        'metric': metric,
        'resource': self.monitored_resource,
        'metricKind': metric_kind,
        'valueType': 'DOUBLE',
        'points': points
        })
Beispiel #4
0
 def dump(self, service, name, instance, metric_data, service_data):
   # pylint: disable=unused-argiment
   name, tags = spectator_client.normalize_name_and_tags(
       name, instance, metric_data)
   if tags is None:
     print 'IGNORE {0}.{1}'.format(service, name)
   else:
     print '{0}.{1} {2} {3}'.format(
         service, name,
         [(tag['key'], tag['value']) for tag in tags],
         instance['values'])
    def add_metric_to_timeseries(self, service, name, instance,
                                 metric_metadata, service_metadata, result):
        name, tags = spectator_client.normalize_name_and_tags(
            name, instance, metric_metadata)
        if tags is None:
            return

        metric = {
            'type': self.metric_type(service, name),
            'labels':
            {tag['key']: self.TAG_VALUE_FUNC(tag['value'])
             for tag in tags}
        }
        if self.__add_source_tag:
            metric['labels']['InstanceSrc'] = '{host}:{port}'.format(
                host=service_metadata['__host'],
                port=service_metadata['__port'])

        points = [{
            'interval': {
                'endTime': self.millis_to_time(e['t'])
            },
            'value': {
                'doubleValue': e['v']
            }
        } for e in instance['values']]

        primitive_kind = spectator_client.determine_primitive_kind(
            metric_metadata['kind'])
        if primitive_kind == spectator_client.GAUGE_PRIMITIVE_KIND:
            metric_kind = 'GAUGE'
        else:
            metric_kind = 'CUMULATIVE'
            start_time = self.millis_to_time(
                service_metadata.get('startTime', 0))
            for elem in points:
                elem['interval']['startTime'] = start_time

        result.append({
            'metric':
            metric,
            'resource':
            self.get_monitored_resource(service, service_metadata),
            'metricKind':
            metric_kind,
            'valueType':
            'DOUBLE',
            'points':
            points
        })
    def __collect_instance_info(self, service, name, instance, metric_metadata,
                                service_metadata, service_to_name_to_info):
        """Creates an InstanceRecord for the given metric sample instance.

       This record is an internal structure that will be used to feed the
       Prometheus client library API. We need to see all the different time
       series for a given metric before we can form the payload so that we
       can anticipate all the labels we are going to need each prometheus
       instance needs the same labels present, but spectator did not.

    Args:
      service: [string] The name of the service that the metric is from.
      name: [string] The name of the metric coming from the service.
      instance: [dict] The spectator entry for a specific metric value
         for a specific tag binding instance that we're going to append.
      metric_metadata: [dict] The spectator JSON object for the metric
         is used to get the kind and possibly other metadata.
      service_to_name_to_info: [dict] A dictionary keyed by service to
        A dictionary mapping metric names to MetricInfo being built.
    """
        # In practice this converts a Spinnaker Timer into either
        # <name>__count or <name>__totalTime and removes the "statistic" tag.
        name, tags = spectator_client.normalize_name_and_tags(
            name, instance, metric_metadata)
        if tags is None:
            return  # ignore metrics that had no tags because these are bogus.

        record = InstanceRecord(
            service, '{0}:{1}'.format(service_metadata['__host'],
                                      service_metadata['__port']), tags,
            instance)

        name_to_info = service_to_name_to_info.get(service)
        if name_to_info is None:
            name_to_info = {}
            service_to_name_to_info[service] = name_to_info

        tag_names = set([tag['key'] for tag in tags])
        info = name_to_info.get(name)
        if info is None:
            info = MetricInfo(metric_metadata['kind'], tag_names, [record])
            name_to_info[name] = info
            return

        info.records.append(record)
        info.tags.update(tag_names)
    def add_metric_to_timeseries(self, service, name, instance,
                                 metric_metadata, service_metadata, result):
        name, tags = spectator_client.normalize_name_and_tags(
            name, instance, metric_metadata)
        if tags is None:
            return

        metric = {
            'type': self.metric_type(service, name),
            'labels': {tag['key']: tag['value']
                       for tag in tags}
        }
        if self.__add_source_tag:
            metric['labels']['InstanceSrc'] = '{host}:{port}'.format(
                host=service_metadata['__host'],
                port=service_metadata['__port'])

        points = [{
            'interval': {
                'endTime': self.millis_to_time(e['t'])
            },
            'value': {
                'doubleValue': e['v']
            }
        } for e in instance['values']]

        if metric_metadata['kind'] in ['Counter', 'Timer']:
            # TODO(ewiseblatt): 20161115
            # startTime is in a newer spectator version that is not yet
            # available all over.
            start_time = self.millis_to_time(
                service_metadata.get('startTime', 0))
            metric_kind = 'CUMULATIVE'
            for elem in points:
                elem['interval']['startTime'] = start_time
        else:
            metric_kind = 'GAUGE'

        result.append({
            'metric': metric,
            'resource': self.monitored_resource,
            'metricKind': metric_kind,
            'valueType': 'DOUBLE',
            'points': points
        })
Beispiel #8
0
    def __collect_instance_info(self, service, name, instance, metric_metadata,
                                service_metadata, service_to_name_to_info):
        """Creates a post payload for a DataDog time series data point.

       See http://docs.datadoghq.com/api/?lang=python#metrics-post.

    Args:
      service: [string] The name of the service that the metric is from.
      name: [string] The name of the metric coming from the service.
      instance: [dict] The spectator entry for a specific metric value
         for a specific tag binding instance that we're going to append.
      metric_metadata: [dict] The spectator JSON object for the metric
         is used to get the kind and possibly other metadata.
      service_to_name_to_info: [dict] A dictionary keyed by service to
        A dictionary mapping metric names to MetricInfo being built.
    """
        # In practice this converts a Spinnaker Timer into either
        # <name>__count or <name>__totalTime and removes the "statistic" tag.
        name, tags = spectator_client.normalize_name_and_tags(
            name, instance, metric_metadata)
        if tags is None:
            return  # ignore metrics that had no tags because these are bogus.

        record = InstanceRecord(
            service, '{0}:{1}'.format(service_metadata['__host'],
                                      service_metadata['__port']), tags,
            instance)

        name_to_info = service_to_name_to_info.get(service)
        if name_to_info is None:
            name_to_info = {}
            service_to_name_to_info[service] = name_to_info

        tag_names = set([tag['key'] for tag in tags])
        info = name_to_info.get(name)
        if info is None:
            info = MetricInfo(metric_metadata['kind'], tag_names, [record])
            name_to_info[name] = info
            return

        info.records.append(record)
        info.tags.update(tag_names)