Refactor collector package configuration
Add a new pattern to allow moving the flag handling out of the collector package and into a separate package. This allows collector package users to create their own config or flag handling. Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
8fb4f78ce5
commit
9c6ff78e74
|
@ -18,17 +18,12 @@ package collector
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/procfs"
|
||||
)
|
||||
|
||||
var (
|
||||
arpDeviceInclude = kingpin.Flag("collector.arp.device-include", "Regexp of arp devices to include (mutually exclusive to device-exclude).").String()
|
||||
arpDeviceExclude = kingpin.Flag("collector.arp.device-exclude", "Regexp of arp devices to exclude (mutually exclusive to device-include).").String()
|
||||
)
|
||||
|
||||
type arpCollector struct {
|
||||
fs procfs.FS
|
||||
deviceFilter deviceFilter
|
||||
|
@ -41,7 +36,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewARPCollector returns a new Collector exposing ARP stats.
|
||||
func NewARPCollector(logger log.Logger) (Collector, error) {
|
||||
func NewARPCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
@ -49,7 +44,7 @@ func NewARPCollector(logger log.Logger) (Collector, error) {
|
|||
|
||||
return &arpCollector{
|
||||
fs: fs,
|
||||
deviceFilter: newDeviceFilter(*arpDeviceExclude, *arpDeviceInclude),
|
||||
deviceFilter: newDeviceFilter(*config.Arp.DeviceExclude, *config.Arp.DeviceInclude),
|
||||
entries: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "arp", "entries"),
|
||||
"ARP entries by device",
|
||||
|
|
|
@ -41,7 +41,7 @@ type bcacheCollector struct {
|
|||
|
||||
// NewBcacheCollector returns a newly allocated bcacheCollector.
|
||||
// It exposes a number of Linux bcache statistics.
|
||||
func NewBcacheCollector(logger log.Logger) (Collector, error) {
|
||||
func NewBcacheCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := bcache.NewFS(*sysPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
||||
|
|
|
@ -39,7 +39,7 @@ func init() {
|
|||
|
||||
// NewBondingCollector returns a newly allocated bondingCollector.
|
||||
// It exposes the number of configured and active slave of linux bonding interfaces.
|
||||
func NewBondingCollector(logger log.Logger) (Collector, error) {
|
||||
func NewBondingCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &bondingCollector{
|
||||
slaves: typedDesc{prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "bonding", "slaves"),
|
||||
|
|
|
@ -32,7 +32,7 @@ func init() {
|
|||
}
|
||||
|
||||
// newBootTimeCollector returns a new Collector exposing system boot time on BSD systems.
|
||||
func newBootTimeCollector(logger log.Logger) (Collector, error) {
|
||||
func newBootTimeCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &bootTimeCollector{
|
||||
logger: logger,
|
||||
}, nil
|
||||
|
|
|
@ -31,7 +31,7 @@ func init() {
|
|||
registerCollector("boottime", defaultEnabled, newBootTimeCollector)
|
||||
}
|
||||
|
||||
func newBootTimeCollector(logger log.Logger) (Collector, error) {
|
||||
func newBootTimeCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &bootTimeCollector{
|
||||
boottime: typedDesc{
|
||||
prometheus.NewDesc(
|
||||
|
|
|
@ -40,7 +40,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewBtrfsCollector returns a new Collector exposing Btrfs statistics.
|
||||
func NewBtrfsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewBtrfsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := btrfs.NewFS(*sysPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
||||
|
|
|
@ -41,7 +41,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewBuddyinfoCollector returns a new Collector exposing buddyinfo stats.
|
||||
func NewBuddyinfoCollector(logger log.Logger) (Collector, error) {
|
||||
func NewBuddyinfoCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
desc := prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, buddyInfoSubsystem, "blocks"),
|
||||
"Count of free blocks according to size.",
|
||||
|
|
|
@ -38,7 +38,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewCgroupSummaryCollector returns a new Collector exposing a summary of cgroups.
|
||||
func NewCgroupSummaryCollector(logger log.Logger) (Collector, error) {
|
||||
func NewCgroupSummaryCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -50,14 +50,14 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
factories = make(map[string]func(logger log.Logger) (Collector, error))
|
||||
factories = make(map[string]func(config NodeCollectorConfig, logger log.Logger) (Collector, error))
|
||||
initiatedCollectorsMtx = sync.Mutex{}
|
||||
initiatedCollectors = make(map[string]Collector)
|
||||
collectorState = make(map[string]*bool)
|
||||
forcedCollectors = map[string]bool{} // collectors which have been explicitly enabled or disabled
|
||||
)
|
||||
|
||||
func registerCollector(collector string, isDefaultEnabled bool, factory func(logger log.Logger) (Collector, error)) {
|
||||
func registerCollector(collector string, isDefaultEnabled bool, factory func(config NodeCollectorConfig, logger log.Logger) (Collector, error)) {
|
||||
var helpDefaultState string
|
||||
if isDefaultEnabled {
|
||||
helpDefaultState = "enabled"
|
||||
|
@ -104,7 +104,7 @@ func collectorFlagAction(collector string) func(ctx *kingpin.ParseContext) error
|
|||
}
|
||||
|
||||
// NewNodeCollector creates a new NodeCollector.
|
||||
func NewNodeCollector(logger log.Logger, filters ...string) (*NodeCollector, error) {
|
||||
func NewNodeCollector(config NodeCollectorConfig, logger log.Logger, filters ...string) (*NodeCollector, error) {
|
||||
f := make(map[string]bool)
|
||||
for _, filter := range filters {
|
||||
enabled, exist := collectorState[filter]
|
||||
|
@ -126,7 +126,7 @@ func NewNodeCollector(logger log.Logger, filters ...string) (*NodeCollector, err
|
|||
if collector, ok := initiatedCollectors[key]; ok {
|
||||
collectors[key] = collector
|
||||
} else {
|
||||
collector, err := factories[key](log.With(logger, "collector", key))
|
||||
collector, err := factories[key](config, log.With(logger, "collector", key))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
||||
//go:build !noarp
|
||||
// +build !noarp
|
||||
|
||||
package collector
|
||||
|
||||
type NodeCollectorConfig struct {
|
||||
Arp ArpConfig
|
||||
}
|
||||
|
||||
type ArpConfig struct {
|
||||
DeviceInclude *string
|
||||
DeviceExclude *string
|
||||
}
|
|
@ -57,7 +57,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewConntrackCollector returns a new Collector exposing conntrack stats.
|
||||
func NewConntrackCollector(logger log.Logger) (Collector, error) {
|
||||
func NewConntrackCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &conntrackCollector{
|
||||
current: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "", "nf_conntrack_entries"),
|
||||
|
|
|
@ -61,7 +61,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewCPUCollector returns a new Collector exposing CPU stats.
|
||||
func NewCPUCollector(logger log.Logger) (Collector, error) {
|
||||
func NewCPUCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &statCollector{
|
||||
cpu: nodeCPUSecondsDesc,
|
||||
logger: logger,
|
||||
|
|
|
@ -86,7 +86,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewStatCollector returns a new Collector exposing CPU stats.
|
||||
func NewStatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &statCollector{
|
||||
cpu: nodeCPUSecondsDesc,
|
||||
logger: logger,
|
||||
|
|
|
@ -93,7 +93,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewStatCollector returns a new Collector exposing CPU stats.
|
||||
func NewStatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &statCollector{
|
||||
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
|
||||
temp: typedDesc{prometheus.NewDesc(
|
||||
|
|
|
@ -69,7 +69,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewCPUCollector returns a new Collector exposing kernel/system statistics.
|
||||
func NewCPUCollector(logger log.Logger) (Collector, error) {
|
||||
func NewCPUCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -222,7 +222,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewStatCollector returns a new Collector exposing CPU stats.
|
||||
func NewStatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &statCollector{
|
||||
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
|
||||
temp: typedDesc{prometheus.NewDesc(
|
||||
|
|
|
@ -52,7 +52,7 @@ func init() {
|
|||
registerCollector("cpu", defaultEnabled, NewCPUCollector)
|
||||
}
|
||||
|
||||
func NewCPUCollector(logger log.Logger) (Collector, error) {
|
||||
func NewCPUCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &cpuCollector{
|
||||
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
|
||||
logger: logger,
|
||||
|
|
|
@ -36,7 +36,7 @@ func init() {
|
|||
registerCollector("cpu", defaultEnabled, NewCpuCollector)
|
||||
}
|
||||
|
||||
func NewCpuCollector(logger log.Logger) (Collector, error) {
|
||||
func NewCpuCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &cpuCollector{
|
||||
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
|
||||
logger: logger,
|
||||
|
|
|
@ -40,7 +40,7 @@ func init() {
|
|||
registerCollector(cpuVulerabilitiesCollector, defaultDisabled, NewVulnerabilitySysfsCollector)
|
||||
}
|
||||
|
||||
func NewVulnerabilitySysfsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewVulnerabilitySysfsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &cpuVulnerabilitiesCollector{}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewCPUFreqCollector returns a new Collector exposing kernel/system statistics.
|
||||
func NewCPUFreqCollector(logger log.Logger) (Collector, error) {
|
||||
func NewCPUFreqCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := sysfs.NewFS(*sysPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
||||
|
|
|
@ -36,7 +36,7 @@ func init() {
|
|||
registerCollector("cpufreq", defaultEnabled, NewCpuFreqCollector)
|
||||
}
|
||||
|
||||
func NewCpuFreqCollector(logger log.Logger) (Collector, error) {
|
||||
func NewCpuFreqCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &cpuFreqCollector{
|
||||
logger: logger,
|
||||
}, nil
|
||||
|
|
|
@ -106,7 +106,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewDevstatCollector returns a new Collector exposing Device stats.
|
||||
func NewDevstatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewDevstatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &devstatCollector{
|
||||
bytesDesc: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"),
|
||||
|
|
|
@ -51,7 +51,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewDevstatCollector returns a new Collector exposing Device stats.
|
||||
func NewDevstatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewDevstatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &devstatCollector{
|
||||
devinfo: &C.struct_devinfo{},
|
||||
bytes: typedDesc{prometheus.NewDesc(
|
||||
|
|
|
@ -43,7 +43,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
|
||||
func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewDiskstatsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
var diskLabelNames = []string{"device"}
|
||||
|
||||
deviceFilter, err := newDiskstatsDeviceFilter(logger)
|
||||
|
|
|
@ -95,7 +95,7 @@ func init() {
|
|||
|
||||
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
|
||||
// Docs from https://www.kernel.org/doc/Documentation/iostats.txt
|
||||
func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewDiskstatsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
var diskLabelNames = []string{"device"}
|
||||
fs, err := blockdevice.NewFS(*procPath, *sysPath)
|
||||
if err != nil {
|
||||
|
|
|
@ -36,8 +36,8 @@ func (c testDiskStatsCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
prometheus.DescribeByCollect(c, ch)
|
||||
}
|
||||
|
||||
func NewTestDiskStatsCollector(logger log.Logger) (prometheus.Collector, error) {
|
||||
dsc, err := NewDiskstatsCollector(logger)
|
||||
func NewTestDiskStatsCollector(config NodeCollectorConfig, logger log.Logger) (prometheus.Collector, error) {
|
||||
dsc, err := NewDiskstatsCollector(config, logger)
|
||||
if err != nil {
|
||||
return testDiskStatsCollector{}, err
|
||||
}
|
||||
|
@ -314,12 +314,13 @@ node_disk_written_bytes_total{device="sr0"} 0
|
|||
node_disk_written_bytes_total{device="vda"} 1.0938236928e+11
|
||||
`
|
||||
|
||||
config := NodeCollectorConfig{}
|
||||
logger := log.NewLogfmtLogger(os.Stderr)
|
||||
collector, err := NewDiskstatsCollector(logger)
|
||||
collector, err := NewDiskstatsCollector(config, logger)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c, err := NewTestDiskStatsCollector(logger)
|
||||
c, err := NewTestDiskStatsCollector(config, logger)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
|
||||
func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewDiskstatsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
deviceFilter, err := newDiskstatsDeviceFilter(logger)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
|
||||
|
|
|
@ -60,7 +60,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
|
||||
func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewDiskstatsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
deviceFilter, err := newDiskstatsDeviceFilter(logger)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
|
||||
|
|
|
@ -38,7 +38,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewDMICollector returns a new Collector exposing DMI information.
|
||||
func NewDMICollector(logger log.Logger) (Collector, error) {
|
||||
func NewDMICollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := sysfs.NewFS(*sysPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
||||
|
|
|
@ -86,7 +86,7 @@ func init() {
|
|||
registerCollector("drbd", defaultDisabled, newDRBDCollector)
|
||||
}
|
||||
|
||||
func newDRBDCollector(logger log.Logger) (Collector, error) {
|
||||
func newDRBDCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &drbdCollector{
|
||||
numerical: map[string]drbdNumericalMetric{
|
||||
"ns": newDRBDNumericalMetric(
|
||||
|
|
|
@ -46,7 +46,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewDrmCollector returns a new Collector exposing /sys/class/drm/card?/device stats.
|
||||
func NewDrmCollector(logger log.Logger) (Collector, error) {
|
||||
func NewDrmCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := sysfs.NewFS(*sysPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
||||
|
|
|
@ -47,7 +47,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewEdacCollector returns a new Collector exposing edac stats.
|
||||
func NewEdacCollector(logger log.Logger) (Collector, error) {
|
||||
func NewEdacCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &edacCollector{
|
||||
ceCount: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, edacSubsystem, "correctable_errors_total"),
|
||||
|
|
|
@ -36,7 +36,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewEntropyCollector returns a new Collector exposing entropy stats.
|
||||
func NewEntropyCollector(logger log.Logger) (Collector, error) {
|
||||
func NewEntropyCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -85,7 +85,7 @@ type ethtoolCollector struct {
|
|||
// makeEthtoolCollector is the internal constructor for EthtoolCollector.
|
||||
// This allows NewEthtoolTestCollector to override its .ethtool interface
|
||||
// for testing.
|
||||
func makeEthtoolCollector(logger log.Logger) (*ethtoolCollector, error) {
|
||||
func makeEthtoolCollector(config NodeCollectorConfig, logger log.Logger) (*ethtoolCollector, error) {
|
||||
fs, err := sysfs.NewFS(*sysPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
||||
|
@ -213,8 +213,8 @@ func buildEthtoolFQName(metric string) string {
|
|||
}
|
||||
|
||||
// NewEthtoolCollector returns a new Collector exposing ethtool stats.
|
||||
func NewEthtoolCollector(logger log.Logger) (Collector, error) {
|
||||
return makeEthtoolCollector(logger)
|
||||
func NewEthtoolCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return makeEthtoolCollector(config, logger)
|
||||
}
|
||||
|
||||
// updatePortCapabilities generates metrics for autonegotiate, pause and asymmetricpause.
|
||||
|
|
|
@ -46,8 +46,8 @@ func (c testEthtoolCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
prometheus.DescribeByCollect(c, ch)
|
||||
}
|
||||
|
||||
func NewTestEthtoolCollector(logger log.Logger) (prometheus.Collector, error) {
|
||||
dsc, err := NewEthtoolTestCollector(logger)
|
||||
func NewTestEthtoolCollector(config NodeCollectorConfig, logger log.Logger) (prometheus.Collector, error) {
|
||||
dsc, err := NewEthtoolTestCollector(config, logger)
|
||||
if err != nil {
|
||||
return testEthtoolCollector{}, err
|
||||
}
|
||||
|
@ -252,8 +252,8 @@ func (e *EthtoolFixture) LinkInfo(intf string) (ethtool.EthtoolCmd, error) {
|
|||
return res, err
|
||||
}
|
||||
|
||||
func NewEthtoolTestCollector(logger log.Logger) (Collector, error) {
|
||||
collector, err := makeEthtoolCollector(logger)
|
||||
func NewEthtoolTestCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
collector, err := makeEthtoolCollector(config, logger)
|
||||
collector.ethtool = &EthtoolFixture{
|
||||
fixturePath: "fixtures/ethtool/",
|
||||
}
|
||||
|
@ -367,12 +367,13 @@ node_network_supported_speed_bytes{device="eth0",duplex="half",mode="10baseT"} 1
|
|||
`
|
||||
*sysPath = "fixtures/sys"
|
||||
|
||||
config := NodeCollectorConfig{}
|
||||
logger := log.NewLogfmtLogger(os.Stderr)
|
||||
collector, err := NewEthtoolTestCollector(logger)
|
||||
collector, err := NewEthtoolTestCollector(config, logger)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c, err := NewTestEthtoolCollector(logger)
|
||||
c, err := NewTestEthtoolCollector(config, logger)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewExecCollector returns a new Collector exposing system execution statistics.
|
||||
func NewExecCollector(logger log.Logger) (Collector, error) {
|
||||
func NewExecCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
// From sys/vm/vm_meter.c:
|
||||
// All are of type CTLTYPE_UINT.
|
||||
//
|
||||
|
|
|
@ -40,7 +40,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewFibreChannelCollector returns a new Collector exposing FibreChannel stats.
|
||||
func NewFibreChannelCollector(logger log.Logger) (Collector, error) {
|
||||
func NewFibreChannelCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
var i fibrechannelCollector
|
||||
var err error
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewFileFDStatCollector returns a new Collector exposing file-nr stats.
|
||||
func NewFileFDStatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewFileFDStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &fileFDStatCollector{logger}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewFilesystemCollector returns a new Collector exposing filesystems stats.
|
||||
func NewFilesystemCollector(logger log.Logger) (Collector, error) {
|
||||
func NewFilesystemCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
if *oldMountPointsExcluded != "" {
|
||||
if !mountPointsExcludeSet {
|
||||
level.Warn(logger).Log("msg", "--collector.filesystem.ignored-mount-points is DEPRECATED and will be removed in 2.0.0, use --collector.filesystem.mount-points-exclude")
|
||||
|
|
|
@ -57,7 +57,7 @@ type hwMonCollector struct {
|
|||
|
||||
// NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats
|
||||
// (similar to lm-sensors).
|
||||
func NewHwMonCollector(logger log.Logger) (Collector, error) {
|
||||
func NewHwMonCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
|
||||
return &hwMonCollector{
|
||||
logger: logger,
|
||||
|
|
|
@ -40,7 +40,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewInfiniBandCollector returns a new Collector exposing InfiniBand stats.
|
||||
func NewInfiniBandCollector(logger log.Logger) (Collector, error) {
|
||||
func NewInfiniBandCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
var i infinibandCollector
|
||||
var err error
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewInterruptsCollector returns a new Collector exposing interrupts stats.
|
||||
func NewInterruptsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewInterruptsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &interruptsCollector{
|
||||
desc: typedDesc{prometheus.NewDesc(
|
||||
namespace+"_interrupts_total",
|
||||
|
|
|
@ -73,11 +73,11 @@ func init() {
|
|||
|
||||
// NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the
|
||||
// "procfs" config parameter to override the default proc location (/proc).
|
||||
func NewIPVSCollector(logger log.Logger) (Collector, error) {
|
||||
return newIPVSCollector(logger)
|
||||
func NewIPVSCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return newIPVSCollector(config, logger)
|
||||
}
|
||||
|
||||
func newIPVSCollector(logger log.Logger) (*ipvsCollector, error) {
|
||||
func newIPVSCollector(config NodeCollectorConfig, logger log.Logger) (*ipvsCollector, error) {
|
||||
var (
|
||||
c ipvsCollector
|
||||
err error
|
||||
|
|
|
@ -111,7 +111,7 @@ func TestIPVSCollector(t *testing.T) {
|
|||
if _, err := kingpin.CommandLine.Parse(args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
collector, err := newIPVSCollector(log.NewNopLogger())
|
||||
collector, err := newIPVSCollector(NodeCollectorConfig{}, log.NewNopLogger())
|
||||
if err != nil {
|
||||
if test.err == nil {
|
||||
t.Fatal(err)
|
||||
|
@ -179,7 +179,7 @@ func TestIPVSCollectorResponse(t *testing.T) {
|
|||
if _, err := kingpin.CommandLine.Parse(args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
collector, err := NewIPVSCollector(log.NewNopLogger())
|
||||
collector, err := NewIPVSCollector(NodeCollectorConfig{}, log.NewNopLogger())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ func getCanonicalMetricName(filename string) string {
|
|||
}
|
||||
|
||||
// NewKsmdCollector returns a new Collector exposing kernel/system statistics.
|
||||
func NewKsmdCollector(logger log.Logger) (Collector, error) {
|
||||
func NewKsmdCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
subsystem := "ksmd"
|
||||
descs := make(map[string]*prometheus.Desc)
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ func init() {
|
|||
registerCollector("lnstat", defaultDisabled, NewLnstatCollector)
|
||||
}
|
||||
|
||||
func NewLnstatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewLnstatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &lnstatCollector{logger}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewLoadavgCollector returns a new Collector exposing load average stats.
|
||||
func NewLoadavgCollector(logger log.Logger) (Collector, error) {
|
||||
func NewLoadavgCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &loadavgCollector{
|
||||
metric: []typedDesc{
|
||||
{prometheus.NewDesc(namespace+"_load1", "1m load average.", nil, nil), prometheus.GaugeValue},
|
||||
|
|
|
@ -86,7 +86,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewLogindCollector returns a new Collector exposing logind statistics.
|
||||
func NewLogindCollector(logger log.Logger) (Collector, error) {
|
||||
func NewLogindCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &logindCollector{logger}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewMdadmCollector returns a new Collector exposing raid statistics.
|
||||
func NewMdadmCollector(logger log.Logger) (Collector, error) {
|
||||
func NewMdadmCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &mdadmCollector{logger}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewMeminfoCollector returns a new Collector exposing memory stats.
|
||||
func NewMeminfoCollector(logger log.Logger) (Collector, error) {
|
||||
func NewMeminfoCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &meminfoCollector{logger}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewMeminfoNumaCollector returns a new Collector exposing memory stats.
|
||||
func NewMeminfoNumaCollector(logger log.Logger) (Collector, error) {
|
||||
func NewMeminfoNumaCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &meminfoNumaCollector{
|
||||
metricDescs: map[string]*prometheus.Desc{},
|
||||
logger: logger,
|
||||
|
|
|
@ -41,7 +41,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewMemoryCollector returns a new Collector exposing memory stats.
|
||||
func NewMemoryCollector(logger log.Logger) (Collector, error) {
|
||||
func NewMemoryCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
tmp32, err := unix.SysctlUint32("vm.stats.vm.v_page_size")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %w", err)
|
||||
|
|
|
@ -111,7 +111,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewMountStatsCollector returns a new Collector exposing NFS statistics.
|
||||
func NewMountStatsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewMountStatsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -49,7 +49,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewNetClassCollector returns a new Collector exposing network class stats.
|
||||
func NewNetClassCollector(logger log.Logger) (Collector, error) {
|
||||
func NewNetClassCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := sysfs.NewFS(*sysPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
||||
|
|
|
@ -54,7 +54,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewNetDevCollector returns a new Collector exposing network device stats.
|
||||
func NewNetDevCollector(logger log.Logger) (Collector, error) {
|
||||
func NewNetDevCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
if *oldNetdevDeviceInclude != "" {
|
||||
if *netdevDeviceInclude == "" {
|
||||
level.Warn(logger).Log("msg", "--collector.netdev.device-whitelist is DEPRECATED and will be removed in 2.0.0, use --collector.netdev.device-include")
|
||||
|
|
|
@ -36,7 +36,7 @@ func init() {
|
|||
registerCollector("netisr", defaultEnabled, NewNetisrCollector)
|
||||
}
|
||||
|
||||
func NewNetisrCollector(logger log.Logger) (Collector, error) {
|
||||
func NewNetisrCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &netisrCollector{
|
||||
sysctls: []bsdSysctl{
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ func init() {
|
|||
|
||||
// NewNetStatCollector takes and returns
|
||||
// a new Collector exposing network stats.
|
||||
func NewNetStatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewNetStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
pattern := regexp.MustCompile(*netStatFields)
|
||||
return &netStatCollector{
|
||||
fieldPattern: pattern,
|
||||
|
|
|
@ -38,7 +38,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewNetworkRouteCollector returns a new Collector exposing systemd statistics.
|
||||
func NewNetworkRouteCollector(logger log.Logger) (Collector, error) {
|
||||
func NewNetworkRouteCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
const subsystem = "network"
|
||||
|
||||
routeInfoDesc := prometheus.NewDesc(
|
||||
|
|
|
@ -48,7 +48,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewNfsCollector returns a new Collector exposing NFS statistics.
|
||||
func NewNfsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewNfsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := nfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -44,7 +44,7 @@ const (
|
|||
)
|
||||
|
||||
// NewNFSdCollector returns a new Collector exposing /proc/net/rpc/nfsd statistics.
|
||||
func NewNFSdCollector(logger log.Logger) (Collector, error) {
|
||||
func NewNFSdCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := nfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -62,7 +62,7 @@ func init() {
|
|||
// Default definition of "local" is:
|
||||
// - collector.ntp.server address is a loopback address (or collector.ntp.server-is-mine flag is turned on)
|
||||
// - the server is reachable with outgoin IP_TTL = 1
|
||||
func NewNtpCollector(logger log.Logger) (Collector, error) {
|
||||
func NewNtpCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
ipaddr := net.ParseIP(*ntpServer)
|
||||
if !*ntpServerIsLocal && (ipaddr == nil || !ipaddr.IsLoopback()) {
|
||||
return nil, fmt.Errorf("only IP address of local NTP server is valid for --collector.ntp.server")
|
||||
|
|
|
@ -37,7 +37,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewNVMeCollector returns a new Collector exposing NVMe stats.
|
||||
func NewNVMeCollector(logger log.Logger) (Collector, error) {
|
||||
func NewNVMeCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := sysfs.NewFS(*sysPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
||||
|
|
|
@ -81,7 +81,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewOSCollector returns a new Collector exposing os-release information.
|
||||
func NewOSCollector(logger log.Logger) (Collector, error) {
|
||||
func NewOSCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &osReleaseCollector{
|
||||
logger: logger,
|
||||
infoDesc: prometheus.NewDesc(
|
||||
|
|
|
@ -87,7 +87,7 @@ func TestUpdateStruct(t *testing.T) {
|
|||
}
|
||||
wantedVersion := 20.04
|
||||
|
||||
collector, err := NewOSCollector(log.NewNopLogger())
|
||||
collector, err := NewOSCollector(NodeCollectorConfig{}, log.NewNopLogger())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -301,7 +301,7 @@ func newPerfTracepointCollector(
|
|||
|
||||
// NewPerfCollector returns a new perf based collector, it creates a profiler
|
||||
// per CPU.
|
||||
func NewPerfCollector(logger log.Logger) (Collector, error) {
|
||||
func NewPerfCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
collector := &perfCollector{
|
||||
perfHwProfilers: map[int]*perf.HardwareProfiler{},
|
||||
perfSwProfilers: map[int]*perf.SoftwareProfiler{},
|
||||
|
|
|
@ -45,7 +45,7 @@ func canTestPerf(t *testing.T) {
|
|||
|
||||
func TestPerfCollector(t *testing.T) {
|
||||
canTestPerf(t)
|
||||
collector, err := NewPerfCollector(log.NewNopLogger())
|
||||
collector, err := NewPerfCollector(NodeCollectorConfig{}, log.NewNopLogger())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ func TestPerfCollectorStride(t *testing.T) {
|
|||
}
|
||||
}
|
||||
perfCPUsFlag = &test.flag
|
||||
collector, err := NewPerfCollector(log.NewNopLogger())
|
||||
collector, err := NewPerfCollector(NodeCollectorConfig{}, log.NewNopLogger())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ func init() {
|
|||
registerCollector("powersupplyclass", defaultEnabled, NewPowerSupplyClassCollector)
|
||||
}
|
||||
|
||||
func NewPowerSupplyClassCollector(logger log.Logger) (Collector, error) {
|
||||
func NewPowerSupplyClassCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
pattern := regexp.MustCompile(*powerSupplyClassIgnoredPowerSupplies)
|
||||
return &powerSupplyClassCollector{
|
||||
subsystem: "power_supply",
|
||||
|
|
|
@ -49,7 +49,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewPressureStatsCollector returns a Collector exposing pressure stall information
|
||||
func NewPressureStatsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewPressureStatsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -47,7 +47,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewProcessStatCollector returns a new Collector exposing process data read from the proc filesystem.
|
||||
func NewProcessStatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewProcessStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -51,7 +51,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewQdiscStatCollector returns a new Collector exposing queuing discipline statistics.
|
||||
func NewQdiscStatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewQdiscStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
if *collectorQdiskDeviceExclude != "" && *collectorQdiskDeviceInclude != "" {
|
||||
return nil, fmt.Errorf("collector.qdisk.device-include and collector.qdisk.device-exclude are mutaly exclusive")
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ var (
|
|||
)
|
||||
|
||||
// NewRaplCollector returns a new Collector exposing RAPL metrics.
|
||||
func NewRaplCollector(logger log.Logger) (Collector, error) {
|
||||
func NewRaplCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := sysfs.NewFS(*sysPath)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -39,7 +39,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewRunitCollector returns a new Collector exposing runit statistics.
|
||||
func NewRunitCollector(logger log.Logger) (Collector, error) {
|
||||
func NewRunitCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
var (
|
||||
subsystem = "service"
|
||||
constLabels = prometheus.Labels{"supervisor": "runit"}
|
||||
|
|
|
@ -53,7 +53,7 @@ var (
|
|||
)
|
||||
|
||||
// NewSchedstatCollector returns a new Collector exposing task scheduler statistics
|
||||
func NewSchedstatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewSchedstatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -34,7 +34,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewSelinuxCollector returns a new Collector exposing SELinux statistics.
|
||||
func NewSelinuxCollector(logger log.Logger) (Collector, error) {
|
||||
func NewSelinuxCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
const subsystem = "selinux"
|
||||
|
||||
return &selinuxCollector{
|
||||
|
|
|
@ -35,7 +35,7 @@ func init() {
|
|||
registerCollector("slabinfo", defaultDisabled, NewSlabinfoCollector)
|
||||
}
|
||||
|
||||
func NewSlabinfoCollector(logger log.Logger) (Collector, error) {
|
||||
func NewSlabinfoCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -43,7 +43,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewSockStatCollector returns a new Collector exposing socket stats.
|
||||
func NewSockStatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewSockStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &sockStatCollector{logger}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewSoftirqsCollector returns a new Collector exposing softirq stats.
|
||||
func NewSoftirqsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewSoftirqsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
desc := typedDesc{prometheus.NewDesc(
|
||||
namespace+"_softirqs_functions_total",
|
||||
"Softirq counts per CPU.",
|
||||
|
|
|
@ -46,7 +46,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewSoftnetCollector returns a new Collector exposing softnet metrics.
|
||||
func NewSoftnetCollector(logger log.Logger) (Collector, error) {
|
||||
func NewSoftnetCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -44,7 +44,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewStatCollector returns a new Collector exposing kernel/system statistics.
|
||||
func NewStatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -49,7 +49,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewSupervisordCollector returns a new Collector exposing supervisord statistics.
|
||||
func NewSupervisordCollector(logger log.Logger) (Collector, error) {
|
||||
func NewSupervisordCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
var (
|
||||
subsystem = "supervisord"
|
||||
labelNames = []string{"name", "group"}
|
||||
|
|
|
@ -41,7 +41,7 @@ func init() {
|
|||
registerCollector("sysctl", defaultDisabled, NewSysctlCollector)
|
||||
}
|
||||
|
||||
func NewSysctlCollector(logger log.Logger) (Collector, error) {
|
||||
func NewSysctlCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
||||
|
|
|
@ -88,7 +88,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewSystemdCollector returns a new Collector exposing systemd statistics.
|
||||
func NewSystemdCollector(logger log.Logger) (Collector, error) {
|
||||
func NewSystemdCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
const subsystem = "systemd"
|
||||
|
||||
unitDesc := prometheus.NewDesc(
|
||||
|
|
|
@ -100,7 +100,7 @@ func TestSystemdIgnoreFilter(t *testing.T) {
|
|||
}
|
||||
func TestSystemdIgnoreFilterDefaultKeepsAll(t *testing.T) {
|
||||
logger := log.NewNopLogger()
|
||||
c, err := NewSystemdCollector(logger)
|
||||
c, err := NewSystemdCollector(NodeCollectorConfig{}, logger)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func init() {
|
|||
|
||||
// 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(logger log.Logger) (Collector, error) {
|
||||
func NewTapestatsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
var tapeLabelNames = []string{"device"}
|
||||
|
||||
fs, err := sysfs.NewFS(*sysPath)
|
||||
|
|
|
@ -68,7 +68,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewTCPStatCollector returns a new Collector exposing network stats.
|
||||
func NewTCPStatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewTCPStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &tcpStatCollector{
|
||||
desc: typedDesc{prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "tcp", "connection_states"),
|
||||
|
|
|
@ -55,7 +55,7 @@ func init() {
|
|||
|
||||
// NewTextFileCollector returns a new Collector exposing metrics read from files
|
||||
// in the given textfile directory.
|
||||
func NewTextFileCollector(logger log.Logger) (Collector, error) {
|
||||
func NewTextFileCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
c := &textFileCollector{
|
||||
path: *textFileDirectory,
|
||||
logger: logger,
|
||||
|
|
|
@ -67,7 +67,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewThermCollector returns a new Collector exposing current CPU power levels.
|
||||
func NewThermCollector(logger log.Logger) (Collector, error) {
|
||||
func NewThermCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &thermCollector{
|
||||
cpuSchedulerLimit: typedDesc{
|
||||
desc: prometheus.NewDesc(
|
||||
|
|
|
@ -43,7 +43,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewThermalZoneCollector returns a new Collector exposing kernel/system statistics.
|
||||
func NewThermalZoneCollector(logger log.Logger) (Collector, error) {
|
||||
func NewThermalZoneCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := sysfs.NewFS(*sysPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
||||
|
|
|
@ -38,7 +38,7 @@ func init() {
|
|||
|
||||
// NewTimeCollector returns a new Collector exposing the current system time in
|
||||
// seconds since epoch.
|
||||
func NewTimeCollector(logger log.Logger) (Collector, error) {
|
||||
func NewTimeCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
const subsystem = "time"
|
||||
return &timeCollector{
|
||||
now: typedDesc{prometheus.NewDesc(
|
||||
|
|
|
@ -66,7 +66,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewTimexCollector returns a new Collector exposing adjtime(3) stats.
|
||||
func NewTimexCollector(logger log.Logger) (Collector, error) {
|
||||
func NewTimexCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
const subsystem = "timex"
|
||||
|
||||
return &timexCollector{
|
||||
|
|
|
@ -40,7 +40,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewUDPqueuesCollector returns a new Collector exposing network udp queued bytes.
|
||||
func NewUDPqueuesCollector(logger log.Logger) (Collector, error) {
|
||||
func NewUDPqueuesCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -53,7 +53,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewUnameCollector returns new unameCollector.
|
||||
func newUnameCollector(logger log.Logger) (Collector, error) {
|
||||
func newUnameCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &unameCollector{logger}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewvmStatCollector returns a new Collector exposing vmstat stats.
|
||||
func NewvmStatCollector(logger log.Logger) (Collector, error) {
|
||||
func NewvmStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
pattern := regexp.MustCompile(*vmStatFields)
|
||||
return &vmStatCollector{
|
||||
fieldPattern: pattern,
|
||||
|
|
|
@ -67,7 +67,7 @@ type wifiStater interface {
|
|||
}
|
||||
|
||||
// NewWifiCollector returns a new Collector exposing Wifi statistics.
|
||||
func NewWifiCollector(logger log.Logger) (Collector, error) {
|
||||
func NewWifiCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
const (
|
||||
subsystem = "wifi"
|
||||
)
|
||||
|
|
|
@ -35,7 +35,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewXFSCollector returns a new Collector exposing XFS statistics.
|
||||
func NewXFSCollector(logger log.Logger) (Collector, error) {
|
||||
func NewXFSCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := xfs.NewFS(*procPath, *sysPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
||||
|
|
|
@ -43,7 +43,7 @@ type zfsCollector struct {
|
|||
}
|
||||
|
||||
// NewZFSCollector returns a new Collector exposing ZFS statistics.
|
||||
func NewZFSCollector(logger log.Logger) (Collector, error) {
|
||||
func NewZFSCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &zfsCollector{
|
||||
linuxProcpathBase: "spl/kstat/zfs",
|
||||
linuxZpoolIoPath: "/*/io",
|
||||
|
|
|
@ -36,7 +36,7 @@ func init() {
|
|||
registerCollector("zfs", defaultEnabled, NewZfsCollector)
|
||||
}
|
||||
|
||||
func NewZfsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewZfsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &zfsCollector{
|
||||
sysctls: []bsdSysctl{
|
||||
{
|
||||
|
|
|
@ -65,7 +65,7 @@ func init() {
|
|||
registerCollector("zfs", defaultEnabled, NewZfsCollector)
|
||||
}
|
||||
|
||||
func NewZfsCollector(logger log.Logger) (Collector, error) {
|
||||
func NewZfsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
return &zfsCollector{
|
||||
abdstatsLinearCount: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "abdstats_linear_count_total"),
|
||||
|
|
|
@ -37,7 +37,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewZoneinfoCollector returns a new Collector exposing zone stats.
|
||||
func NewZoneinfoCollector(logger log.Logger) (Collector, error) {
|
||||
func NewZoneinfoCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %w", err)
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// 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 kingpinconfig
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus/node_exporter/collector"
|
||||
)
|
||||
|
||||
func AddFlags(a *kingpin.Application) collector.NodeCollectorConfig {
|
||||
config := collector.NodeCollectorConfig{}
|
||||
|
||||
config.Arp.DeviceInclude = a.Flag("collector.arp.device-include", "Regexp of arp devices to include (mutually exclusive to device-exclude).").String()
|
||||
config.Arp.DeviceExclude = a.Flag("collector.arp.device-exclude", "Regexp of arp devices to exclude (mutually exclusive to device-include).").String()
|
||||
|
||||
return config
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue