Application Scenario
To collect services on self-built IDC, deploy Agent and manage collection configurations, and report monitoring data to the cloud TMP. For cloud services, we recommend using Integration Center, which will manage Agent, offering automated integration for multiple middlewares and scraping tasks. Obtaining Prometheus Instance Access Configuration
1. Go to Prometheus Monitoring Console, select the corresponding instance ID/Name, and on the Basic Info > Service Address page, obtain the Remote Write address and Token. Confirming the Network Environment and Connectivity with Cloud Instances
Based on the acquired RemoteWrite address, execute the following command. If the network is connected, the returned information will include 401 Unauthorized
.
curl -v -X POST ${RemoteWriteURL}
Installing and Starting vmagent
vmagent uses fewer resources and is widely used due to its compatibility with Prometheus collection configuration and Remote Write protocol. This document only describes common startup options for vmagent, managed through Systemd or Docker. For more detailed information, please see the official documentation. Common Startup Options
-promscrape.noStaleMarkers: If the collection target disappears, a stale marker for all associated metrics is generated and written to remote storage by default. Setting this option disables this behavior and can reduce memory usage. -loggerTimezone: The time zone for the time in logs, for example, Asia/Shanghai, Europe/Berlin
or Local
(UTC by default).
-remoteWrite.tmpDataPath: The file path for temporary data storage to be written after collection.
-remoteWrite.url: The URL where data is written to remote storage.
-remoteWrite.basicAuth.username: Remote storage -remoteWrite.url corresponding basic auth username.
-remoteWrite.basicAuth.password: Remote storage -remoteWrite.url corresponding basic auth password.
-promscrape.config: Path of the collection configuration, which can be a file path or HTTP URL. For more details, please see Reference Documentation. -promscrape.configCheckInterval: Interval for checking the -promscrape.config configuration changes. For configuration updates, please see Reference Documentation. Managing via Docker
2. Replace the Prometheus instance information in the script and start vmagent.
mkdir /etc/prometheus
touch /etc/prometheus/scrape-config.yaml
docker run -d --name vmagent --restart always --net host -v /etc/prometheus:/etc/prometheus victoriametrics/vmagent:latest \\
-promscrape.noStaleMarkers \\
-loggerTimezone=Local \\
-remoteWrite.url="${RemoteWriteURL}" \\
-remoteWrite.basicAuth.username="${APPID}" \\
-remoteWrite.basicAuth.password='${Token}' \\
-remoteWrite.tmpDataPath=/var/lib/vmagent \\
-promscrape.config=/etc/prometheus/scrape-config.yaml \\
-promscrape.configCheckInterval=5s
3. View vmagent logs
docker ps
docker logs vmagent
If it starts normally, executing the following command will return OK
.
curl localhost:8429/health
Managing via Systemd
1. On the vmagent Release page, download the corresponding vmutils-* compressed package according to your operating system and CPU architecture, and decompress it. 2. Replace the access information of the Prometheus instance in the script and start vmagent.
mkdir /etc/prometheus
touch /etc/prometheus/scrape-config.yaml
cat >/usr/lib/systemd/system/vmagent.service <<EOF
[Unit]
Description=VictoriaMetrics Agent
After=network.target
[Service]
LimitNOFILE=10240
ExecStart=/usr/bin/vmagent \\
-promscrape.noStaleMarkers \\
-loggerTimezone=Local \\
-remoteWrite.url="${RemoteWriteURL}" \\
-remoteWrite.basicAuth.username="${APPID}" \\
-remoteWrite.basicAuth.password="${Token}" \\
-remoteWrite.tmpDataPath=/var/lib/vmagent \\
-promscrape.config=/etc/prometheus/scrape-config.yaml \\
-promscrape.configCheckInterval=5s
Restart=always
RestartSec=10s
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable vmagent
systemctl start vmagent
sleep 3
systemctl status vmagent
3. View logs
If it starts normally, executing the following command will return OK
.
curl localhost:8429/health
Managing the Configuration
Modifying the Configuration File
Edit the collection configuration file /etc/prometheus/scrape-config.yaml
to add/update/delete collection tasks. For Prometheus collection task configuration, see Official Documentation. global:
scrape_interval: 30s
scrape_configs:
- job_name: agent-monitor
static_configs:
- targets:
- localhost:8429
After the configuration is modified, it will only take effect after the time set by the option -promscrape.configCheckInterval
.
Viewing Monitoring Target Information
Execute the following command to view the collection target and check whether the configuration is effective and meets expectations.
curl localhost:8429/api/v1/targets
Was this page helpful?