RousselTMLEARNING

Observability

Ingesting metrics into VictoriaMetrics: scraping, vmagent and remote write

All the ways to feed VictoriaMetrics: remote write from Prometheus, built-in scraping, vmagent and its disk buffer, relabeling, stream aggregation, and other protocols (InfluxDB, OTLP, Graphite).

1. From Prometheus #

Long-term storage in one line.

remote_write #

# prometheus.yml
remote_write:
  - url: http://vm:8428/api/v1/write
    queue_config: { max_samples_per_send: 10000, capacity: 20000, max_shards: 30 }

Prometheus keeps a short retention for its local alerts; VictoriaMetrics keeps the history.

2. Scraping directly #

Without Prometheus.

promscrape #

VictoriaMetrics and vmagent understand the Prometheus configuration file (scrape_configs, service discovery, relabeling):

victoria-metrics -promscrape.config=/etc/prometheus/prometheus.yml -storageDataPath=/data
# ou, plus courant, avec vmagent
vmagent -promscrape.config=/etc/prometheus/prometheus.yml \
        -remoteWrite.url=http://vm:8428/api/v1/write

Targets and their status are shown on /targets; /service-discovery shows labels before and after relabeling.

3. vmagent #

A robust collector.

Features #

FeatureOption
Disk buffer if the destination is unavailable-remoteWrite.tmpDataPath, -remoteWrite.maxDiskUsagePerURL
Several destinations (replication)several -remoteWrite.url
Relabeling before sending-remoteWrite.urlRelabelConfig
Stream aggregation-streamAggr.config (reduce cardinality before storage)
Distributed collection-promscrape.cluster.membersCount, -promscrape.cluster.memberNum
Receiving protocolsInfluxDB, Graphite, OpenTSDB, OTLP
vmagent \
  -promscrape.config=/etc/vmagent/scrape.yml \
  -remoteWrite.url=http://vm-eu:8428/api/v1/write \
  -remoteWrite.url=http://vm-us:8428/api/v1/write \
  -remoteWrite.tmpDataPath=/var/lib/vmagent \
  -remoteWrite.maxDiskUsagePerURL=10GB
Good practice: vmagent often replaces Prometheus in agent mode: less memory, a persistent disk buffer and native replication to several stores.

Stream aggregation #

# stream-aggr.yml : remplacer les séries par instance par un total par service
- match: 'http_requests_total'
  interval: 1m
  by: [service, code]
  outputs: [total]

The result (http_requests_total:1m_by_code_service_total) is sent instead of, or in addition to, the raw series: useful for very high-cardinality metrics where only the aggregate is consulted.

4. Other protocols #

A universal entry point.

Examples #

# InfluxDB line protocol
curl -d 'cpu,host=web-1 usage=42.5' http://vm:8428/write
# Import au format Prometheus texte
curl -d 'temperature{salle="serveur"} 21.5' http://vm:8428/api/v1/import/prometheus
# OpenTelemetry (OTLP HTTP, métriques)
#   http://vm:8428/opentelemetry/v1/metrics
# Export pour sauvegarde ou migration
curl -s 'http://vm:8428/api/v1/export?match[]={__name__="temperature"}'

Related articles

VictoriaMetrics: why and how, from single node to cluster

What VictoriaMetrics brings compared with Prometheus alone, its components (single-node, vmagent, vmalert, vm…

MetricsQL: PromQL with superpowers

The differences between MetricsQL and PromQL: implicit windows, extra functions (range, rollup, label), WITH …

VictoriaMetrics cluster: vminsert, vmselect, vmstorage and multi-tenancy

The VictoriaMetrics cluster architecture: the roles of vminsert, vmselect and vmstorage, data distribution an…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!