Skip to main content

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.
  2. Configure an agent to collect metrics.

1. Add a service user

Add a service user with permissions in the Projects scope and the role:

Users can be added by the Account Owner or users with the iam.admin role.

2. Configure the agent to receive metrics

  1. Open the CLI.

  2. Create a prometheus.yaml configuration file:

    nano /etc/prometheus/prometheus.yaml
  3. In the prometheus.yaml configuration file, fill in the scrape_configs block:

    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 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.
  4. Optional: you can configure metrics collection from several pools or projects. To add a new pool or project, repeat step 3.

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

  6. Exit the nano text editor, saving the 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__=~".+"}'