Exporting metrics in Prometheus format
To export metrics in the Prometheus format, use the prometheusMetrics method. Before uploading metrics to Prometheus, set up metric collection in Prometheus.
An example of metric collection setup from Monitoring in Prometheus:
-
Select the folder you want to collect data from.
-
Select a service from the following list:
application-load-balancer
: Application Load Balancer.audit-trails
: Audit Trails.cdn
: Cloud CDN.certificate-manager
: Certificate Manager.compute
: Compute Cloud.container-registry
: Container Registry.data-proc
: Yandex Data Processing.data-streams
: Data Streams.data-transfer
: Data Transfer.iam
: Identity and Access Management.interconnect
: Cloud Interconnect.kms
: Key Management Service.logging
: Cloud Logging.managed-clickhouse
: Managed Service for ClickHouse®.managed-elasticsearch
: Managed Service for Elasticsearch.managed-greenplum
: Managed Service for Greenplum®.managed-kafka
: Managed Service for Apache Kafka®.managed-kubernetes
: Managed Service for Kubernetes.managed-mongodb
: Managed Service for MongoDB.managed-mysql
: Managed Service for MySQL®.managed-opensearch
: Managed Service for OpenSearch.managed-postgresql
: Managed Service for PostgreSQL.managed-redis
: Yandex Managed Service for Valkey™.managed-sqlserver
: Managed Service for SQL Server.message-queue
: Message Queue.monitoring
: Monitoring.network-load-balancer
: Network Load Balancer.serverless-apigateway
: API Gateway.serverless-containers
: Serverless Containers.serverless-functions
: Cloud Functions.speechkit
: SpeechKit.storage
: Object Storage.translate
: Translate.vision
: Vision OCR.ydb
: Managed Service for YDB.
-
Create a static API key for the service account.
-
Assign the service account the
monitoring.viewer
role for the selected folder. -
In the Prometheus configuration
, add a new job (job
) to the data collection section:... scrape_configs: ... - job_name: 'yc-monitoring-export' metrics_path: '/monitoring/v2/prometheusMetrics' scheme: 'https' params: folderId: - '<folder_ID>' # for example, `aoeng2krmasi`******** service: - '<service>' # for example, `managed-mongodb` bearer_token: '<API_key>' # Or via a file (recommended): # bearer_token_file: '<name_of_file_with_API_key>' static_configs: - targets: ['monitoring.api.cloud.yandex.net'] labels: folderId: '<folder_ID>' service: '<service _ID>'
-
Restart Prometheus.
-
Check data collection in the Prometheus user interface:
http://localhost:9090/targets
(replacelocalhost
with the name of your host running Prometheus). -
If you need to change label names, use relabeling
.
Tip
If you have a lot of metrics, increase the data collection timeout (scrape_timeout
) to 60s.
ClickHouse® is a registered trademark of ClickHouse, Inc