Exporting metrics in Prometheus format
To export metrics in Prometheus format, use the prometheusMetrics method. Set up metric collection in Prometheus before pushing metrics to it.
Here is an example of setting up Monitoring metric collection 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-gitlab: Managed Service for GitLab.managed-greenplum: Yandex MPP Analytics for PostgreSQL.managed-kafka: Managed Service for Apache Kafka®.managed-kubernetes: Managed Service for Kubernetes.managed-mongodb: Yandex StoreDoc.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.postbox: Yandex Cloud Postbox.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 an API key for the service account.
-
Assign the service account the
monitoring.viewerrole for the selected folder. -
In the Prometheus configuration
, add anotherjobto the data collection section:... scrape_configs: ... - job_name: 'yc-monitoring-export' metrics_path: '/monitoring/v2/prometheusMetrics' scheme: 'https' params: folderId: - '<folder_ID>' # For example, it can be `aoeng2krmasi`********. service: - '<service>' # For example, it can be `managed-mongodb`. bearer_token: '<API_key>' # Alternatively, you can use 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 UI:
http://localhost:9090/targets(replacelocalhostwith the name of your host running Prometheus). -
If you need to change label names, use relabeling
.
Tip
When dealing with lots of metrics, increase scrape_timeout to 60s.
ClickHouse® is a registered trademark of ClickHouse, Inc