OpenTelemetry Host Metrics receiver
hostmetricsreceiver is an OpenTelemetry Collector plugin that gathers various metrics about the host system, for example, CPU, RAM, disk metrics and other system-level metrics.
By collecting and analyzing host metrics, you can gain insight into the performance and health of your host systems and identify potential problems or bottlenecks that could affect the overall performance of your applications and services.
What is OpenTelemetry Collector?
OpenTelemetry Collector provides powerful data processing capabilities. It can aggregate, filter, transform, and enrich telemetry data as it flows through the system.
To start collecting host metrics, you need to install Collector on each system you want to monitor and add the following lines to the Collector config:
processors: resourcedetection: detectors: [env, system] cumulativetodelta: receivers: hostmetrics: collection_interval: 10s scrapers: # CPU utilization metrics cpu: # Disk I/O metrics disk: # File System utilization metrics filesystem: # CPU load metrics load: # Memory utilization metrics memory: # Network interface I/O metrics & TCP connection metrics network: # Paging/Swap space utilization and I/O metrics paging: service: pipelines: metrics: receivers: [otlp, hostmetrics] processors: [cumulativetodelta, batch, resourcedetection] exporters: [otlp/uptrace]
If you need to configure
otlp/uptrace exporter, see Sending data from Otel Collector to Uptrace.
If you are using unusual filesystems, you may want to configure
filesystem receiver more thoroughly, for example, to scrape only supported filesystem types and avoid warnings:
receivers: hostmetrics: collection_interval: 10s scrapers: cpu: disk: load: filesystem: include_fs_types: match_type: strict fs_types: [ext3, ext4] memory: network: paging:
To collect per process CPU, Memory, and Disk I/O metrics, you need to enable the respective scrapers:
receivers: hostmetrics: collection_interval: 10s scrapers: # Process count metrics process: # Per process CPU, Memory, and Disk I/O metrics processes:
Those scrapers are disabled by default, because they require running OpenTelemetry Collector with elevated permissions in order to access information about other processes.
On Linux, you can achieve that by running
# /lib/systemd/system/otelcol-contrib.service User=root Group=root
sudo to start the process:
# /lib/systemd/system/otelcol-contrib.service ExecStart=sudo /usr/bin/otelcol-contrib $OTELCOL_OPTIONS
Container host metrics
On Linux, OpenTelemetry collects metrics from the Linux system directories. To collect metrics about the host system and not the container, you can mount the host filesystem when running the container:
# mount the entire filesystem docker run -v /:/hostfs ... # or mount only parts you need docker run -v /proc:/hostfs/proc ...
root_path so the hostmetrics receiver knows where the root filesystem is:
receivers: hostmetrics: root_path: /hostfs
OpenTelemetry Collector supports a variety of receivers that allow you to collect telemetry data from different sources. Receivers act as plugins within the Collector and handle the ingestion of data from various protocols and formats. Here are some of the commonly used receivers available in the OpenTelemetry Collector: