in blueprints/cloud-operations/network-quota-monitoring/src/plugins/monitoring.py [0:0]
def descriptor_requests(project_id, root, existing, computed):
'Returns create requests for missing descriptors.'
type_base = DESCRIPTOR_TYPE_BASE.format(root)
url = DESCRIPTOR_URL.format(project_id)
for descriptor in computed:
d_type = f'{type_base}{descriptor.type}'
if d_type in existing:
continue
LOGGER.info(f'creating descriptor {d_type}')
if descriptor.is_ratio:
unit = '10^2.%'
value_type = 'DOUBLE'
else:
unit = '1'
value_type = 'INT64'
data = json.dumps({
'type': d_type,
'displayName': descriptor.name,
'metricKind': 'GAUGE',
'valueType': value_type,
'unit': unit,
'monitoredResourceTypes': ['global'],
'labels': [{
'key': l,
'valueType': 'STRING'
} for l in descriptor.labels]
})
yield HTTPRequest(url, HEADERS, data)