Merge config changes

This commit is contained in:
matt durham 2023-09-28 09:26:34 -04:00
parent 2e027c850e
commit 2f4d563976
No known key found for this signature in database
GPG key ID: A62E920AE398897B
31 changed files with 215 additions and 282 deletions

View file

@ -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)

View file

@ -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) {

205
collector/config.go Normal file
View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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 {

View file

@ -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.

View file

@ -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
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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)

View file

@ -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)
}

View file

@ -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) {

View file

@ -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)

View file

@ -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)
}

View file

@ -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,

View file

@ -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{

View file

@ -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 != "" {

View file

@ -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)

View file

@ -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 (

View file

@ -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)

View file

@ -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 (

View file

@ -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 {

View file

@ -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"

View file

@ -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) {

View file

@ -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) {

View file

@ -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)

View file

@ -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.