From c711385e3c340555dc8f2a75fae098d5b61a4e32 Mon Sep 17 00:00:00 2001 From: Devin Trejo Date: Thu, 1 Aug 2024 06:40:02 -0400 Subject: [PATCH] improvement: Expose hwmon collector config options in prometheus.exporter.unix component. (#1369) * improvement: Expose hwmon collector config options in prometheus.exporter.unix component. * Cleanup docs. Add changelog. Consitent naming hwmon. * Cleanup changelog. * Add to convert command. Fix docstrings suggestions from PR review * PR review doc recommendations --------- Co-authored-by: William Dumont --- CHANGELOG.md | 2 ++ .../components/prometheus/prometheus.exporter.unix.md | 9 +++++++++ internal/component/prometheus/exporter/unix/config.go | 9 +++++++++ .../staticconvert/internal/build/node_exporter.go | 4 ++++ internal/static/integrations/node_exporter/config.go | 7 +++++++ 5 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf863e75cb..0faa4cfca0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,8 @@ Main (unreleased) - `mimir.rules.kubernetes` is now able to add extra labels to the Prometheus rules. (@psychomantys) +- `prometheus.exporter.unix` component now exposes hwmon collector config. (@dtrejod) + - Upgrade from OpenTelemetry v0.102.1 to v0.105.0. - [`otelcol.receiver.*`] A new `compression_algorithms` attribute to configure which compression algorithms are allowed by the HTTP server. diff --git a/docs/sources/reference/components/prometheus/prometheus.exporter.unix.md b/docs/sources/reference/components/prometheus/prometheus.exporter.unix.md index 502d15a35d..b5e22f86c5 100644 --- a/docs/sources/reference/components/prometheus/prometheus.exporter.unix.md +++ b/docs/sources/reference/components/prometheus/prometheus.exporter.unix.md @@ -60,6 +60,7 @@ The following blocks are supported inside the definition of `prometheus.exporter | disk | [disk][] | Configures the diskstats collector. | no | | ethtool | [ethtool][] | Configures the ethtool collector. | no | | filesystem | [filesystem][] | Configures the filesystem collector. | no | +| hwmon | [hwmon][] | Configures the hwmon collector. | no | | ipvs | [ipvs][] | Configures the ipvs collector. | no | | ntp | [ntp][] | Configures the ntp collector. | no | | netclass | [netclass][] | Configures the netclass collector. | no | @@ -80,6 +81,7 @@ The following blocks are supported inside the definition of `prometheus.exporter [disk]: #disk-block [ethtool]: #ethtool-block [filesystem]: #filesystem-block +[hwmon]: #hwmon-block [ipvs]: #ipvs-block [ntp]: #ntp-block [netclass]: #netclass-block @@ -163,6 +165,13 @@ The default values vary by the operating system {{< param "PRODUCT_NAME" >}} run ``` {{< /code >}} +### hwmon block + +| Name | Type | Description | Default | Required | +|--------------------|------------|------------------------------------------------------------------------------------|----------|----------| +| `chip_include` | `string` | Regular expression of hwmon chip to include. Mutually exclusive to `chip-exclude`. | | no | +| `chip_exclude` | `string` | Regular expression of hwmon chip to exclude. Mutually exclusive to `chip-include`. | | no | + ### ipvs block | Name | Type | Description | Default | Required | diff --git a/internal/component/prometheus/exporter/unix/config.go b/internal/component/prometheus/exporter/unix/config.go index 373db2dc5e..027158366c 100644 --- a/internal/component/prometheus/exporter/unix/config.go +++ b/internal/component/prometheus/exporter/unix/config.go @@ -85,6 +85,7 @@ type Arguments struct { Disk DiskStatsConfig `alloy:"disk,block,optional"` EthTool EthToolConfig `alloy:"ethtool,block,optional"` Filesystem FilesystemConfig `alloy:"filesystem,block,optional"` + HwMon HwMonConfig `alloy:"hwmon,block,optional"` IPVS IPVSConfig `alloy:"ipvs,block,optional"` NTP NTPConfig `alloy:"ntp,block,optional"` Netclass NetclassConfig `alloy:"netclass,block,optional"` @@ -125,6 +126,8 @@ func (a *Arguments) Convert() *node_integration.Config { FilesystemFSTypesExclude: a.Filesystem.FSTypesExclude, FilesystemMountPointsExclude: a.Filesystem.MountPointsExclude, FilesystemMountTimeout: a.Filesystem.MountTimeout, + HwMonChipInclude: a.HwMon.ChipInclude, + HwMonChipExclude: a.HwMon.ChipExclude, IPVSBackendLabels: a.IPVS.BackendLabels, NTPIPTTL: a.NTP.IPTTL, NTPLocalOffsetTolerance: a.NTP.LocalOffsetTolerance, @@ -236,6 +239,12 @@ type EthToolConfig struct { MetricsInclude string `alloy:"metrics_include,attr,optional"` } +// HwMonConfig contains config specific to the hwmon collector. +type HwMonConfig struct { + ChipExclude string `alloy:"chip_exclude,attr,optional"` + ChipInclude string `alloy:"chip_include,attr,optional"` +} + // FilesystemConfig contains config specific to the filesystem collector. type FilesystemConfig struct { FSTypesExclude string `alloy:"fs_types_exclude,attr,optional"` diff --git a/internal/converter/internal/staticconvert/internal/build/node_exporter.go b/internal/converter/internal/staticconvert/internal/build/node_exporter.go index cd9174a7f4..d24615b9e6 100644 --- a/internal/converter/internal/staticconvert/internal/build/node_exporter.go +++ b/internal/converter/internal/staticconvert/internal/build/node_exporter.go @@ -44,6 +44,10 @@ func toNodeExporter(config *node_exporter.Config) *unix.Arguments { MountPointsExclude: config.FilesystemMountPointsExclude, MountTimeout: config.FilesystemMountTimeout, }, + HwMon: unix.HwMonConfig{ + ChipExclude: config.HwMonChipExclude, + ChipInclude: config.HwMonChipInclude, + }, IPVS: unix.IPVSConfig{ BackendLabels: config.IPVSBackendLabels, }, diff --git a/internal/static/integrations/node_exporter/config.go b/internal/static/integrations/node_exporter/config.go index b49f46dcc1..c62852744a 100644 --- a/internal/static/integrations/node_exporter/config.go +++ b/internal/static/integrations/node_exporter/config.go @@ -112,6 +112,8 @@ type Config struct { FilesystemFSTypesExclude string `yaml:"filesystem_fs_types_exclude,omitempty"` FilesystemMountPointsExclude string `yaml:"filesystem_mount_points_exclude,omitempty"` FilesystemMountTimeout time.Duration `yaml:"filesystem_mount_timeout,omitempty"` + HwMonChipInclude string `yaml:"hwmon_chip_include,omitempty"` + HwMonChipExclude string `yaml:"hwmon_chip_exclude,omitempty"` IPVSBackendLabels []string `yaml:"ipvs_backend_labels,omitempty"` NTPIPTTL int `yaml:"ntp_ip_ttl,omitempty"` NTPLocalOffsetTolerance time.Duration `yaml:"ntp_local_offset_tolerance,omitempty"` @@ -382,6 +384,11 @@ func (c *Config) mapConfigToNodeConfig() *collector.NodeCollectorConfig { StatWorkerCount: &blankInt, } + cfg.HwMon = collector.HwMonConfig{ + ChipInclude: &c.HwMonChipInclude, + ChipExclude: &c.HwMonChipExclude, + } + var joinedLabels string if len(c.IPVSBackendLabels) > 0 { joinedLabels = strings.Join(c.IPVSBackendLabels, ",")