---
title: "VMAgent"
sidebar_label: "VMAgent"
description: "How to set up VMAgent to collect metrics into your infrastructure"
sidebar_position: 2
---

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

# VMAgent

[VMAgent](https://docs.victoriametrics.com/victoriametrics/vmagent/) is an agent that allows you to set up the collection and processing of metrics.

Before you begin, [set up VMAgent](#configure-vmagent).

## Set up VMAgent \{#configure-vmagent}

You can set up the agent to collect metrics into your infrastructure.

1. [Add a service user](#add-service-user).
2. [Set up the agent to collect 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 the **Projects** scope permission and one of the following roles:

* `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. Set up the agent to collect metrics \{#set-up-agent}

1. Open the CLI.

2. Create the `vmagent.yaml` configuration file:

   ```bash
   nano /etc/vmagent/vmagent.yaml
   ```

3. In the `vmagent.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. It can be copied 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>` — 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 for a [dedicated server](/dedicated/), use the URL of the cloud server pool that corresponds to the pool where your dedicated server is located. The list of URLs can be viewed in the [URL list](/api/urls/);
   * `<user_id>` — ID of the user you [added in step 1](#add-service-user);
   * `<password>` — password of the user you [added in step 1](#add-service-user).

4. Optional: you can configure metric collection from multiple pools or projects. To add a new pool or project, repeat step 3.

5. Optional: add metric export to external storage or processing systems, for example to VictoriaMetrics. To do this, add and populate the [`remote_write`](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write) section in the `vmagent.yaml` configuration file.

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

7. Launch VMAgent:

   ```bash
   docker run \
     --name vmagent \
     --rm \
     -v ${PWD}/vmagent.yaml:/etc/vmagent/vmagent.yaml:ro  \
     -p 8429:8429 \
     victoriametrics/vmagent:latest \
     --promscrape.config=/etc/vmagent/vmagent.yaml \
     --remoteWrite.url=http:/<storage_path>/api/v1/write
   ```

   Specify `<storage_path>` — the address of your custom metrics storage.

8. Optional: make sure that metrics are being collected. To do this, check the agent's connection to the Metrics service:

   ```bash
   curl localhost:8429/targets
   ```

   The command output should display a status of `up`. Example output:

   ```bash
   job=test_scrape (1/1 up)
   ```

<Formbricks />
