Prometheus metric collection agent
To transfer metrics from the VM to Yandex Managed Service for Prometheus®, you need a metric collection agent. You can install any agent supporting metrics transfer or use the Unified Agent which can transfer Prometheus metrics.
This section describes how to install an agent when creating a VM. For other installation options, see Installing and updating Yandex Unified Agent.
Note
As of version 25.03.80, Unified Agent can collect and transmit Prometheus metrics.
List of supported operating systems
- Ubuntu 14.04 or higher
- Debian 9 or higher
Before you begin installation
-
Create a service account in the folder you want to write metrics to and assign it the
monitoring.editor
role. -
Set up agent authorization in the Yandex Monitoring API. To do this, link your service account to the VM. This way, the agent will automatically get the service account IAM token from the metadata service.
Installation and setup
You can install a metric collection agent when creating a VM with the help of the management console, CLI, API, or Terraform.
-
In the management console
, start creating your VM. -
Expand Additional ⟶ Monitoring.
-
Enable Agent for delivering metrics and select Yandex Managed Service for Prometheus®.
-
Create a workspace or select an existing one.
-
Optionally, specify the delivery parameters for your custom metrics, in JSON format.
It no parameters are specified, the agent will only deliver Linux system metrics. You can add or change the delivery of your custom metrics later, in user metadata.
Metrics description format:
{ "jobs": [ { "job_name": <name>, "scrape_interval": "15s", "scrape_timeout": "5s", "metrics_path": "/metrics", "targets": [ { "host": <host_FQDN>, //this is an optional field "port": 42 } ] } ] }
Where:
job_name
: Random name for the set of metrics to collect.scrape_interval
: How often the agent will collect metrics.scrape_timeout
: Time the agent will have to collect metrics.metrics_path
: Path to the service metrics location.targets
: Parameters of the host to collect metrics from:host
: Full domain name, such asmy.example.com
. This is an optional setting.port
: Metric collection port.
To install the agent, provide the following string in the user metadata (user-data
):
```text
#cloud-config\nruncmd:\n - wget -O - https://monitoring.api.cloud.yandex.net/monitoring/v2/unifiedAgent/config/install.sh | bash
```
To install the agent:
-
Specify the following in the VM creation configuration:
resource "yandex_compute_instance" "my-vm" { ... service_account_id = "ajehka*************" metadata = { monitoring_workspaceid = "mon618clr**************" user-data = "${file("<path_to_configuration_file>")}" } ... }
Where:
monitoring_workspaceid
: ID of the workspace to which you want to write metrics.service_account_id
: ID of the service account with themonitoring.editor
role.
-
In the configuration file (
user-data
), specify the following line:#cloud-config\nruncmd:\n - wget -O - https://monitoring.api.cloud.yandex.net/monitoring/v2/unifiedAgent/config/install.sh | bash
To install the agent and send metrics, make sure the VM has access to the internet.
Configuration
The agent has two configuration files: config.yml
and prometheus.yml
.
The config.yml
file is located at /etc/yc/unified_agent/config.yml
. When the agent is installed in Prometheus metric collection mode, the file does not contain the metric collection parameters.
Sample config.yml file
status:
port: "16241"
import:
- /etc/yc/unified_agent/conf.d/*.yml
- /etc/yc/unified_agent/generated_conf.d/*.yml
The prometheus.yml
file is located at /etc/yc/unified_agent/generated_conf.d/prometheus.yml
. By default, it is configured to collect metrics in Prometheus format. If you specified your own metric collection settings when installing the agent, they will be added to this file.
Sample prometheus.yml file
storages:
- name: __prometheus_metrics_storage
plugin: fs
config:
directory: /var/lib/yc/unified_agent/__prometheus_metrics_storage
max_partition_size: 100mb
max_segment_size: 10mb
channels:
- name: __remote_write
channel:
pipe:
- storage_ref:
name: __prometheus_metrics_storage
output:
plugin: metrics
config:
url: "https://monitoring.api.cloud.yandex.net/prometheus/workspaces/workspace_id/api/v1/write"
set_host_label: null
iam:
cloud_meta: { }
routes:
- input:
id: linux_metrics_input
plugin: linux_metrics
config:
poll_period: 60s
namespace: sys
prometheus_config:
job_name: linux_metrics
channel:
channel_ref:
name: __remote_write
Once the VM is deployed, the agent will start automatically and will be sending metrics to Yandex Managed Service for Prometheus®.
You will be charged for metric delivery.
Overview of VM metrics
To view metrics your agent transfers to Yandex Managed Service for Prometheus®:
-
In the management console
, select the folder where the VM is located. -
In the list of services, select Monitoring.
-
Navigate to Prometheus.
-
Select the workspace to which your VM metrics are written.
-
Open the Metrics tab and enter a Query in PromQL to view:
-
Linux system metrics:
{job="linux_metrics", instance="<VM_name>", __name__="<metric_name>"}
.Example:
{job="linux_metrics", instance="my_vm", __name__="sys_cpu_CpuCores"}
.For the list of metrics transferred by the Prometheus agent, see Yandex Unified Agent metrics.
-
Custom metrics if the agent has been configured to transfer them:
{job="metrics_totality_name", instance="<VM_name>:<port>", __name__="<metric_name>"}
.Where:
job
: Name of the set of metrics specified when configuring the agent.instance
: VM name and port used by your application.name
: Name of the metric your application transfers.
Example:
{job="web_server", instance="my_server:9100", __name__="http_requests_total"}
.
-
-
Click Execute.