diff --git a/README.md b/README.md index 116e2939..65199f88 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ ethtool | metrics | --collector.ethtool.metrics-include | N/A filesystem | fs-types | N/A | --collector.filesystem.fs-types-exclude filesystem | mount-points | N/A | --collector.filesystem.mount-points-exclude hwmon | chip | --collector.hwmon.chip-include | --collector.hwmon.chip-exclude +hwmon | sensor | --collector.hwmon.sensor-include | --collector.hwmon.sensor-exclude netdev | device | --collector.netdev.device-include | --collector.netdev.device-exclude qdisk | device | --collector.qdisk.device-include | --collector.qdisk.device-exclude slabinfo | slab-names | --collector.slabinfo.slabs-include | --collector.slabinfo.slabs-exclude diff --git a/collector/hwmon_linux.go b/collector/hwmon_linux.go index a8086d30..ed46f0f8 100644 --- a/collector/hwmon_linux.go +++ b/collector/hwmon_linux.go @@ -32,8 +32,10 @@ import ( ) var ( - collectorHWmonChipInclude = kingpin.Flag("collector.hwmon.chip-include", "Regexp of hwmon chip to include (mutually exclusive to device-exclude).").String() - collectorHWmonChipExclude = kingpin.Flag("collector.hwmon.chip-exclude", "Regexp of hwmon chip to exclude (mutually exclusive to device-include).").String() + collectorHWmonChipInclude = kingpin.Flag("collector.hwmon.chip-include", "Regexp of hwmon chip to include (mutually exclusive to device-exclude).").String() + collectorHWmonChipExclude = kingpin.Flag("collector.hwmon.chip-exclude", "Regexp of hwmon chip to exclude (mutually exclusive to device-include).").String() + collectorHWmonSensorInclude = kingpin.Flag("collector.hwmon.sensor-include", "Regexp of hwmon sensor to include (mutually exclusive to sensor-exclude).").String() + collectorHWmonSensorExclude = kingpin.Flag("collector.hwmon.sensor-exclude", "Regexp of hwmon sensor to exclude (mutually exclusive to sensor-include).").String() hwmonInvalidMetricChars = regexp.MustCompile("[^a-z0-9:_]") hwmonFilenameFormat = regexp.MustCompile(`^(?P[^0-9]+)(?P[0-9]*)?(_(?P.+))?$`) @@ -52,6 +54,7 @@ func init() { type hwMonCollector struct { deviceFilter deviceFilter + sensorFilter deviceFilter logger log.Logger } @@ -62,6 +65,7 @@ func NewHwMonCollector(logger log.Logger) (Collector, error) { return &hwMonCollector{ logger: logger, deviceFilter: newDeviceFilter(*collectorHWmonChipExclude, *collectorHWmonChipInclude), + sensorFilter: newDeviceFilter(*collectorHWmonSensorExclude, *collectorHWmonSensorInclude), }, nil } @@ -202,6 +206,15 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) er // Format all sensors. for sensor, sensorData := range data { + // Filtering for sensors is done on concatenated device name and sensor name + // separated by a semicolon. This allows for excluding or including of specific + // sensors on specific devices. For example, to exclude the sensor "temp3" on + // the device "platform_coretemp_0", use "platform_coretemp_0;temp3" + if c.sensorFilter.ignored(hwmonName + ";" + sensor) { + level.Debug(c.logger).Log("msg", "ignoring sensor", "sensor", sensor) + continue + } + _, sensorType, _, _ := explodeSensorFilename(sensor) labels := []string{hwmonName, sensor}