Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging config changes to the working branch #26

Merged
merged 9 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions collector/arp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions collector/bcache_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
163 changes: 163 additions & 0 deletions collector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package collector

import "time"

type NodeCollectorConfig struct {
Arp ArpConfig
Bcache BcacheConfig
Expand Down Expand Up @@ -41,3 +43,164 @@ type NodeCollectorConfig struct {
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
LabelsSet bool
}
7 changes: 0 additions & 7 deletions collector/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 7 additions & 5 deletions collector/cpu_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -215,6 +215,7 @@ type statCollector struct {
cpu typedDesc
temp typedDesc
logger log.Logger
p PathConfig
}

func init() {
Expand All @@ -231,6 +232,7 @@ func NewStatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector
[]string{"cpu"}, nil,
), prometheus.GaugeValue},
logger: logger,
p: config.Path,
}, nil
}

Expand All @@ -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
}
Expand Down
7 changes: 0 additions & 7 deletions collector/diskstats_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions collector/ethtool_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions collector/filesystem_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
16 changes: 2 additions & 14 deletions collector/filesystem_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -172,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
}
Expand Down
2 changes: 1 addition & 1 deletion collector/filesystem_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion collector/filesystem_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion collector/filesystem_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions collector/hwmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions collector/ipvs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ func init() {
registerCollector("ipvs", defaultEnabled, NewIPVSCollector)
}

type IPVSConfig struct {
Labels *string
LabelsSet bool
}

// 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) {
Expand Down
Loading