Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Monitoring
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Working with metrics
      • Delivering Linux system metrics
      • Delivering custom application metrics
      • Delivering metrics from HAProxy and other third-party applications
      • Delivering metrics from hosts outside Yandex Cloud
      • Writing custom metrics via the API
      • Getting a list of metrics
      • Downloading metrics
      • Exporting metrics in Prometheus format
    • Working with dashboards
      • Creating dashboards
      • Copying dashboards
      • Adding widgets to a dashboard
      • Deleting widgets from a dashboard
      • Deleting dashboards
    • Working with alerts
      • Creating alerts
      • Creating notification channels
      • Deleting alerts
  • Concepts
    • Service overview
    • Data model
    • Visualization
      • Overview
      • Query string
      • Widgets
      • Dashboards
    • Transmitting metrics
      • Agent for delivering metrics
        • Overview
        • Installation and startup
        • Configuration
        • Best practices for using the agent
    • Query language
    • Alerting
    • Data decimation
    • Deleting expired metrics (TTL)
    • Quotas and limits
  • Access management
  • Pricing policy
    • Current pricing policy
    • Archive
      • Policy before October 1, 2020
  • API reference
    • API authentication
    • REST
      • Overview
      • MetricsData
        • Overview
        • read
        • write
        • prometheusMetrics
      • MetricsMeta
        • Overview
        • listLabelKeys
        • listLabelValues
        • listMetricNames
        • listMetrics
  • Metric reference
  • Questions and answers
    • General questions
    • Navigation
    • Metric collection and export
    • Metrics and units of measure
    • Alerts / notifications
    • All questions on the same page
  1. Step-by-step instructions
  2. Working with metrics
  3. Writing custom metrics via the API

Writing custom metrics via the API

Written by
Yandex Cloud

    To start writing custom metrics via the API, use the write method.

    Before getting started

    To try the examples in this section:

    1. Make sure you have installed the cURL utility that is used in the examples.
    2. Get the ID of the folder you are granted the monitoring.editor role or higher of.
    3. Get an IAM token:
      • Instructions for a Yandex account.
      • Instructions for a service account.

    Sample request

    1. Create a file with the request body (for example, body.json). In the metrics 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
              }
          ]
      }
      
    2. 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"
      }
      

    Was the article helpful?

    Language / Region
    © 2022 Yandex.Cloud LLC