---
title: "Prometheus"
sidebar_label: "Prometheus"
description: "How to configure Prometheus to receive metrics into your infrastructure"
sidebar_position: 2
---

import Formbricks from '@theme/MDXComponents/Formbricks';
import MoreVerticalIcon from '@selectel/docux/icons/more-vertical';
import CopyIcon from '@selectel/docux/icons/copy'

# Prometheus

[Prometheus](https://prometheus.io/docs/introduction/overview/) — an application that allows you to set up the collection, storage, and processing of metrics.

Before you begin, [configure Prometheus](#configure-prometheus).

## Configure Prometheus \{#configure-prometheus}

You can configure an agent to receive metrics into your infrastructure.

1. [Add a service user](#add-service-user).
2. [Configure the agent to receive metrics](#set-up-agent).

### 1. Add a service user \{#add-service-user}

[Add a service user](/access-control/manage/add-user.mdx#add-service-user) with access rights in the **Projects** area and the following role:

* `metrics.admin;`
* `member;`
* or [`reader`](/access-control/role-reference.mdx#reader).

Users can be added by the [Account Owner](/access-control/user-types.mdx#account-owner) or users with the [`iam.admin`](/access-control/role-reference.mdx#iam-admin).

### 2. Configure the agent to receive metrics \{#set-up-agent}

1. Open the CLI.

2. Create a configuration file `prometheus.yaml`:

   ```bash
   nano /etc/prometheus/prometheus.yaml
   ```

3. In the `prometheus.yaml` configuration file, populate the `scrape_configs`:

   ```yaml
   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](https://my.selectel.ru/vpc/): in the top menu, click **Products** and select any product → open the projects menu → in the line of the required project, click <CopyIcon />;
   * `<namespace>` — the name of the selected namespace, for example, `compute`. You can view it in the [Metrics Reference](/metrics/metrics-references.mdx);
   * `<base_url>` — the URL for accessing the Metrics service API. If you are configuring an agent to collect metrics from a [dedicated server](/dedicated/), use the cloud server pool URL that corresponds to the pool where your dedicated server is located. A list of URLs can be found in the [Metrics](/api/urls/#metrics) subsection of the [List of URLs](/api/urls/);
   * `<user_id>` — the ID of the user you [added in step 1](#add-service-user);
   * `<password>` — the password of the user you [added in step 1](#add-service-user).

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 metrics export to external storage or processing systems, for example, VictoriaMetrics. To do this, add and populate the [`remote_write`](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write) section in the `prometheus.yaml` configuration file.

6. Exit the `nano` text editor and save your changes: press **Ctrl+Х**, then **Y+Enter**.

7. Run Prometheus:

   ```bash
   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:

   ```bash
   curl localhost:9090/federate -X GET -d 'match[]={__name__=~".+"}'
   ```

<Formbricks />
