I want to filter out (either including or excluding) hostmetrics’s CPU based on metric’s labels but this does not work well when I use the include/exclude syntax for filterprocessor
.
Here are my config.yml
:
receivers:
hostmetrics:
collection_interval: 10s
scrapers:
cpu:
metrics:
system.cpu.time:
enabled: true
processors:
filter/metric_attr:
error_mode: ignore
metrics:
include:
match_type: expr
expressions:
- Label("cpu") matches "^cpu0$"
exporters:
prometheus:
endpoint: localhost:8889
namespace: otel-host-metrics
service:
telemetry:
logs:
level: debug
pipelines:
metrics:
receivers: [hostmetrics]
processors: [filter/metric_attr]
exporters: [prometheus]
What actually works is using OTTL syntax, but this can only drop metrics, it does not have the flexibility to include/exclude:
# This drops the metrics which has cpu attribute matches cpu1
filter/drop_label:
error_mode: ignore
metrics:
datapoint:
- attributes["cpu"] == "cpu1"
For additional info, this is what hostmetrics CPU looks like when printed out using debug
exporters with verbosity: detailed
:
Metric #0
Descriptor:
-> Name: system.cpu.time
-> Description: Total seconds each logical CPU spent on each mode.
-> Unit: s
-> DataType: Sum
-> IsMonotonic: true
-> AggregationTemporality: Cumulative
NumberDataPoints #0
Data point attributes:
-> cpu: Str(cpu0)
-> state: Str(user)
StartTimestamp: 2024-07-13 17:45:32 +0000 UTC
Timestamp: 2024-07-15 07:01:21.909324181 +0000 UTC
Value: 364.330000