def _api_format()

in blueprints/cloud-operations/compute-quota-monitoring/src/main.py [0:0]


  def _api_format(self, name, value):
    'Return a specific timeseries for this quota in API format.'
    d = {
        'metric': {
            'type': f'{BASE}/{self.metric.lower()}/{name}',
            'labels': {
                'location': self.region,
                'project': self.project
            }
        },
        'resource': {
            'type': 'global',
            'labels': {}
        },
        'metricKind':
            'GAUGE',
        'points': [{
            'interval': {
                'endTime': f'{self.tstamp.isoformat("T")}Z'
            },
            'value': {}
        }]
    }
    if name == 'ratio':
      d['valueType'] = 'DOUBLE'
      d['points'][0]['value'] = {'doubleValue': value}
    else:
      d['valueType'] = 'INT64'
      d['points'][0]['value'] = {'int64Value': value}
    # re-enable the following line if cardinality is not a problem
    # d['metric']['labels']['quota'] = f'{self.usage}/{self.limit}'
    return d