Example #1
0
def _extract_header(time_series):
    """Return a copy of time_series with the points removed."""
    return TimeSeries(
        metric=time_series.metric,
        resource=time_series.resource,
        metric_kind=time_series.metric_kind,
        value_type=time_series.value_type,
    )
Example #2
0
  def _query_iter_get_result():
    METRIC_LABELS = list({'instance_name': name} for name in INSTANCE_NAMES)
    RESOURCE_LABELS = list({
        'project_id': PROJECT,
        'zone': zone,
        'instance_id': instance_id,
    } for zone, instance_id in zip(INSTANCE_ZONES, INSTANCE_IDS))

    for metric_labels, resource_labels in zip(METRIC_LABELS, RESOURCE_LABELS):
      yield TimeSeries(
        metric=Metric(type=METRIC_TYPE, labels=metric_labels),
        resource=MonitoredResource(type=RESOURCE_TYPE, labels=resource_labels),
        metric_kind='GAUGE',
        value_type='DOUBLE',
        points=[],
      )
Example #3
0
    def _format_metric(self, key, value, unit, buffer=False, **dimensions):
        series = TimeSeries()

        series.metrics.type = 'custom.googleapis.com/custodian/policy/%s' % key

        # Google controlled vocabulary with artificial limitations on resource type
        # there's not uch useful we can utilize.
        series.resource.type = 'global'

        # series.resource.labels['project_id'] =
        point = series.points.add()
        if unit == 'Count':
            point.value.int64 = value
        elif unit == 'Seconds':
            point.value.double_value = value
        now = time.time()
        point.interval.end_time.seconds = ns = int(now)
        point.interval.end_time.nanos = int((now - ns) * 10**9)
        return series
Example #4
0
def get_time_series(metric_descriptor, value):
  series = TimeSeries()

  series.metric.type = metric_descriptor.type
  labels = series.metric.labels
  labels['workflow_id'] = WORKFLOW_ID
  labels['task_call_name'] = TASK_CALL_NAME
  labels['task_call_index'] = TASK_CALL_INDEX
  labels['task_call_attempt'] = TASK_CALL_ATTEMPT
  labels['cpu_count'] = CPU_COUNT_LABEL
  labels['mem_size'] = MEMORY_SIZE_LABEL
  labels['disk_size'] = DISK_SIZE_LABEL

  series.resource.type = 'gce_instance'
  series.resource.labels['zone'] = ZONE
  series.resource.labels['instance_id'] = INSTANCE

  point = series.points.add(value=value)
  point.interval.end_time.seconds = int(time())

  return series
Example #5
0
def get_time_series(metric_descriptor, value):
    global last_time
    series = TimeSeries()

    series.metric.type = metric_descriptor.type
    labels = series.metric.labels
    labels['workflow_id'] = WORKFLOW_ID
    labels['task_call_name'] = TASK_CALL_NAME
    labels['task_call_index'] = TASK_CALL_INDEX
    labels['task_call_attempt'] = TASK_CALL_ATTEMPT
    labels['cpu_count'] = CPU_COUNT_LABEL
    labels['mem_size'] = MEMORY_SIZE_LABEL
    labels['disk_size'] = DISK_SIZE_LABEL
    labels['preemptible'] = PREEMPTIBLE_LABEL

    series.resource.type = 'gce_instance'
    series.resource.labels['zone'] = MACHINE['zone']
    series.resource.labels['instance_id'] = MACHINE['name']

    point = series.points.add(value=value)
    end_time = max(time(), last_time + REPORT_TIME_SEC_MIN)
    point.interval.end_time.seconds = int(end_time)

    return series
Example #6
0
 def deserialize(cls, data: str) -> "Result":
     ts = TimeSeries.from_json(data)
     return cls(ts=ts)
Example #7
0
 def serialize(obj) -> str:
     return json.dumps(TimeSeries.to_dict(obj.ts))
Example #8
0
 def deserialize(cls, data: str) -> "GCPResult":
     b = base64.b64decode(data.encode("utf-8"))
     ts = TimeSeries.deserialize(b)
     return cls(ts=ts)
Example #9
0
 def serialize(obj):
     b = TimeSeries.serialize(obj.ts)
     return base64.b64encode(b).decode("utf-8")