Prometheus
Prometheus is an application that allows you to configure metric collection, storage, and processing.
Before you begin, configure Prometheus.
Configure Prometheus
You can configure an agent to receive metrics into your infrastructure.
1. Add a service user
Add a service user with permissions in the Projects scope and the role:
- metrics.admin;
- member;
- or reader.
Users can be added by the Account Owner or users with the iam.admin role.
2. Configure the agent to receive metrics
-
Open the CLI.
-
Create a
prometheus.yamlconfiguration file:nano /etc/prometheus/prometheus.yaml -
In the
prometheus.yamlconfiguration file, fill in thescrape_configsblock:scrape_configs:- job_name: test_scrapescrape_interval: 1mmetrics_path: /projects/<project_id>/namespaces/<namespace>/prometheus/metricsstatic_configs:- targets:- <base_url>basic_auth:username: <user_id>password: <password>Specify:
<project_id>— project ID. You can copy it in the Control panel: in the top menu, click Products and select any product → open the project menu → on the line with the desired project, click ;<namespace>— name of the selected namespace, for example,compute. You can find it in the Metrics reference guide;<base_url>— URL to access the Metrics service API. If you are configuring an agent to collect metrics for a dedicated server, use the cloud server pool URL that corresponds to the pool where your dedicated server is located. The list of URLs can be found in the Metrics section of the List of URLs guide;<user_id>— ID of the user that you added in step 1;<password>— password of the user that you added in step 1.
-
Optional: you can configure metrics collection from several pools or projects. To add a new pool or project, repeat step 3.
-
Optional: add sending metrics to external storage or processing systems, for example, VictoriaMetrics. To do this, add and fill in the
remote_writesection in theprometheus.yamlconfiguration file. -
Exit the
nanotext editor, saving the changes: press Ctrl+X, and then Y+Enter. -
Run Prometheus:
docker run \--name prometheus \--rm \-v ${PWD}/prometheus.yaml:/etc/prometheus/prometheus.yaml:ro \-p 9090:9090 \prom/prometheus:latest \--config.file=/etc/prometheus/prometheus.yaml -
Optional: verify that metrics are being collected. To do this, query all collected metrics in Prometheus:
curl localhost:9090/federate -X GET -d 'match[]={__name__=~".+"}'