From dde374e68a285f93d62931fee057043a8b4cf546 Mon Sep 17 00:00:00 2001 From: matt durham Date: Wed, 27 Sep 2023 12:01:37 -0400 Subject: [PATCH 1/8] spceific arch configs --- collector/config_bsds.go | 27 ++++++++++++++++++++++++ collector/config_darwin.go | 26 +++++++++++++++++++++++ collector/{config.go => config_linux.go} | 0 collector/config_solaris.go | 22 +++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 collector/config_bsds.go create mode 100644 collector/config_darwin.go rename collector/{config.go => config_linux.go} (100%) create mode 100644 collector/config_solaris.go diff --git a/collector/config_bsds.go b/collector/config_bsds.go new file mode 100644 index 0000000000..f7a8a73f97 --- /dev/null +++ b/collector/config_bsds.go @@ -0,0 +1,27 @@ +// Copyright 2023 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build dragonfly || freebsd || netbsd || openbsd +// +build dragonfly freebsd netbsd openbsd + +package collector + +type NodeCollectorConfig struct { + Filesystem FilesystemConfig + NetDev NetDevConfig + NTP NTPConfig + Path PathConfig + Runit RunitConfig + Supervisord SupervisordConfig + TextFile TextFileConfig +} diff --git a/collector/config_darwin.go b/collector/config_darwin.go new file mode 100644 index 0000000000..5470b33155 --- /dev/null +++ b/collector/config_darwin.go @@ -0,0 +1,26 @@ +// Copyright 2023 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package collector + +type NodeCollectorConfig struct { + DiskstatsDeviceFilter DiskstatsDeviceFilterConfig + Filesystem FilesystemConfig + NetDev NetDevConfig + NTP NTPConfig + Path PathConfig + PowerSupplyClass PowerSupplyClassConfig + Runit RunitConfig + Supervisord SupervisordConfig + TextFile TextFileConfig +} diff --git a/collector/config.go b/collector/config_linux.go similarity index 100% rename from collector/config.go rename to collector/config_linux.go diff --git a/collector/config_solaris.go b/collector/config_solaris.go new file mode 100644 index 0000000000..c79f459925 --- /dev/null +++ b/collector/config_solaris.go @@ -0,0 +1,22 @@ +// Copyright 2023 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package collector + +type NodeCollectorConfig struct { + NTP NTPConfig + Path PathConfig + Runit RunitConfig + Supervisord SupervisordConfig + TextFile TextFileConfig +} From e7bf2f85793b3d7f8e192a3dd41478c1adda651e Mon Sep 17 00:00:00 2001 From: matt durham Date: Wed, 27 Sep 2023 12:10:39 -0400 Subject: [PATCH 2/8] update amd openbsd --- collector/config_bsds.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/collector/config_bsds.go b/collector/config_bsds.go index f7a8a73f97..7537c01085 100644 --- a/collector/config_bsds.go +++ b/collector/config_bsds.go @@ -17,11 +17,12 @@ package collector type NodeCollectorConfig struct { - Filesystem FilesystemConfig - NetDev NetDevConfig - NTP NTPConfig - Path PathConfig - Runit RunitConfig - Supervisord SupervisordConfig - TextFile TextFileConfig + DiskstatsDeviceFilter DiskstatsDeviceFilterConfig + Filesystem FilesystemConfig + NetDev NetDevConfig + NTP NTPConfig + Path PathConfig + Runit RunitConfig + Supervisord SupervisordConfig + TextFile TextFileConfig } From 2e027c850efc3c583d37c6278b3464a5d36b1d0b Mon Sep 17 00:00:00 2001 From: matt durham Date: Wed, 27 Sep 2023 12:24:00 -0400 Subject: [PATCH 3/8] fix issues --- collector/config_bsds.go | 4 ++-- collector/filesystem_bsd.go | 4 ++-- collector/filesystem_common.go | 2 +- collector/loadavg.go | 2 +- collector/netdev_common.go | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/collector/config_bsds.go b/collector/config_bsds.go index 7537c01085..5d11748c93 100644 --- a/collector/config_bsds.go +++ b/collector/config_bsds.go @@ -11,8 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build dragonfly || freebsd || netbsd || openbsd -// +build dragonfly freebsd netbsd openbsd +//go:build dragonfly || freebsd || netbsd || openbsd || 386 +// +build dragonfly freebsd netbsd openbsd 386 package collector diff --git a/collector/filesystem_bsd.go b/collector/filesystem_bsd.go index d3025a0171..ccd71a77bc 100644 --- a/collector/filesystem_bsd.go +++ b/collector/filesystem_bsd.go @@ -39,7 +39,7 @@ const ( ) // Expose filesystem fullness. -func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { +func (c *filesystemCollector) GetStats(p PathConfig) (stats []filesystemStats, err error) { var mntbuf *C.struct_statfs count := C.getmntinfo(&mntbuf, C.MNT_NOWAIT) if count == 0 { @@ -70,7 +70,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { stats = append(stats, filesystemStats{ labels: filesystemLabels{ device: device, - mountPoint: rootfsStripPrefix(mountpoint), + mountPoint: p.rootfsStripPrefix(mountpoint), fsType: fstype, }, size: float64(mnt[i].f_blocks) * float64(mnt[i].f_bsize), diff --git a/collector/filesystem_common.go b/collector/filesystem_common.go index 8072781845..6e0deddcbe 100644 --- a/collector/filesystem_common.go +++ b/collector/filesystem_common.go @@ -165,7 +165,7 @@ func NewFilesystemCollector(config *NodeCollectorConfig, logger log.Logger) (Col } func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) error { - stats, err := c.GetStats() + stats, err := c.GetStats(c.config.Path) if err != nil { return err } diff --git a/collector/loadavg.go b/collector/loadavg.go index 086886c474..62e3f5c421 100644 --- a/collector/loadavg.go +++ b/collector/loadavg.go @@ -49,7 +49,7 @@ func NewLoadavgCollector(config *NodeCollectorConfig, logger log.Logger) (Collec } func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) error { - loads, err := getLoad(c.config) + loads, err := getLoad() if err != nil { return fmt.Errorf("couldn't get load: %w", err) } diff --git a/collector/netdev_common.go b/collector/netdev_common.go index e789bdd3b8..33ef202328 100644 --- a/collector/netdev_common.go +++ b/collector/netdev_common.go @@ -112,7 +112,7 @@ func (c *netDevCollector) metricDesc(key string) *prometheus.Desc { } func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error { - netDev, err := getNetDevStats(c.config, c.config.NetDev.Netlink, &c.deviceFilter, c.logger) + netDev, err := getNetDevStats(&c.deviceFilter, c.logger) if err != nil { return fmt.Errorf("couldn't get netstats: %w", err) } From 2f4d56397675fd2ee495c25c8d12d5f8097714c2 Mon Sep 17 00:00:00 2001 From: matt durham Date: Thu, 28 Sep 2023 09:26:34 -0400 Subject: [PATCH 4/8] Merge config changes --- collector/arp_linux.go | 6 - collector/bcache_linux.go | 4 - collector/config.go | 205 +++++++++++++++++++++++++++++++++ collector/config_bsds.go | 28 ----- collector/config_darwin.go | 26 ----- collector/config_linux.go | 43 ------- collector/config_solaris.go | 22 ---- collector/cpu_netbsd.go | 12 +- collector/diskstats_common.go | 7 -- collector/ethtool_linux.go | 6 - collector/filesystem_common.go | 16 +-- collector/hwmon_linux.go | 5 - collector/ipvs_linux.go | 4 - collector/netclass_linux.go | 7 -- collector/netdev_common.go | 12 +- collector/netstat_linux.go | 4 - collector/ntp.go | 10 -- collector/paths.go | 7 -- collector/perf_linux.go | 11 -- collector/powersupplyclass.go | 4 - collector/qdisc_linux.go | 8 -- collector/rapl_linux.go | 4 - collector/runit.go | 4 - collector/stat_linux.go | 4 - collector/supervisord.go | 4 - collector/sysctl_linux.go | 5 - collector/systemd_linux.go | 13 --- collector/tapestats_linux.go | 4 - collector/textfile.go | 4 - collector/vmstat_linux.go | 4 - collector/wifi_linux.go | 4 - 31 files changed, 215 insertions(+), 282 deletions(-) create mode 100644 collector/config.go delete mode 100644 collector/config_bsds.go delete mode 100644 collector/config_darwin.go delete mode 100644 collector/config_linux.go delete mode 100644 collector/config_solaris.go diff --git a/collector/arp_linux.go b/collector/arp_linux.go index 75059c1b7b..7d8e7edc40 100644 --- a/collector/arp_linux.go +++ b/collector/arp_linux.go @@ -40,12 +40,6 @@ func init() { registerCollector("arp", defaultEnabled, NewARPCollector) } -type ArpConfig struct { - DeviceInclude *string - DeviceExclude *string - Netlink *bool -} - // NewARPCollector returns a new Collector exposing ARP stats. func NewARPCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { fs, err := procfs.NewFS(*config.Path.ProcPath) diff --git a/collector/bcache_linux.go b/collector/bcache_linux.go index 6773587bcb..bcae26868e 100644 --- a/collector/bcache_linux.go +++ b/collector/bcache_linux.go @@ -36,10 +36,6 @@ type bcacheCollector struct { config *NodeCollectorConfig } -type BcacheConfig struct { - PriorityStats *bool -} - // NewBcacheCollector returns a newly allocated bcacheCollector. // It exposes a number of Linux bcache statistics. func NewBcacheCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { diff --git a/collector/config.go b/collector/config.go new file mode 100644 index 0000000000..1ec2eff5bf --- /dev/null +++ b/collector/config.go @@ -0,0 +1,205 @@ +// Copyright 2023 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package collector + +import "time" + +type NodeCollectorConfig struct { + Arp ArpConfig + Bcache BcacheConfig + CPU CPUConfig + DiskstatsDeviceFilter DiskstatsDeviceFilterConfig + Ethtool EthtoolConfig + Filesystem FilesystemConfig + HwMon HwMonConfig + IPVS IPVSConfig + NetClass NetClassConfig + NetDev NetDevConfig + NetStat NetStatConfig + NTP NTPConfig + Path PathConfig + Perf PerfConfig + PowerSupplyClass PowerSupplyClassConfig + Qdisc QdiscConfig + Rapl RaplConfig + Runit RunitConfig + Stat StatConfig + Supervisord SupervisordConfig + Sysctl SysctlConfig + Systemd SystemdConfig + Tapestats TapestatsConfig + TextFile TextFileConfig + VmStat VmStatConfig + Wifi WifiConfig +} + +type WifiConfig struct { + Fixtures *string +} + +type VmStatConfig struct { + Fields *string +} + +type TextFileConfig struct { + Directory *string +} +type TapestatsConfig struct { + IgnoredDevices *string +} + +type SystemdConfig struct { + UnitInclude *string + UnitIncludeSet bool + UnitExclude *string + UnitExcludeSet bool + OldUnitInclude *string + OldUnitExclude *string + Private *bool + EnableTaskMetrics *bool + EnableRestartsMetrics *bool + EnableStartTimeMetrics *bool +} + +type SysctlConfig struct { + Include *[]string + IncludeInfo *[]string +} + +type SupervisordConfig struct { + URL *string +} + +type RunitConfig struct { + ServiceDir *string +} + +type StatConfig struct { + Softirq *bool +} + +type RaplConfig struct { + ZoneLabel *bool +} + +type QdiscConfig struct { + Fixtures *string + DeviceInclude *string + OldDeviceInclude *string + DeviceExclude *string + OldDeviceExclude *string +} + +type PowerSupplyClassConfig struct { + IgnoredPowerSupplies *string +} + +type PerfConfig struct { + CPUs *string + Tracepoint *[]string + NoHwProfiler *bool + HwProfiler *[]string + NoSwProfiler *bool + SwProfiler *[]string + NoCaProfiler *bool + CaProfilerFlag *[]string +} + +type PathConfig struct { + ProcPath *string + SysPath *string + RootfsPath *string + UdevDataPath *string +} + +type NTPConfig struct { + Server *string + ServerPort *int + ProtocolVersion *int + ServerIsLocal *bool + IPTTL *int + MaxDistance *time.Duration + OffsetTolerance *time.Duration +} + +type NetStatConfig struct { + Fields *string +} + +type NetDevConfig struct { + DeviceInclude *string + OldDeviceInclude *string + DeviceExclude *string + OldDeviceExclude *string + AddressInfo *bool + DetailedMetrics *bool + Netlink *bool +} + +type NetClassConfig struct { + IgnoredDevices *string + InvalidSpeed *bool + Netlink *bool + RTNLWithStats *bool +} + +type ArpConfig struct { + DeviceInclude *string + DeviceExclude *string + Netlink *bool +} + +type BcacheConfig struct { + PriorityStats *bool +} + +type CPUConfig struct { + EnableCPUGuest *bool + EnableCPUInfo *bool + FlagsInclude *string + BugsInclude *string +} + +type DiskstatsDeviceFilterConfig struct { + DeviceExclude *string + DeviceExcludeSet bool + OldDeviceExclude *string + DeviceInclude *string +} + +type EthtoolConfig struct { + DeviceInclude *string + DeviceExclude *string + IncludedMetrics *string +} + +type HwMonConfig struct { + ChipInclude *string + ChipExclude *string +} + +type FilesystemConfig struct { + MountPointsExclude *string + MountPointsExcludeSet bool + OldMountPointsExcluded *string + FSTypesExclude *string + FSTypesExcludeSet bool + OldFSTypesExcluded *string + MountTimeout *time.Duration + StatWorkerCount *int +} + +type IPVSConfig struct { + Labels *string +} diff --git a/collector/config_bsds.go b/collector/config_bsds.go deleted file mode 100644 index 5d11748c93..0000000000 --- a/collector/config_bsds.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2023 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build dragonfly || freebsd || netbsd || openbsd || 386 -// +build dragonfly freebsd netbsd openbsd 386 - -package collector - -type NodeCollectorConfig struct { - DiskstatsDeviceFilter DiskstatsDeviceFilterConfig - Filesystem FilesystemConfig - NetDev NetDevConfig - NTP NTPConfig - Path PathConfig - Runit RunitConfig - Supervisord SupervisordConfig - TextFile TextFileConfig -} diff --git a/collector/config_darwin.go b/collector/config_darwin.go deleted file mode 100644 index 5470b33155..0000000000 --- a/collector/config_darwin.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2023 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package collector - -type NodeCollectorConfig struct { - DiskstatsDeviceFilter DiskstatsDeviceFilterConfig - Filesystem FilesystemConfig - NetDev NetDevConfig - NTP NTPConfig - Path PathConfig - PowerSupplyClass PowerSupplyClassConfig - Runit RunitConfig - Supervisord SupervisordConfig - TextFile TextFileConfig -} diff --git a/collector/config_linux.go b/collector/config_linux.go deleted file mode 100644 index 324a06fffc..0000000000 --- a/collector/config_linux.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2023 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package collector - -type NodeCollectorConfig struct { - Arp ArpConfig - Bcache BcacheConfig - CPU CPUConfig - DiskstatsDeviceFilter DiskstatsDeviceFilterConfig - Ethtool EthtoolConfig - Filesystem FilesystemConfig - HwMon HwMonConfig - IPVS IPVSConfig - NetClass NetClassConfig - NetDev NetDevConfig - NetStat NetStatConfig - NTP NTPConfig - Path PathConfig - Perf PerfConfig - PowerSupplyClass PowerSupplyClassConfig - Qdisc QdiscConfig - Rapl RaplConfig - Runit RunitConfig - Stat StatConfig - Supervisord SupervisordConfig - Sysctl SysctlConfig - Systemd SystemdConfig - Tapestats TapestatsConfig - TextFile TextFileConfig - VmStat VmStatConfig - Wifi WifiConfig -} diff --git a/collector/config_solaris.go b/collector/config_solaris.go deleted file mode 100644 index c79f459925..0000000000 --- a/collector/config_solaris.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2023 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package collector - -type NodeCollectorConfig struct { - NTP NTPConfig - Path PathConfig - Runit RunitConfig - Supervisord SupervisordConfig - TextFile TextFileConfig -} diff --git a/collector/cpu_netbsd.go b/collector/cpu_netbsd.go index 776b45496b..4bf1aaf27d 100644 --- a/collector/cpu_netbsd.go +++ b/collector/cpu_netbsd.go @@ -92,8 +92,8 @@ func ioctl(fd int, nr int64, typ byte, size uintptr, retptr unsafe.Pointer) erro return nil } -func readSysmonProperties() (sysmonProperties, error) { - fd, err := unix.Open(rootfsFilePath("/dev/sysmon"), unix.O_RDONLY, 0777) +func readSysmonProperties(p PathConfig) (sysmonProperties, error) { + fd, err := unix.Open(p.rootfsStripPrefix("/dev/sysmon"), unix.O_RDONLY, 0777) if err != nil { return nil, err } @@ -142,12 +142,12 @@ func convertTemperatures(prop sysmonProperty, res map[int]float64) error { return nil } -func getCPUTemperatures() (map[int]float64, error) { +func getCPUTemperatures(p PathConfig) (map[int]float64, error) { res := make(map[int]float64) // Read all properties - props, err := readSysmonProperties() + props, err := readSysmonProperties(p) if err != nil { return res, err } @@ -215,6 +215,7 @@ type statCollector struct { cpu typedDesc temp typedDesc logger log.Logger + p PathConfig } func init() { @@ -231,6 +232,7 @@ func NewStatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector []string{"cpu"}, nil, ), prometheus.GaugeValue}, logger: logger, + p: config.Path, }, nil } @@ -253,7 +255,7 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error { return err } - cpuTemperatures, err := getCPUTemperatures() + cpuTemperatures, err := getCPUTemperatures(c.p) if err != nil { return err } diff --git a/collector/diskstats_common.go b/collector/diskstats_common.go index 0b927e8689..e636aa689c 100644 --- a/collector/diskstats_common.go +++ b/collector/diskstats_common.go @@ -77,13 +77,6 @@ var ( ) ) -type DiskstatsDeviceFilterConfig struct { - DeviceExclude *string - DeviceExcludeSet bool - OldDeviceExclude *string - DeviceInclude *string -} - func newDiskstatsDeviceFilter(config DiskstatsDeviceFilterConfig, logger log.Logger) (deviceFilter, error) { if *config.OldDeviceExclude != "" { if !config.DeviceExcludeSet { diff --git a/collector/ethtool_linux.go b/collector/ethtool_linux.go index 860445bf00..6bfc869c4a 100644 --- a/collector/ethtool_linux.go +++ b/collector/ethtool_linux.go @@ -78,12 +78,6 @@ type ethtoolCollector struct { logger log.Logger } -type EthtoolConfig struct { - DeviceInclude *string - DeviceExclude *string - IncludedMetrics *string -} - // makeEthtoolCollector is the internal constructor for EthtoolCollector. // This allows NewEthtoolTestCollector to override its .ethtool interface // for testing. diff --git a/collector/filesystem_common.go b/collector/filesystem_common.go index 6e0deddcbe..aca57da7a1 100644 --- a/collector/filesystem_common.go +++ b/collector/filesystem_common.go @@ -19,12 +19,10 @@ package collector import ( "errors" - "regexp" - "time" - "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" + "regexp" ) // Arch-dependent implementation must define: @@ -57,16 +55,6 @@ type filesystemStats struct { files, filesFree float64 ro, deviceError float64 } -type FilesystemConfig struct { - MountPointsExclude *string - MountPointsExcludeSet bool - OldMountPointsExcluded *string - FSTypesExclude *string - FSTypesExcludeSet bool - OldFSTypesExcluded *string - MountTimeout *time.Duration - StatWorkerCount *int -} func init() { registerCollector("filesystem", defaultEnabled, NewFilesystemCollector) @@ -165,7 +153,7 @@ func NewFilesystemCollector(config *NodeCollectorConfig, logger log.Logger) (Col } func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) error { - stats, err := c.GetStats(c.config.Path) + stats, err := c.GetStats() if err != nil { return err } diff --git a/collector/hwmon_linux.go b/collector/hwmon_linux.go index 7ce6e904ee..40fd559975 100644 --- a/collector/hwmon_linux.go +++ b/collector/hwmon_linux.go @@ -52,11 +52,6 @@ type hwMonCollector struct { config *NodeCollectorConfig } -type HwMonConfig struct { - ChipInclude *string - ChipExclude *string -} - // NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats // (similar to lm-sensors). func NewHwMonCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { diff --git a/collector/ipvs_linux.go b/collector/ipvs_linux.go index 266e9f805b..487a25dcc5 100644 --- a/collector/ipvs_linux.go +++ b/collector/ipvs_linux.go @@ -69,10 +69,6 @@ func init() { registerCollector("ipvs", defaultEnabled, NewIPVSCollector) } -type IPVSConfig struct { - Labels *string -} - // NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the // "procfs" config parameter to override the default proc location (/proc). func NewIPVSCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { diff --git a/collector/netclass_linux.go b/collector/netclass_linux.go index 38a6dd4da2..0cacb9fbc7 100644 --- a/collector/netclass_linux.go +++ b/collector/netclass_linux.go @@ -42,13 +42,6 @@ func init() { registerCollector("netclass", defaultEnabled, NewNetClassCollector) } -type NetClassConfig struct { - IgnoredDevices *string - InvalidSpeed *bool - Netlink *bool - RTNLWithStats *bool -} - // NewNetClassCollector returns a new Collector exposing network class stats. func NewNetClassCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { fs, err := sysfs.NewFS(*config.Path.SysPath) diff --git a/collector/netdev_common.go b/collector/netdev_common.go index 33ef202328..b841378e16 100644 --- a/collector/netdev_common.go +++ b/collector/netdev_common.go @@ -44,16 +44,6 @@ func init() { registerCollector("netdev", defaultEnabled, NewNetDevCollector) } -type NetDevConfig struct { - DeviceInclude *string - OldDeviceInclude *string - DeviceExclude *string - OldDeviceExclude *string - AddressInfo *bool - DetailedMetrics *bool - Netlink *bool -} - // NewNetDevCollector returns a new Collector exposing network device stats. func NewNetDevCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { if *config.NetDev.OldDeviceInclude != "" { @@ -112,7 +102,7 @@ func (c *netDevCollector) metricDesc(key string) *prometheus.Desc { } func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error { - netDev, err := getNetDevStats(&c.deviceFilter, c.logger) + netDev, err := getNetDevStats(c.config, c.config.NetDev.Netlink, &c.deviceFilter, c.logger) if err != nil { return fmt.Errorf("couldn't get netstats: %w", err) } diff --git a/collector/netstat_linux.go b/collector/netstat_linux.go index a99d023e4f..b3f21dbc01 100644 --- a/collector/netstat_linux.go +++ b/collector/netstat_linux.go @@ -44,10 +44,6 @@ func init() { registerCollector(netStatsSubsystem, defaultEnabled, NewNetStatCollector) } -type NetStatConfig struct { - Fields *string -} - // NewNetStatCollector takes and returns // a new Collector exposing network stats. func NewNetStatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { diff --git a/collector/ntp.go b/collector/ntp.go index 6a813380e7..0652e32b9e 100644 --- a/collector/ntp.go +++ b/collector/ntp.go @@ -48,16 +48,6 @@ func init() { registerCollector("ntp", defaultDisabled, NewNtpCollector) } -type NTPConfig struct { - Server *string - ServerPort *int - ProtocolVersion *int - ServerIsLocal *bool - IPTTL *int - MaxDistance *time.Duration - OffsetTolerance *time.Duration -} - // NewNtpCollector returns a new Collector exposing sanity of local NTP server. // Default definition of "local" is: // - collector.ntp.server address is a loopback address (or collector.ntp.server-is-mine flag is turned on) diff --git a/collector/paths.go b/collector/paths.go index e14e0204a5..6a2c665542 100644 --- a/collector/paths.go +++ b/collector/paths.go @@ -18,13 +18,6 @@ import ( "strings" ) -type PathConfig struct { - ProcPath *string - SysPath *string - RootfsPath *string - UdevDataPath *string -} - func (p *PathConfig) procFilePath(name string) string { return filepath.Join(*p.ProcPath, name) } diff --git a/collector/perf_linux.go b/collector/perf_linux.go index 148c3322a1..bedc5a43d4 100644 --- a/collector/perf_linux.go +++ b/collector/perf_linux.go @@ -37,17 +37,6 @@ func init() { registerCollector(perfSubsystem, defaultDisabled, NewPerfCollector) } -type PerfConfig struct { - CPUs *string - Tracepoint *[]string - NoHwProfiler *bool - HwProfiler *[]string - NoSwProfiler *bool - SwProfiler *[]string - NoCaProfiler *bool - CaProfilerFlag *[]string -} - var ( perfHardwareProfilerMap = map[string]perf.HardwareProfilerType{ "CpuCycles": perf.CpuCyclesProfiler, diff --git a/collector/powersupplyclass.go b/collector/powersupplyclass.go index b869f6ca48..89b3875141 100644 --- a/collector/powersupplyclass.go +++ b/collector/powersupplyclass.go @@ -36,10 +36,6 @@ func init() { registerCollector("powersupplyclass", defaultEnabled, NewPowerSupplyClassCollector) } -type PowerSupplyClassConfig struct { - IgnoredPowerSupplies *string -} - func NewPowerSupplyClassCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { pattern := regexp.MustCompile(*config.PowerSupplyClass.IgnoredPowerSupplies) return &powerSupplyClassCollector{ diff --git a/collector/qdisc_linux.go b/collector/qdisc_linux.go index 422520b885..fb5217eceb 100644 --- a/collector/qdisc_linux.go +++ b/collector/qdisc_linux.go @@ -45,14 +45,6 @@ func init() { registerCollector("qdisc", defaultDisabled, NewQdiscStatCollector) } -type QdiscConfig struct { - Fixtures *string - DeviceInclude *string - OldDeviceInclude *string - DeviceExclude *string - OldDeviceExclude *string -} - // NewQdiscStatCollector returns a new Collector exposing queuing discipline statistics. func NewQdiscStatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { if *config.Qdisc.OldDeviceInclude != "" { diff --git a/collector/rapl_linux.go b/collector/rapl_linux.go index 0ec9c4db6e..94a0ba0530 100644 --- a/collector/rapl_linux.go +++ b/collector/rapl_linux.go @@ -42,10 +42,6 @@ func init() { registerCollector(raplCollectorSubsystem, defaultEnabled, NewRaplCollector) } -type RaplConfig struct { - ZoneLabel *bool -} - // NewRaplCollector returns a new Collector exposing RAPL metrics. func NewRaplCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { fs, err := sysfs.NewFS(*config.Path.SysPath) diff --git a/collector/runit.go b/collector/runit.go index cbacdaa5cc..73b406540c 100644 --- a/collector/runit.go +++ b/collector/runit.go @@ -36,10 +36,6 @@ func init() { registerCollector("runit", defaultDisabled, NewRunitCollector) } -type RunitConfig struct { - ServiceDir *string -} - // NewRunitCollector returns a new Collector exposing runit statistics. func NewRunitCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { var ( diff --git a/collector/stat_linux.go b/collector/stat_linux.go index f549306fea..01393387e2 100644 --- a/collector/stat_linux.go +++ b/collector/stat_linux.go @@ -41,10 +41,6 @@ func init() { registerCollector("stat", defaultEnabled, NewStatCollector) } -type StatConfig struct { - Softirq *bool -} - // NewStatCollector returns a new Collector exposing kernel/system statistics. func NewStatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { fs, err := procfs.NewFS(*config.Path.ProcPath) diff --git a/collector/supervisord.go b/collector/supervisord.go index c70ed0603d..57ac5b8f90 100644 --- a/collector/supervisord.go +++ b/collector/supervisord.go @@ -46,10 +46,6 @@ func init() { registerCollector("supervisord", defaultDisabled, NewSupervisordCollector) } -type SupervisordConfig struct { - URL *string -} - // NewSupervisordCollector returns a new Collector exposing supervisord statistics. func NewSupervisordCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { var ( diff --git a/collector/sysctl_linux.go b/collector/sysctl_linux.go index a98d82afad..63c1307dc6 100644 --- a/collector/sysctl_linux.go +++ b/collector/sysctl_linux.go @@ -37,11 +37,6 @@ func init() { registerCollector("sysctl", defaultDisabled, NewSysctlCollector) } -type SysctlConfig struct { - Include *[]string - IncludeInfo *[]string -} - func NewSysctlCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { fs, err := procfs.NewFS(*config.Path.ProcPath) if err != nil { diff --git a/collector/systemd_linux.go b/collector/systemd_linux.go index 2aa46716f6..869fc6f30c 100644 --- a/collector/systemd_linux.go +++ b/collector/systemd_linux.go @@ -70,19 +70,6 @@ func init() { registerCollector("systemd", defaultDisabled, NewSystemdCollector) } -type SystemdConfig struct { - UnitInclude *string - UnitIncludeSet bool - UnitExclude *string - UnitExcludeSet bool - OldUnitInclude *string - OldUnitExclude *string - Private *bool - EnableTaskMetrics *bool - EnableRestartsMetrics *bool - EnableStartTimeMetrics *bool -} - // NewSystemdCollector returns a new Collector exposing systemd statistics. func NewSystemdCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { const subsystem = "systemd" diff --git a/collector/tapestats_linux.go b/collector/tapestats_linux.go index 38a326f3ae..d7088d8408 100644 --- a/collector/tapestats_linux.go +++ b/collector/tapestats_linux.go @@ -47,10 +47,6 @@ func init() { registerCollector("tapestats", defaultEnabled, NewTapestatsCollector) } -type TapestatsConfig struct { - IgnoredDevices *string -} - // NewTapestatsCollector returns a new Collector exposing tape device stats. // Docs from https://www.kernel.org/doc/html/latest/scsi/st.html#sysfs-and-statistics-for-tape-devices func NewTapestatsCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { diff --git a/collector/textfile.go b/collector/textfile.go index 5e5db0aa8e..f60fff8771 100644 --- a/collector/textfile.go +++ b/collector/textfile.go @@ -51,10 +51,6 @@ func init() { registerCollector("textfile", defaultEnabled, NewTextFileCollector) } -type TextFileConfig struct { - Directory *string -} - // NewTextFileCollector returns a new Collector exposing metrics read from files // in the given textfile directory. func NewTextFileCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { diff --git a/collector/vmstat_linux.go b/collector/vmstat_linux.go index bd285a2e38..134362ced9 100644 --- a/collector/vmstat_linux.go +++ b/collector/vmstat_linux.go @@ -42,10 +42,6 @@ func init() { registerCollector(vmStatSubsystem, defaultEnabled, NewvmStatCollector) } -type VmStatConfig struct { - Fields *string -} - // NewvmStatCollector returns a new Collector exposing vmstat stats. func NewvmStatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) { pattern := regexp.MustCompile(*config.VmStat.Fields) diff --git a/collector/wifi_linux.go b/collector/wifi_linux.go index 4f27b6fce7..85cdab17cf 100644 --- a/collector/wifi_linux.go +++ b/collector/wifi_linux.go @@ -52,10 +52,6 @@ func init() { registerCollector("wifi", defaultDisabled, NewWifiCollector) } -type WifiConfig struct { - Fixtures *string -} - var _ wifiStater = &wifi.Client{} // wifiStater is an interface used to swap out a *wifi.Client for end to end tests. From 508bd94ac91956662d83ca90c8bed1b7a437ef82 Mon Sep 17 00:00:00 2001 From: matt durham Date: Thu, 28 Sep 2023 09:26:52 -0400 Subject: [PATCH 5/8] Merge config changes --- collector/cpu_linux.go | 7 ------- collector/loadavg.go | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/collector/cpu_linux.go b/collector/cpu_linux.go index 7d4ea46a4f..c24c0a062c 100644 --- a/collector/cpu_linux.go +++ b/collector/cpu_linux.go @@ -62,13 +62,6 @@ var ( jumpBackDebugMessage = fmt.Sprintf("CPU Idle counter jumped backwards more than %f seconds, possible hotplug event, resetting CPU stats", jumpBackSeconds) ) -type CPUConfig struct { - EnableCPUGuest *bool - EnableCPUInfo *bool - FlagsInclude *string - BugsInclude *string -} - func init() { registerCollector("cpu", defaultEnabled, NewCPUCollector) } diff --git a/collector/loadavg.go b/collector/loadavg.go index 62e3f5c421..086886c474 100644 --- a/collector/loadavg.go +++ b/collector/loadavg.go @@ -49,7 +49,7 @@ func NewLoadavgCollector(config *NodeCollectorConfig, logger log.Logger) (Collec } func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) error { - loads, err := getLoad() + loads, err := getLoad(c.config) if err != nil { return fmt.Errorf("couldn't get load: %w", err) } From dfd66e0c977f403481628f06a2b088dc81d1de0d Mon Sep 17 00:00:00 2001 From: matt durham Date: Thu, 28 Sep 2023 09:29:52 -0400 Subject: [PATCH 6/8] Finish config changes --- collector/config.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/collector/config.go b/collector/config.go index 1ec2eff5bf..1ce8b99f71 100644 --- a/collector/config.go +++ b/collector/config.go @@ -201,5 +201,6 @@ type FilesystemConfig struct { } type IPVSConfig struct { - Labels *string + Labels *string + LabelsSet bool } From 302c8c817621e04cb58e8315c405ee62b57ff264 Mon Sep 17 00:00:00 2001 From: matt durham Date: Thu, 28 Sep 2023 09:38:11 -0400 Subject: [PATCH 7/8] Fix netdev signature --- collector/netdev_darwin.go | 2 +- collector/netdev_openbsd.go | 2 +- collector/netdev_openbsd_amd64.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/collector/netdev_darwin.go b/collector/netdev_darwin.go index c08f1f8ede..fc68822d02 100644 --- a/collector/netdev_darwin.go +++ b/collector/netdev_darwin.go @@ -27,7 +27,7 @@ import ( "golang.org/x/sys/unix" ) -func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) { +func getNetDevStats(_ *NodeCollectorConfig, _ *bool, filter *deviceFilter, logger log.Logger) (netDevStats, error) { netDev := netDevStats{} ifs, err := net.Interfaces() diff --git a/collector/netdev_openbsd.go b/collector/netdev_openbsd.go index b90e3ba7ab..a5397ff33b 100644 --- a/collector/netdev_openbsd.go +++ b/collector/netdev_openbsd.go @@ -31,7 +31,7 @@ import ( */ import "C" -func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) { +func getNetDevStats(_ *NodeCollectorConfig, _ *bool, filter *deviceFilter, logger log.Logger) (netDevStats, error) { netDev := netDevStats{} var ifap, ifa *C.struct_ifaddrs diff --git a/collector/netdev_openbsd_amd64.go b/collector/netdev_openbsd_amd64.go index da8a81f34e..415cd3eacb 100644 --- a/collector/netdev_openbsd_amd64.go +++ b/collector/netdev_openbsd_amd64.go @@ -24,7 +24,7 @@ import ( "unsafe" ) -func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) { +func getNetDevStats(_ *NodeCollectorConfig, _ *bool, filter *deviceFilter, logger log.Logger) (netDevStats, error) { netDev := netDevStats{} mib := [6]_C_int{unix.CTL_NET, unix.AF_ROUTE, 0, 0, unix.NET_RT_IFLIST, 0} From bc2b7b4dc038b81d150155110e7cefc0dd44ffc2 Mon Sep 17 00:00:00 2001 From: matt durham Date: Thu, 28 Sep 2023 09:56:24 -0400 Subject: [PATCH 8/8] fix filesystem on other archs --- collector/filesystem_common.go | 2 +- collector/filesystem_freebsd.go | 2 +- collector/filesystem_linux.go | 2 +- collector/filesystem_openbsd.go | 2 +- collector/loadavg_bsd.go | 2 +- collector/loadavg_solaris.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/collector/filesystem_common.go b/collector/filesystem_common.go index 824cf2c851..7723b727f4 100644 --- a/collector/filesystem_common.go +++ b/collector/filesystem_common.go @@ -160,7 +160,7 @@ func NewFilesystemCollector(config *NodeCollectorConfig, logger log.Logger) (Col } func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) error { - stats, err := c.GetStats() + stats, err := c.GetStats(c.config.Path) if err != nil { return err } diff --git a/collector/filesystem_freebsd.go b/collector/filesystem_freebsd.go index f05702d14f..327916a59d 100644 --- a/collector/filesystem_freebsd.go +++ b/collector/filesystem_freebsd.go @@ -27,7 +27,7 @@ const ( ) // Expose filesystem fullness. -func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { +func (c *filesystemCollector) GetStats(_ PathConfig) ([]filesystemStats, error) { n, err := unix.Getfsstat(nil, unix.MNT_NOWAIT) if err != nil { return nil, err diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index 963ab561b9..f403d953bc 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -40,7 +40,7 @@ var stuckMounts = make(map[string]struct{}) var stuckMountsMtx = &sync.Mutex{} // GetStats returns filesystem stats. -func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { +func (c *filesystemCollector) GetStats(_ PathConfig) ([]filesystemStats, error) { mps, err := mountPointDetails(c.config, c.logger) if err != nil { return nil, err diff --git a/collector/filesystem_openbsd.go b/collector/filesystem_openbsd.go index 1c1e479e1f..eebb33290c 100644 --- a/collector/filesystem_openbsd.go +++ b/collector/filesystem_openbsd.go @@ -27,7 +27,7 @@ const ( ) // Expose filesystem fullness. -func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { +func (c *filesystemCollector) GetStats(_ PathConfig) (stats []filesystemStats, err error) { var mnt []unix.Statfs_t size, err := unix.Getfsstat(mnt, unix.MNT_NOWAIT) if err != nil { diff --git a/collector/loadavg_bsd.go b/collector/loadavg_bsd.go index a1f5ae6643..1d591b8fbb 100644 --- a/collector/loadavg_bsd.go +++ b/collector/loadavg_bsd.go @@ -23,7 +23,7 @@ import ( "golang.org/x/sys/unix" ) -func getLoad() ([]float64, error) { +func getLoad(_ *NodeCollectorConfig) ([]float64, error) { type loadavg struct { load [3]uint32 scale int diff --git a/collector/loadavg_solaris.go b/collector/loadavg_solaris.go index 316233fa98..4d4c8e0978 100644 --- a/collector/loadavg_solaris.go +++ b/collector/loadavg_solaris.go @@ -43,7 +43,7 @@ func kstatToFloat(ks *kstat.KStat, kstatKey string) float64 { return kstatLoadavg } -func getLoad() ([]float64, error) { +func getLoad(_ *NodeCollectorConfig) ([]float64, error) { tok, err := kstat.Open() if err != nil { panic(err)