Writing custom metrics via the API
Written by
To start writing custom metrics via the API, use the write method.
Before getting started
To try the examples in this section:
- Make sure you have installed the cURL utility that is used in the examples.
- Get the ID of the folder you are granted the
monitoring.editor
role or higher of. - Get an IAM token:
- Instructions for a Yandex account.
- Instructions for a service account.
Sample request
-
Create a file with the request body (for example,
body.json
). In themetrics
property, specify the list of metrics to write. Send the required labels in the request parameters and additional labels in the request body.body.json:
{ "metrics": [ { "name": "temperature", "labels": { "building": "office", "room": "openspace" }, "value": 18.6 } ] }
-
Send the request and save the response to a file, for example,
output.json
:$ export IAM_TOKEN=CggaATEVAgA... $ curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${IAM_TOKEN}" \ -d '@body.json' \ 'https://monitoring.api.cloud.yandex.net/monitoring/v2/data/write?folderId=aoe6vrq0g3svvs3uf62u&service=custom' > output.json
Sample response:
output.json:
{ "metrics_written":"1" }