Skip to main content

Prometheus

Last update:

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.
  2. Configure the agent to receive metrics.

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

  1. Open the CLI.

  2. Create a configuration file prometheus.yaml:

    nano /etc/prometheus/prometheus.yaml
  3. In the prometheus.yaml configuration file, populate the scrape_configs:

    scrape_configs:
    - job_name: test_scrape
    scrape_interval: 1m
    metrics_path: /projects/<project_id>/namespaces/<namespace>/prometheus/metrics
    static_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.
  4. Optional: you can configure metrics collection from multiple pools or projects. To add a new pool or project, repeat step 3.

  5. Optional: add metrics export to external storage or processing systems, for example to VictoriaMetrics. To do this, add and complete the remote_write section in the prometheus.yaml.

  6. Exit the nano text editor while saving changes: press Ctrl+X, and then Y+Enter.

  7. 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
  8. 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__=~".+"}'