Merge pull request #26 from grafana/update_configs

Merging config changes to the working branch
This commit is contained in:
mattdurham 2023-09-28 07:06:03 -07:00 committed by GitHub
commit 4a5fa78e97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 182 additions and 180 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) {

View file

@ -13,6 +13,8 @@
package collector
import "time"
type NodeCollectorConfig struct {
Arp ArpConfig
Bcache BcacheConfig
@ -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
}

View file

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

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

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

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

View file

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

View file

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

View file

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

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

View file

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

View file

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

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

View file

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

View file

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

View file

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

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.