Collect host metrics with Vector
Vector's host_metrics source
collects CPU, memory, filesystem and network metrics. Send these through the
prometheus_remote_write sink
to OpenObserve's metrics endpoint. Sending them to the logs /_json endpoint
stores them as logs instead. For log collection, see the Vector logs guide.
Set up credentials
Install Vector on the host you
want to monitor, then set the following environment variables in Bash. Use the ingestion
URL, organization ID, user and passcode from Data sources > Custom > Metrics in your
OpenObserve instance. OPENOBSERVE_URL is the base URL without a trailing slash,
for example http://localhost:5080 for a local instance. Use HTTPS for a remote
instance, and keep credentials out of configuration files and source control.
export OPENOBSERVE_URL="http://localhost:5080"
export OPENOBSERVE_ORG="default"
export OPENOBSERVE_USER="your-email@example.com"
read -rs -p "Ingestion passcode: " OPENOBSERVE_PASSCODE
export OPENOBSERVE_PASSCODE
export VECTOR_DANGEROUSLY_ALLOW_ENV_VAR_INTERPOLATION=trueVector 0.57 and newer disable environment variable interpolation by default. The last line enables it for this example. Use only environment values you control, and consider Vector's secrets backend for credentials on shared hosts.
Configure and run Vector
Save the following as host-metrics.yaml:
sources:
host_metrics:
type: host_metrics
scrape_interval_secs: 60
sinks:
openobserve_metrics:
type: prometheus_remote_write
inputs: [host_metrics]
endpoint: "${OPENOBSERVE_URL}/api/${OPENOBSERVE_ORG}/prometheus/api/v1/write"
auth:
strategy: basic
user: "${OPENOBSERVE_USER}"
password: "${OPENOBSERVE_PASSCODE}"
compression: snappy
healthcheck:
enabled: falseFrom the directory where you saved the file, validate and run it:
vector validate --no-environment host-metrics.yaml
vector --config host-metrics.yamlVerify ingestion
The example collects host metrics every 60 seconds. After the first collection,
open Metrics in the same organization and query host_cpu_seconds_total.
The available metrics depend on the host operating system and enabled collectors.
When Vector runs in a container, its host metrics describe the resources visible
inside that container. Run it on the host to monitor that host directly.
Troubleshooting
The configuration uses Snappy compression, as required by the
Prometheus remote-write protocol.
Do not copy compression: gzip or the http sink from a Vector logs example.
The metrics endpoint is /api/<organization>/prometheus/api/v1/write, and the
sink type must be prometheus_remote_write.
The sink's startup health check is disabled, and --no-environment skips
component checks, so validation alone does not prove that metrics were ingested. If Vector reports HTTP 400, check OpenObserve's server
logs for the rejected payload. For HTTP 401 or 403, check the selected
organization, ingestion user, passcode and permissions.