Prometheus
Prometheus — an application that allows you to set up the collection, storage, and processing of metrics.
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 access rights in the Projects area and the following role:
metrics.admin;member;- or
reader.
Users can be added by the Account Owner or users with the iam.admin.
2. Configure the agent to receive metrics
-
Open the CLI.
-
Create a configuration file
prometheus.yaml:nano /etc/prometheus/prometheus.yaml -
In the
prometheus.yamlconfiguration file, populate thescrape_configs: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 projects menu → in the line of the required project, click ;<namespace>— the name of the selected namespace, for example,compute;<base_url>— URL for accessing the Metrics service API. If you are configuring an agent to collect metrics from 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 guide URL list;<user_id>— the ID of the user you added in step 1.<password>— the password of the user you added in step 1.
-
Optional: you can configure metrics collection from multiple pools or projects. To add a new pool or project, repeat step 3.
-
Optional: add metrics export to external storage or processing systems, for example to VictoriaMetrics. To do this, add and complete the
remote_writesection in theprometheus.yaml. -
Exit the
nanotext editor while saving 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__=~".+"}'