Update logging
Some checks are pending
golangci-lint / lint (push) Waiting to run

Switch from promlog/go-kit to promslog/slog for logging.
* Update Go build to 1.23.

Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
Ben Kochie 2024-08-29 10:58:11 +02:00
parent b9d0932179
commit 91365fd7ef
No known key found for this signature in database
GPG key ID: C646B23C9E3245F1
145 changed files with 653 additions and 701 deletions

View file

@ -7,7 +7,7 @@ executors:
# should also be updated.
golang:
docker:
- image: cimg/go:1.22
- image: cimg/go:1.23
arm:
machine:
image: ubuntu-2204:current

View file

@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here, .circle/config.yml and
# .promu.yml should also be updated.
version: 1.22
version: 1.23
cgo: true
repository:
path: github.com/prometheus/node_exporter

View file

@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here, .circle/config.yml and
# .promu-cgo.yml should also be updated.
version: 1.22
version: 1.23
repository:
path: github.com/prometheus/node_exporter
build:

View file

@ -19,10 +19,10 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"net"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/jsimonetti/rtnetlink"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
@ -39,7 +39,7 @@ type arpCollector struct {
fs procfs.FS
deviceFilter deviceFilter
entries *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -47,7 +47,7 @@ func init() {
}
// NewARPCollector returns a new Collector exposing ARP stats.
func NewARPCollector(logger log.Logger) (Collector, error) {
func NewARPCollector(logger *slog.Logger) (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)

View file

@ -18,9 +18,9 @@ package collector
import (
"fmt"
"log/slog"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/bcache"
)
@ -36,12 +36,12 @@ func init() {
// A bcacheCollector is a Collector which gathers metrics from Linux bcache.
type bcacheCollector struct {
fs bcache.FS
logger log.Logger
logger *slog.Logger
}
// NewBcacheCollector returns a newly allocated bcacheCollector.
// It exposes a number of Linux bcache statistics.
func NewBcacheCollector(logger log.Logger) (Collector, error) {
func NewBcacheCollector(logger *slog.Logger) (Collector, error) {
fs, err := bcache.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)

View file

@ -19,18 +19,17 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"path/filepath"
"strings"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
type bondingCollector struct {
slaves, active typedDesc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -39,7 +38,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(logger *slog.Logger) (Collector, error) {
return &bondingCollector{
slaves: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, "bonding", "slaves"),
@ -61,7 +60,7 @@ func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error {
bondingStats, err := readBondingStats(statusfile)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "Not collecting bonding, file does not exist", "file", statusfile)
c.logger.Debug("Not collecting bonding, file does not exist", "file", statusfile)
return ErrNoData
}
return err

View file

@ -18,13 +18,13 @@
package collector
import (
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
"log/slog"
)
type bootTimeCollector struct {
logger log.Logger
logger *slog.Logger
}
func init() {
@ -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(logger *slog.Logger) (Collector, error) {
return &bootTimeCollector{
logger: logger,
}, nil

View file

@ -17,21 +17,21 @@
package collector
import (
"github.com/go-kit/log"
"github.com/illumos/go-kstat"
"github.com/prometheus/client_golang/prometheus"
"log/slog"
)
type bootTimeCollector struct {
boottime typedDesc
logger log.Logger
logger *slog.Logger
}
func init() {
registerCollector("boottime", defaultEnabled, newBootTimeCollector)
}
func newBootTimeCollector(logger log.Logger) (Collector, error) {
func newBootTimeCollector(logger *slog.Logger) (Collector, error) {
return &bootTimeCollector{
boottime: typedDesc{
prometheus.NewDesc(

View file

@ -18,13 +18,12 @@ package collector
import (
"fmt"
"log/slog"
"path"
"strings"
"syscall"
dennwc "github.com/dennwc/btrfs"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/btrfs"
)
@ -32,7 +31,7 @@ import (
// A btrfsCollector is a Collector which gathers metrics from Btrfs filesystems.
type btrfsCollector struct {
fs btrfs.FS
logger log.Logger
logger *slog.Logger
}
func init() {
@ -40,7 +39,7 @@ func init() {
}
// NewBtrfsCollector returns a new Collector exposing Btrfs statistics.
func NewBtrfsCollector(logger log.Logger) (Collector, error) {
func NewBtrfsCollector(logger *slog.Logger) (Collector, error) {
fs, err := btrfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)
@ -62,8 +61,8 @@ func (c *btrfsCollector) Update(ch chan<- prometheus.Metric) error {
ioctlStatsMap, err := c.getIoctlStats()
if err != nil {
level.Debug(c.logger).Log(
"msg", "Error querying btrfs device stats with ioctl",
c.logger.Debug(
"Error querying btrfs device stats with ioctl",
"err", err)
ioctlStatsMap = make(map[string]*btrfsIoctlFsStats)
}
@ -129,8 +128,8 @@ func (c *btrfsCollector) getIoctlStats() (map[string]*btrfsIoctlFsStats, error)
if err != nil {
// Failed to open this mount point, maybe we didn't have permission
// maybe we'll find another mount point for this FS later.
level.Debug(c.logger).Log(
"msg", "Error inspecting btrfs mountpoint",
c.logger.Debug(
"Error inspecting btrfs mountpoint",
"mountPoint", mountPath,
"err", err)
continue
@ -141,8 +140,8 @@ func (c *btrfsCollector) getIoctlStats() (map[string]*btrfsIoctlFsStats, error)
if err != nil {
// Failed to get the FS info for some reason,
// perhaps it'll work with a different mount point
level.Debug(c.logger).Log(
"msg", "Error querying btrfs filesystem",
c.logger.Debug(
"Error querying btrfs filesystem",
"mountPoint", mountPath,
"err", err)
continue
@ -156,8 +155,8 @@ func (c *btrfsCollector) getIoctlStats() (map[string]*btrfsIoctlFsStats, error)
deviceStats, err := c.getIoctlDeviceStats(fs, &fsInfo)
if err != nil {
level.Debug(c.logger).Log(
"msg", "Error querying btrfs device stats",
c.logger.Debug(
"Error querying btrfs device stats",
"mountPoint", mountPath,
"err", err)
continue

View file

@ -18,10 +18,9 @@ package collector
import (
"fmt"
"log/slog"
"strconv"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)
@ -33,7 +32,7 @@ const (
type buddyinfoCollector struct {
fs procfs.FS
desc *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -41,7 +40,7 @@ func init() {
}
// NewBuddyinfoCollector returns a new Collector exposing buddyinfo stats.
func NewBuddyinfoCollector(logger log.Logger) (Collector, error) {
func NewBuddyinfoCollector(logger *slog.Logger) (Collector, error) {
desc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, buddyInfoSubsystem, "blocks"),
"Count of free blocks according to size.",
@ -62,7 +61,7 @@ func (c *buddyinfoCollector) Update(ch chan<- prometheus.Metric) error {
return fmt.Errorf("couldn't get buddyinfo: %w", err)
}
level.Debug(c.logger).Log("msg", "Set node_buddy", "buddyInfo", buddyInfo)
c.logger.Debug("Set node_buddy", "buddyInfo", buddyInfo)
for _, entry := range buddyInfo {
for size, value := range entry.Sizes {
ch <- prometheus.MustNewConstMetric(

View file

@ -18,8 +18,8 @@ package collector
import (
"fmt"
"log/slog"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)
@ -30,7 +30,7 @@ type cgroupSummaryCollector struct {
fs procfs.FS
cgroups *prometheus.Desc
enabled *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -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(logger *slog.Logger) (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)

View file

@ -17,12 +17,11 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"sync"
"time"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
@ -50,14 +49,14 @@ const (
)
var (
factories = make(map[string]func(logger log.Logger) (Collector, error))
factories = make(map[string]func(logger *slog.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(logger *slog.Logger) (Collector, error)) {
var helpDefaultState string
if isDefaultEnabled {
helpDefaultState = "enabled"
@ -78,7 +77,7 @@ func registerCollector(collector string, isDefaultEnabled bool, factory func(log
// NodeCollector implements the prometheus.Collector interface.
type NodeCollector struct {
Collectors map[string]Collector
logger log.Logger
logger *slog.Logger
}
// DisableDefaultCollectors sets the collector state to false for all collectors which
@ -104,7 +103,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(logger *slog.Logger, filters ...string) (*NodeCollector, error) {
f := make(map[string]bool)
for _, filter := range filters {
enabled, exist := collectorState[filter]
@ -126,7 +125,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](logger.With("collector", key))
if err != nil {
return nil, err
}
@ -156,7 +155,7 @@ func (n NodeCollector) Collect(ch chan<- prometheus.Metric) {
wg.Wait()
}
func execute(name string, c Collector, ch chan<- prometheus.Metric, logger log.Logger) {
func execute(name string, c Collector, ch chan<- prometheus.Metric, logger *slog.Logger) {
begin := time.Now()
err := c.Update(ch)
duration := time.Since(begin)
@ -164,13 +163,13 @@ func execute(name string, c Collector, ch chan<- prometheus.Metric, logger log.L
if err != nil {
if IsNoDataError(err) {
level.Debug(logger).Log("msg", "collector returned no data", "name", name, "duration_seconds", duration.Seconds(), "err", err)
logger.Debug("collector returned no data", "name", name, "duration_seconds", duration.Seconds(), "err", err)
} else {
level.Error(logger).Log("msg", "collector failed", "name", name, "duration_seconds", duration.Seconds(), "err", err)
logger.Error("collector failed", "name", name, "duration_seconds", duration.Seconds(), "err", err)
}
success = 0
} else {
level.Debug(logger).Log("msg", "collector succeeded", "name", name, "duration_seconds", duration.Seconds())
logger.Debug("collector succeeded", "name", name, "duration_seconds", duration.Seconds())
success = 1
}
ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), name)

View file

@ -19,10 +19,9 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)
@ -38,7 +37,7 @@ type conntrackCollector struct {
drop *prometheus.Desc
earlyDrop *prometheus.Desc
searchRestart *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
type conntrackStatistics struct {
@ -57,7 +56,7 @@ func init() {
}
// NewConntrackCollector returns a new Collector exposing conntrack stats.
func NewConntrackCollector(logger log.Logger) (Collector, error) {
func NewConntrackCollector(logger *slog.Logger) (Collector, error) {
return &conntrackCollector{
current: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_entries"),
@ -154,7 +153,7 @@ func (c *conntrackCollector) Update(ch chan<- prometheus.Metric) error {
func (c *conntrackCollector) handleErr(err error) error {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "conntrack probably not loaded")
c.logger.Debug("conntrack probably not loaded")
return ErrNoData
}
return fmt.Errorf("failed to retrieve conntrack stats: %w", err)

View file

@ -23,10 +23,10 @@ import (
"bytes"
"encoding/binary"
"fmt"
"log/slog"
"strconv"
"unsafe"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -53,7 +53,7 @@ const ClocksPerSec = float64(C.CLK_TCK)
type statCollector struct {
cpu *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -61,7 +61,7 @@ func init() {
}
// NewCPUCollector returns a new Collector exposing CPU stats.
func NewCPUCollector(logger log.Logger) (Collector, error) {
func NewCPUCollector(logger *slog.Logger) (Collector, error) {
return &statCollector{
cpu: nodeCPUSecondsDesc,
logger: logger,

View file

@ -18,10 +18,10 @@ package collector
import (
"errors"
"log/slog"
"strconv"
"unsafe"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -78,7 +78,7 @@ const maxCPUTimesLen = C.MAXCPU * C.CPUSTATES
type statCollector struct {
cpu *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -86,7 +86,7 @@ func init() {
}
// NewStatCollector returns a new Collector exposing CPU stats.
func NewStatCollector(logger log.Logger) (Collector, error) {
func NewStatCollector(logger *slog.Logger) (Collector, error) {
return &statCollector{
cpu: nodeCPUSecondsDesc,
logger: logger,

View file

@ -17,6 +17,7 @@
package collector
import (
"log/slog"
"runtime"
"testing"
)

View file

@ -18,12 +18,11 @@ package collector
import (
"fmt"
"log/slog"
"math"
"strconv"
"unsafe"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)
@ -85,7 +84,7 @@ func getCPUTimes() ([]cputime, error) {
type statCollector struct {
cpu typedDesc
temp typedDesc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -93,7 +92,7 @@ func init() {
}
// NewStatCollector returns a new Collector exposing CPU stats.
func NewStatCollector(logger log.Logger) (Collector, error) {
func NewStatCollector(logger *slog.Logger) (Collector, error) {
return &statCollector{
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
temp: typedDesc{prometheus.NewDesc(
@ -134,11 +133,11 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
if err == unix.ENOENT {
// No temperature information for this CPU
level.Debug(c.logger).Log("msg", "no temperature information for CPU", "cpu", cpu)
c.logger.Debug("no temperature information for CPU", "cpu", cpu)
} else {
// Unexpected error
ch <- c.temp.mustNewConstMetric(math.NaN(), lcpu)
level.Error(c.logger).Log("msg", "failed to query CPU temperature for CPU", "cpu", cpu, "err", err)
c.logger.Error("failed to query CPU temperature for CPU", "cpu", cpu, "err", err)
}
continue
}

View file

@ -18,6 +18,7 @@ package collector
import (
"fmt"
"log/slog"
"os"
"path/filepath"
"regexp"
@ -26,8 +27,6 @@ import (
"sync"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
"github.com/prometheus/procfs/sysfs"
@ -45,7 +44,7 @@ type cpuCollector struct {
cpuCoreThrottle *prometheus.Desc
cpuPackageThrottle *prometheus.Desc
cpuIsolated *prometheus.Desc
logger log.Logger
logger *slog.Logger
cpuStats map[int64]procfs.CPUStat
cpuStatsMutex sync.Mutex
isolatedCpus []uint16
@ -70,7 +69,7 @@ func init() {
}
// NewCPUCollector returns a new Collector exposing kernel/system statistics.
func NewCPUCollector(logger log.Logger) (Collector, error) {
func NewCPUCollector(logger *slog.Logger) (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)
@ -86,7 +85,7 @@ func NewCPUCollector(logger log.Logger) (Collector, error) {
if !os.IsNotExist(err) {
return nil, fmt.Errorf("Unable to get isolated cpus: %w", err)
}
level.Debug(logger).Log("msg", "Could not open isolated file", "error", err)
logger.Debug("Could not open isolated file", "error", err)
}
c := &cpuCollector{
@ -146,7 +145,7 @@ func NewCPUCollector(logger log.Logger) (Collector, error) {
func (c *cpuCollector) compileIncludeFlags(flagsIncludeFlag, bugsIncludeFlag *string) error {
if (*flagsIncludeFlag != "" || *bugsIncludeFlag != "") && !*enableCPUInfo {
*enableCPUInfo = true
level.Info(c.logger).Log("msg", "--collector.cpu.info has been set to `true` because you set the following flags, like --collector.cpu.info.flags-include and --collector.cpu.info.bugs-include")
c.logger.Info("--collector.cpu.info has been set to `true` because you set the following flags, like --collector.cpu.info.flags-include and --collector.cpu.info.bugs-include")
}
var err error
@ -205,7 +204,7 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error {
cpuFreqEnabled, ok := collectorState["cpufreq"]
if !ok || cpuFreqEnabled == nil {
level.Debug(c.logger).Log("msg", "cpufreq key missing or nil value in collectorState map")
c.logger.Debug("cpufreq key missing or nil value in collectorState map")
} else if !*cpuFreqEnabled {
for _, cpu := range info {
ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz,
@ -269,12 +268,12 @@ func (c *cpuCollector) updateThermalThrottle(ch chan<- prometheus.Metric) error
// topology/physical_package_id
if physicalPackageID, err = readUintFromFile(filepath.Join(cpu, "topology", "physical_package_id")); err != nil {
level.Debug(c.logger).Log("msg", "CPU is missing physical_package_id", "cpu", cpu)
c.logger.Debug("CPU is missing physical_package_id", "cpu", cpu)
continue
}
// topology/core_id
if coreID, err = readUintFromFile(filepath.Join(cpu, "topology", "core_id")); err != nil {
level.Debug(c.logger).Log("msg", "CPU is missing core_id", "cpu", cpu)
c.logger.Debug("CPU is missing core_id", "cpu", cpu)
continue
}
@ -292,7 +291,7 @@ func (c *cpuCollector) updateThermalThrottle(ch chan<- prometheus.Metric) error
if coreThrottleCount, err := readUintFromFile(filepath.Join(cpu, "thermal_throttle", "core_throttle_count")); err == nil {
packageCoreThrottles[physicalPackageID][coreID] = coreThrottleCount
} else {
level.Debug(c.logger).Log("msg", "CPU is missing core_throttle_count", "cpu", cpu)
c.logger.Debug("CPU is missing core_throttle_count", "cpu", cpu)
}
}
@ -302,7 +301,7 @@ func (c *cpuCollector) updateThermalThrottle(ch chan<- prometheus.Metric) error
if packageThrottleCount, err := readUintFromFile(filepath.Join(cpu, "thermal_throttle", "package_throttle_count")); err == nil {
packageThrottles[physicalPackageID] = packageThrottleCount
} else {
level.Debug(c.logger).Log("msg", "CPU is missing package_throttle_count", "cpu", cpu)
c.logger.Debug("CPU is missing package_throttle_count", "cpu", cpu)
}
}
}
@ -380,68 +379,68 @@ func (c *cpuCollector) updateCPUStats(newStats map[int64]procfs.CPUStat) {
// If idle jumps backwards by more than X seconds, assume we had a hotplug event and reset the stats for this CPU.
if (cpuStats.Idle - n.Idle) >= jumpBackSeconds {
level.Debug(c.logger).Log("msg", jumpBackDebugMessage, "cpu", i, "old_value", cpuStats.Idle, "new_value", n.Idle)
c.logger.Debug(jumpBackDebugMessage, "cpu", i, "old_value", cpuStats.Idle, "new_value", n.Idle)
cpuStats = procfs.CPUStat{}
}
if n.Idle >= cpuStats.Idle {
cpuStats.Idle = n.Idle
} else {
level.Debug(c.logger).Log("msg", "CPU Idle counter jumped backwards", "cpu", i, "old_value", cpuStats.Idle, "new_value", n.Idle)
c.logger.Debug("CPU Idle counter jumped backwards", "cpu", i, "old_value", cpuStats.Idle, "new_value", n.Idle)
}
if n.User >= cpuStats.User {
cpuStats.User = n.User
} else {
level.Debug(c.logger).Log("msg", "CPU User counter jumped backwards", "cpu", i, "old_value", cpuStats.User, "new_value", n.User)
c.logger.Debug("CPU User counter jumped backwards", "cpu", i, "old_value", cpuStats.User, "new_value", n.User)
}
if n.Nice >= cpuStats.Nice {
cpuStats.Nice = n.Nice
} else {
level.Debug(c.logger).Log("msg", "CPU Nice counter jumped backwards", "cpu", i, "old_value", cpuStats.Nice, "new_value", n.Nice)
c.logger.Debug("CPU Nice counter jumped backwards", "cpu", i, "old_value", cpuStats.Nice, "new_value", n.Nice)
}
if n.System >= cpuStats.System {
cpuStats.System = n.System
} else {
level.Debug(c.logger).Log("msg", "CPU System counter jumped backwards", "cpu", i, "old_value", cpuStats.System, "new_value", n.System)
c.logger.Debug("CPU System counter jumped backwards", "cpu", i, "old_value", cpuStats.System, "new_value", n.System)
}
if n.Iowait >= cpuStats.Iowait {
cpuStats.Iowait = n.Iowait
} else {
level.Debug(c.logger).Log("msg", "CPU Iowait counter jumped backwards", "cpu", i, "old_value", cpuStats.Iowait, "new_value", n.Iowait)
c.logger.Debug("CPU Iowait counter jumped backwards", "cpu", i, "old_value", cpuStats.Iowait, "new_value", n.Iowait)
}
if n.IRQ >= cpuStats.IRQ {
cpuStats.IRQ = n.IRQ
} else {
level.Debug(c.logger).Log("msg", "CPU IRQ counter jumped backwards", "cpu", i, "old_value", cpuStats.IRQ, "new_value", n.IRQ)
c.logger.Debug("CPU IRQ counter jumped backwards", "cpu", i, "old_value", cpuStats.IRQ, "new_value", n.IRQ)
}
if n.SoftIRQ >= cpuStats.SoftIRQ {
cpuStats.SoftIRQ = n.SoftIRQ
} else {
level.Debug(c.logger).Log("msg", "CPU SoftIRQ counter jumped backwards", "cpu", i, "old_value", cpuStats.SoftIRQ, "new_value", n.SoftIRQ)
c.logger.Debug("CPU SoftIRQ counter jumped backwards", "cpu", i, "old_value", cpuStats.SoftIRQ, "new_value", n.SoftIRQ)
}
if n.Steal >= cpuStats.Steal {
cpuStats.Steal = n.Steal
} else {
level.Debug(c.logger).Log("msg", "CPU Steal counter jumped backwards", "cpu", i, "old_value", cpuStats.Steal, "new_value", n.Steal)
c.logger.Debug("CPU Steal counter jumped backwards", "cpu", i, "old_value", cpuStats.Steal, "new_value", n.Steal)
}
if n.Guest >= cpuStats.Guest {
cpuStats.Guest = n.Guest
} else {
level.Debug(c.logger).Log("msg", "CPU Guest counter jumped backwards", "cpu", i, "old_value", cpuStats.Guest, "new_value", n.Guest)
c.logger.Debug("CPU Guest counter jumped backwards", "cpu", i, "old_value", cpuStats.Guest, "new_value", n.Guest)
}
if n.GuestNice >= cpuStats.GuestNice {
cpuStats.GuestNice = n.GuestNice
} else {
level.Debug(c.logger).Log("msg", "CPU GuestNice counter jumped backwards", "cpu", i, "old_value", cpuStats.GuestNice, "new_value", n.GuestNice)
c.logger.Debug("CPU GuestNice counter jumped backwards", "cpu", i, "old_value", cpuStats.GuestNice, "new_value", n.GuestNice)
}
c.cpuStats[i] = cpuStats

View file

@ -17,10 +17,11 @@
package collector
import (
"io"
"log/slog"
"reflect"
"testing"
"github.com/go-kit/log"
"github.com/prometheus/procfs"
)
@ -35,7 +36,7 @@ func makeTestCPUCollector(s map[int64]procfs.CPUStat) *cpuCollector {
dup := make(map[int64]procfs.CPUStat, len(s))
copyStats(dup, s)
return &cpuCollector{
logger: log.NewNopLogger(),
logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
cpuStats: dup,
}
}

View file

@ -18,6 +18,7 @@ package collector
import (
"errors"
"log/slog"
"math"
"regexp"
"sort"
@ -25,8 +26,6 @@ import (
"strings"
"unsafe"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
@ -214,7 +213,7 @@ func getCPUTimes() ([]cputime, error) {
type statCollector struct {
cpu typedDesc
temp typedDesc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -222,7 +221,7 @@ func init() {
}
// NewStatCollector returns a new Collector exposing CPU stats.
func NewStatCollector(logger log.Logger) (Collector, error) {
func NewStatCollector(logger *slog.Logger) (Collector, error) {
return &statCollector{
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
temp: typedDesc{prometheus.NewDesc(
@ -269,7 +268,7 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error {
if temp, ok := cpuTemperatures[cpu]; ok {
ch <- c.temp.mustNewConstMetric(temp, lcpu)
} else {
level.Debug(c.logger).Log("msg", "no temperature information for CPU", "cpu", cpu)
c.logger.Debug("no temperature information for CPU", "cpu", cpu)
ch <- c.temp.mustNewConstMetric(math.NaN(), lcpu)
}
}

View file

@ -17,6 +17,7 @@
package collector
import (
"log/slog"
"runtime"
"testing"
)

View file

@ -17,10 +17,10 @@
package collector
import (
"log/slog"
"strconv"
"unsafe"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)
@ -45,14 +45,14 @@ const (
type cpuCollector struct {
cpu typedDesc
logger log.Logger
logger *slog.Logger
}
func init() {
registerCollector("cpu", defaultEnabled, NewCPUCollector)
}
func NewCPUCollector(logger log.Logger) (Collector, error) {
func NewCPUCollector(logger *slog.Logger) (Collector, error) {
return &cpuCollector{
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
logger: logger,

View file

@ -17,9 +17,9 @@
package collector
import (
"log/slog"
"strconv"
"github.com/go-kit/log"
"github.com/illumos/go-kstat"
"github.com/prometheus/client_golang/prometheus"
)
@ -29,14 +29,14 @@ import "C"
type cpuCollector struct {
cpu typedDesc
logger log.Logger
logger *slog.Logger
}
func init() {
registerCollector("cpu", defaultEnabled, NewCpuCollector)
}
func NewCpuCollector(logger log.Logger) (Collector, error) {
func NewCpuCollector(logger *slog.Logger) (Collector, error) {
return &cpuCollector{
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
logger: logger,

View file

@ -15,8 +15,8 @@ package collector
import (
"fmt"
"log/slog"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
)
@ -40,7 +40,7 @@ func init() {
registerCollector(cpuVulerabilitiesCollector, defaultDisabled, NewVulnerabilitySysfsCollector)
}
func NewVulnerabilitySysfsCollector(logger log.Logger) (Collector, error) {
func NewVulnerabilitySysfsCollector(logger *slog.Logger) (Collector, error) {
return &cpuVulnerabilitiesCollector{}, nil
}

View file

@ -18,15 +18,15 @@ package collector
import (
"fmt"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
"log/slog"
"strings"
)
type cpuFreqCollector struct {
fs sysfs.FS
logger log.Logger
logger *slog.Logger
}
func init() {
@ -34,7 +34,7 @@ func init() {
}
// NewCPUFreqCollector returns a new Collector exposing kernel/system statistics.
func NewCPUFreqCollector(logger log.Logger) (Collector, error) {
func NewCPUFreqCollector(logger *slog.Logger) (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)

View file

@ -18,9 +18,9 @@ package collector
import (
"fmt"
"log/slog"
"strconv"
"github.com/go-kit/log"
"github.com/illumos/go-kstat"
"github.com/prometheus/client_golang/prometheus"
)
@ -29,14 +29,14 @@ import (
import "C"
type cpuFreqCollector struct {
logger log.Logger
logger *slog.Logger
}
func init() {
registerCollector("cpufreq", defaultEnabled, NewCpuFreqCollector)
}
func NewCpuFreqCollector(logger log.Logger) (Collector, error) {
func NewCpuFreqCollector(logger *slog.Logger) (Collector, error) {
return &cpuFreqCollector{
logger: logger,
}, nil

View file

@ -19,8 +19,8 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -98,7 +98,7 @@ type devstatCollector struct {
bytesDesc *prometheus.Desc
transfersDesc *prometheus.Desc
blocksDesc *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -106,7 +106,7 @@ func init() {
}
// NewDevstatCollector returns a new Collector exposing Device stats.
func NewDevstatCollector(logger log.Logger) (Collector, error) {
func NewDevstatCollector(logger *slog.Logger) (Collector, error) {
return &devstatCollector{
bytesDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"),

View file

@ -19,10 +19,10 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"sync"
"unsafe"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -43,7 +43,7 @@ type devstatCollector struct {
duration typedDesc
busyTime typedDesc
blocks typedDesc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -51,7 +51,7 @@ func init() {
}
// NewDevstatCollector returns a new Collector exposing Device stats.
func NewDevstatCollector(logger log.Logger) (Collector, error) {
func NewDevstatCollector(logger *slog.Logger) (Collector, error) {
return &devstatCollector{
devinfo: &C.struct_devinfo{},
bytes: typedDesc{prometheus.NewDesc(

View file

@ -19,10 +19,9 @@ package collector
import (
"errors"
"log/slog"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
@ -93,10 +92,10 @@ var (
)
)
func newDiskstatsDeviceFilter(logger log.Logger) (deviceFilter, error) {
func newDiskstatsDeviceFilter(logger *slog.Logger) (deviceFilter, error) {
if *oldDiskstatsDeviceExclude != "" {
if !diskstatsDeviceExcludeSet {
level.Warn(logger).Log("msg", "--collector.diskstats.ignored-devices is DEPRECATED and will be removed in 2.0.0, use --collector.diskstats.device-exclude")
logger.Warn("--collector.diskstats.ignored-devices is DEPRECATED and will be removed in 2.0.0, use --collector.diskstats.device-exclude")
*diskstatsDeviceExclude = *oldDiskstatsDeviceExclude
} else {
return deviceFilter{}, errors.New("--collector.diskstats.ignored-devices and --collector.diskstats.device-exclude are mutually exclusive")
@ -108,11 +107,11 @@ func newDiskstatsDeviceFilter(logger log.Logger) (deviceFilter, error) {
}
if *diskstatsDeviceExclude != "" {
level.Info(logger).Log("msg", "Parsed flag --collector.diskstats.device-exclude", "flag", *diskstatsDeviceExclude)
logger.Info("Parsed flag --collector.diskstats.device-exclude", "flag", *diskstatsDeviceExclude)
}
if *diskstatsDeviceInclude != "" {
level.Info(logger).Log("msg", "Parsed Flag --collector.diskstats.device-include", "flag", *diskstatsDeviceInclude)
logger.Info("Parsed Flag --collector.diskstats.device-include", "flag", *diskstatsDeviceInclude)
}
return newDeviceFilter(*diskstatsDeviceExclude, *diskstatsDeviceInclude), nil

View file

@ -18,8 +18,8 @@ package collector
import (
"fmt"
"log/slog"
"github.com/go-kit/log"
"github.com/lufia/iostat"
"github.com/prometheus/client_golang/prometheus"
)
@ -35,7 +35,7 @@ type diskstatsCollector struct {
descs []typedDescFunc
deviceFilter deviceFilter
logger log.Logger
logger *slog.Logger
}
func init() {
@ -43,7 +43,7 @@ func init() {
}
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) {
var diskLabelNames = []string{"device"}
deviceFilter, err := newDiskstatsDeviceFilter(logger)

View file

@ -19,12 +19,11 @@ package collector
import (
"bufio"
"fmt"
"log/slog"
"os"
"strconv"
"strings"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/blockdevice"
)
@ -85,7 +84,7 @@ type diskstatsCollector struct {
filesystemInfoDesc typedFactorDesc
deviceMapperInfoDesc typedFactorDesc
ataDescs map[string]typedFactorDesc
logger log.Logger
logger *slog.Logger
getUdevDeviceProperties func(uint32, uint32) (udevInfo, error)
}
@ -95,7 +94,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(logger *slog.Logger) (Collector, error) {
var diskLabelNames = []string{"device"}
fs, err := blockdevice.NewFS(*procPath, *sysPath)
if err != nil {
@ -262,7 +261,7 @@ func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
// Only enable getting device properties from udev if the directory is readable.
if stat, err := os.Stat(*udevDataPath); err != nil || !stat.IsDir() {
level.Error(logger).Log("msg", "Failed to open directory, disabling udev device properties", "path", *udevDataPath)
logger.Error("Failed to open directory, disabling udev device properties", "path", *udevDataPath)
} else {
collector.getUdevDeviceProperties = getUdevDeviceProperties
}
@ -284,7 +283,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
info, err := getUdevDeviceProperties(stats.MajorNumber, stats.MinorNumber)
if err != nil {
level.Debug(c.logger).Log("msg", "Failed to parse udev info", "err", err)
c.logger.Debug("Failed to parse udev info", "err", err)
}
// This is usually the serial printed on the disk label.
@ -355,14 +354,14 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
for attr, desc := range c.ataDescs {
str, ok := info[attr]
if !ok {
level.Debug(c.logger).Log("msg", "Udev attribute does not exist", "attribute", attr)
c.logger.Debug("Udev attribute does not exist", "attribute", attr)
continue
}
if value, err := strconv.ParseFloat(str, 64); err == nil {
ch <- desc.mustNewConstMetric(value, dev)
} else {
level.Error(c.logger).Log("msg", "Failed to parse ATA value", "err", err)
c.logger.Error("Failed to parse ATA value", "err", err)
}
}
}

View file

@ -18,11 +18,11 @@ package collector
import (
"fmt"
"os"
"io"
"log/slog"
"strings"
"testing"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
)
@ -39,7 +39,7 @@ func (c testDiskStatsCollector) Describe(ch chan<- *prometheus.Desc) {
prometheus.DescribeByCollect(c, ch)
}
func NewTestDiskStatsCollector(logger log.Logger) (prometheus.Collector, error) {
func NewTestDiskStatsCollector(logger *slog.Logger) (prometheus.Collector, error) {
dsc, err := NewDiskstatsCollector(logger)
if err != nil {
return testDiskStatsCollector{}, err
@ -317,7 +317,7 @@ node_disk_written_bytes_total{device="sr0"} 0
node_disk_written_bytes_total{device="vda"} 1.0938236928e+11
`
logger := log.NewLogfmtLogger(os.Stderr)
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
collector, err := NewDiskstatsCollector(logger)
if err != nil {
t.Fatal(err)

View file

@ -18,9 +18,9 @@ package collector
import (
"fmt"
"log/slog"
"unsafe"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)
@ -41,7 +41,7 @@ type diskstatsCollector struct {
time typedDesc
deviceFilter deviceFilter
logger log.Logger
logger *slog.Logger
}
func init() {
@ -49,7 +49,7 @@ func init() {
}
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) {
deviceFilter, err := newDiskstatsDeviceFilter(logger)
if err != nil {
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)

View file

@ -18,9 +18,9 @@ package collector
import (
"fmt"
"log/slog"
"unsafe"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)
@ -52,7 +52,7 @@ type diskstatsCollector struct {
time typedDesc
deviceFilter deviceFilter
logger log.Logger
logger *slog.Logger
}
func init() {
@ -60,7 +60,7 @@ func init() {
}
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) {
deviceFilter, err := newDiskstatsDeviceFilter(logger)
if err != nil {
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)

View file

@ -19,11 +19,10 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"strings"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
)
@ -38,7 +37,7 @@ func init() {
}
// NewDMICollector returns a new Collector exposing DMI information.
func NewDMICollector(logger log.Logger) (Collector, error) {
func NewDMICollector(logger *slog.Logger) (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)
@ -47,7 +46,7 @@ func NewDMICollector(logger log.Logger) (Collector, error) {
dmi, err := fs.DMIClass()
if err != nil {
if errors.Is(err, os.ErrNotExist) {
level.Debug(logger).Log("msg", "Platform does not support Desktop Management Interface (DMI) information", "err", err)
logger.Debug("Platform does not support Desktop Management Interface (DMI) information", "err", err)
dmi = &sysfs.DMIClass{}
} else {
return nil, fmt.Errorf("failed to read Desktop Management Interface (DMI) information: %w", err)

View file

@ -20,12 +20,11 @@ import (
"bufio"
"errors"
"fmt"
"log/slog"
"os"
"strconv"
"strings"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
@ -79,14 +78,14 @@ type drbdCollector struct {
numerical map[string]drbdNumericalMetric
stringPair map[string]drbdStringPairMetric
connected *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
registerCollector("drbd", defaultDisabled, newDRBDCollector)
}
func newDRBDCollector(logger log.Logger) (Collector, error) {
func newDRBDCollector(logger *slog.Logger) (Collector, error) {
return &drbdCollector{
numerical: map[string]drbdNumericalMetric{
"ns": newDRBDNumericalMetric(
@ -191,7 +190,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error {
file, err := os.Open(statsFile)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "stats file does not exist, skipping", "file", statsFile, "err", err)
c.logger.Debug("stats file does not exist, skipping", "file", statsFile, "err", err)
return ErrNoData
}
@ -208,7 +207,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error {
kv := strings.Split(field, ":")
if len(kv) != 2 {
level.Debug(c.logger).Log("msg", "skipping invalid key:value pair", "field", field)
c.logger.Debug("skipping invalid key:value pair", "field", field)
continue
}
@ -274,7 +273,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error {
continue
}
level.Debug(c.logger).Log("msg", "unhandled key-value pair", "key", kv[0], "value", kv[1])
c.logger.Debug("unhandled key-value pair", "key", kv[0], "value", kv[1])
}
return scanner.Err()

View file

@ -18,8 +18,8 @@ package collector
import (
"fmt"
"log/slog"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
)
@ -30,7 +30,7 @@ const (
type drmCollector struct {
fs sysfs.FS
logger log.Logger
logger *slog.Logger
CardInfo *prometheus.Desc
GPUBusyPercent *prometheus.Desc
MemoryGTTSize *prometheus.Desc
@ -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(logger *slog.Logger) (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)

View file

@ -18,10 +18,10 @@ package collector
import (
"fmt"
"log/slog"
"path/filepath"
"regexp"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -39,7 +39,7 @@ type edacCollector struct {
ueCount *prometheus.Desc
csRowCECount *prometheus.Desc
csRowUECount *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -47,7 +47,7 @@ func init() {
}
// NewEdacCollector returns a new Collector exposing edac stats.
func NewEdacCollector(logger log.Logger) (Collector, error) {
func NewEdacCollector(logger *slog.Logger) (Collector, error) {
return &edacCollector{
ceCount: prometheus.NewDesc(
prometheus.BuildFQName(namespace, edacSubsystem, "correctable_errors_total"),

View file

@ -18,8 +18,8 @@ package collector
import (
"fmt"
"log/slog"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)
@ -28,7 +28,7 @@ type entropyCollector struct {
fs procfs.FS
entropyAvail *prometheus.Desc
entropyPoolSize *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -36,7 +36,7 @@ func init() {
}
// NewEntropyCollector returns a new Collector exposing entropy stats.
func NewEntropyCollector(logger log.Logger) (Collector, error) {
func NewEntropyCollector(logger *slog.Logger) (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)

View file

@ -23,6 +23,7 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"regexp"
"sort"
@ -31,8 +32,6 @@ import (
"syscall"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
"github.com/safchain/ethtool"
@ -79,13 +78,13 @@ type ethtoolCollector struct {
deviceFilter deviceFilter
infoDesc *prometheus.Desc
metricsPattern *regexp.Regexp
logger log.Logger
logger *slog.Logger
}
// 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(logger *slog.Logger) (*ethtoolCollector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)
@ -97,13 +96,13 @@ func makeEthtoolCollector(logger log.Logger) (*ethtoolCollector, error) {
}
if *ethtoolDeviceInclude != "" {
level.Info(logger).Log("msg", "Parsed flag --collector.ethtool.device-include", "flag", *ethtoolDeviceInclude)
logger.Info("Parsed flag --collector.ethtool.device-include", "flag", *ethtoolDeviceInclude)
}
if *ethtoolDeviceExclude != "" {
level.Info(logger).Log("msg", "Parsed flag --collector.ethtool.device-exclude", "flag", *ethtoolDeviceExclude)
logger.Info("Parsed flag --collector.ethtool.device-exclude", "flag", *ethtoolDeviceExclude)
}
if *ethtoolIncludedMetrics != "" {
level.Info(logger).Log("msg", "Parsed flag --collector.ethtool.metrics-include", "flag", *ethtoolIncludedMetrics)
logger.Info("Parsed flag --collector.ethtool.metrics-include", "flag", *ethtoolIncludedMetrics)
}
// Pre-populate some common ethtool metrics.
@ -223,7 +222,7 @@ func buildEthtoolFQName(metric string) string {
}
// NewEthtoolCollector returns a new Collector exposing ethtool stats.
func NewEthtoolCollector(logger log.Logger) (Collector, error) {
func NewEthtoolCollector(logger *slog.Logger) (Collector, error) {
return makeEthtoolCollector(logger)
}
@ -376,7 +375,7 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
netClass, err := c.fs.NetClass()
if err != nil {
if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) {
level.Debug(c.logger).Log("msg", "Could not read netclass file", "err", err)
c.logger.Debug("Could not read netclass file", "err", err)
return ErrNoData
}
return fmt.Errorf("could not get net class info: %w", err)
@ -405,12 +404,12 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
} else {
if errno, ok := err.(syscall.Errno); ok {
if err == unix.EOPNOTSUPP {
level.Debug(c.logger).Log("msg", "ethtool link info error", "err", err, "device", device, "errno", uint(errno))
c.logger.Debug("ethtool link info error", "err", err, "device", device, "errno", uint(errno))
} else if errno != 0 {
level.Error(c.logger).Log("msg", "ethtool link info error", "err", err, "device", device, "errno", uint(errno))
c.logger.Error("ethtool link info error", "err", err, "device", device, "errno", uint(errno))
}
} else {
level.Error(c.logger).Log("msg", "ethtool link info error", "err", err, "device", device)
c.logger.Error("ethtool link info error", "err", err, "device", device)
}
}
@ -422,12 +421,12 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
} else {
if errno, ok := err.(syscall.Errno); ok {
if err == unix.EOPNOTSUPP {
level.Debug(c.logger).Log("msg", "ethtool driver info error", "err", err, "device", device, "errno", uint(errno))
c.logger.Debug("ethtool driver info error", "err", err, "device", device, "errno", uint(errno))
} else if errno != 0 {
level.Error(c.logger).Log("msg", "ethtool driver info error", "err", err, "device", device, "errno", uint(errno))
c.logger.Error("ethtool driver info error", "err", err, "device", device, "errno", uint(errno))
}
} else {
level.Error(c.logger).Log("msg", "ethtool driver info error", "err", err, "device", device)
c.logger.Error("ethtool driver info error", "err", err, "device", device)
}
}
@ -438,12 +437,12 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
if errno, ok := err.(syscall.Errno); ok {
if err == unix.EOPNOTSUPP {
level.Debug(c.logger).Log("msg", "ethtool stats error", "err", err, "device", device, "errno", uint(errno))
c.logger.Debug("ethtool stats error", "err", err, "device", device, "errno", uint(errno))
} else if errno != 0 {
level.Error(c.logger).Log("msg", "ethtool stats error", "err", err, "device", device, "errno", uint(errno))
c.logger.Error("ethtool stats error", "err", err, "device", device, "errno", uint(errno))
}
} else {
level.Error(c.logger).Log("msg", "ethtool stats error", "err", err, "device", device)
c.logger.Error("ethtool stats error", "err", err, "device", device)
}
}
@ -462,7 +461,7 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
metricFQName := buildEthtoolFQName(metricName)
existingMetric, exists := metricFQNames[metricFQName]
if exists {
level.Debug(c.logger).Log("msg", "dropping duplicate metric name", "device", device,
c.logger.Debug("dropping duplicate metric name", "device", device,
"metricFQName", metricFQName, "metric1", existingMetric, "metric2", metricName)
// Keep the metricName as "deleted" in the dict in case there are 3 duplicates.
metricFQNames[metricFQName] = ""

View file

@ -19,6 +19,8 @@ package collector
import (
"bufio"
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
"strconv"
@ -26,7 +28,6 @@ import (
"syscall"
"testing"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/safchain/ethtool"
@ -49,7 +50,7 @@ func (c testEthtoolCollector) Describe(ch chan<- *prometheus.Desc) {
prometheus.DescribeByCollect(c, ch)
}
func NewTestEthtoolCollector(logger log.Logger) (prometheus.Collector, error) {
func NewTestEthtoolCollector(logger *slog.Logger) (prometheus.Collector, error) {
dsc, err := NewEthtoolTestCollector(logger)
if err != nil {
return testEthtoolCollector{}, err
@ -255,7 +256,7 @@ func (e *EthtoolFixture) LinkInfo(intf string) (ethtool.EthtoolCmd, error) {
return res, err
}
func NewEthtoolTestCollector(logger log.Logger) (Collector, error) {
func NewEthtoolTestCollector(logger *slog.Logger) (Collector, error) {
collector, err := makeEthtoolCollector(logger)
if err != nil {
return nil, err
@ -370,7 +371,7 @@ node_network_supported_speed_bytes{device="eth0",duplex="half",mode="10baseT"} 1
`
*sysPath = "fixtures/sys"
logger := log.NewLogfmtLogger(os.Stderr)
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
collector, err := NewEthtoolTestCollector(logger)
if err != nil {
t.Fatal(err)

View file

@ -18,13 +18,13 @@
package collector
import (
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"log/slog"
)
type execCollector struct {
sysctls []bsdSysctl
logger log.Logger
logger *slog.Logger
}
func init() {
@ -32,7 +32,7 @@ func init() {
}
// NewExecCollector returns a new Collector exposing system execution statistics.
func NewExecCollector(logger log.Logger) (Collector, error) {
func NewExecCollector(logger *slog.Logger) (Collector, error) {
// From sys/vm/vm_meter.c:
// All are of type CTLTYPE_UINT.
//

View file

@ -18,10 +18,9 @@ package collector
import (
"fmt"
"log/slog"
"os"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/node_exporter/collector/utils"
"github.com/prometheus/procfs/sysfs"
@ -32,7 +31,7 @@ const maxUint64 = ^uint64(0)
type fibrechannelCollector struct {
fs sysfs.FS
metricDescs map[string]*prometheus.Desc
logger log.Logger
logger *slog.Logger
subsystem string
}
@ -41,7 +40,7 @@ func init() {
}
// NewFibreChannelCollector returns a new Collector exposing FibreChannel stats.
func NewFibreChannelCollector(logger log.Logger) (Collector, error) {
func NewFibreChannelCollector(logger *slog.Logger) (Collector, error) {
var i fibrechannelCollector
var err error
@ -99,7 +98,7 @@ func (c *fibrechannelCollector) Update(ch chan<- prometheus.Metric) error {
hosts, err := c.fs.FibreChannelClass()
if err != nil {
if os.IsNotExist(err) {
level.Debug(c.logger).Log("msg", "fibrechannel statistics not found, skipping")
c.logger.Debug("fibrechannel statistics not found, skipping")
return ErrNoData
}
return fmt.Errorf("error obtaining FibreChannel class info: %s", err)

View file

@ -20,10 +20,10 @@ import (
"bytes"
"fmt"
"io"
"log/slog"
"os"
"strconv"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -32,7 +32,7 @@ const (
)
type fileFDStatCollector struct {
logger log.Logger
logger *slog.Logger
}
func init() {
@ -40,7 +40,7 @@ func init() {
}
// NewFileFDStatCollector returns a new Collector exposing file-nr stats.
func NewFileFDStatCollector(logger log.Logger) (Collector, error) {
func NewFileFDStatCollector(logger *slog.Logger) (Collector, error) {
return &fileFDStatCollector{logger}, nil
}

View file

@ -19,9 +19,8 @@ package collector
import (
"errors"
"log/slog"
"unsafe"
"github.com/go-kit/log/level"
)
/*
@ -51,14 +50,14 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
for i := 0; i < int(count); i++ {
mountpoint := C.GoString(&mnt[i].f_mntonname[0])
if c.excludedMountPointsPattern.MatchString(mountpoint) {
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint)
c.logger.Debug("Ignoring mount point", "mountpoint", mountpoint)
continue
}
device := C.GoString(&mnt[i].f_mntfromname[0])
fstype := C.GoString(&mnt[i].f_fstypename[0])
if c.excludedFSTypesPattern.MatchString(fstype) {
level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype)
c.logger.Debug("Ignoring fs type", "type", fstype)
continue
}

View file

@ -19,11 +19,10 @@ package collector
import (
"errors"
"log/slog"
"regexp"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
@ -70,7 +69,7 @@ type filesystemCollector struct {
filesDesc, filesFreeDesc *prometheus.Desc
roDesc, deviceErrorDesc *prometheus.Desc
mountInfoDesc *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
type filesystemLabels struct {
@ -89,10 +88,10 @@ func init() {
}
// NewFilesystemCollector returns a new Collector exposing filesystems stats.
func NewFilesystemCollector(logger log.Logger) (Collector, error) {
func NewFilesystemCollector(logger *slog.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")
logger.Warn("--collector.filesystem.ignored-mount-points is DEPRECATED and will be removed in 2.0.0, use --collector.filesystem.mount-points-exclude")
*mountPointsExclude = *oldMountPointsExcluded
} else {
return nil, errors.New("--collector.filesystem.ignored-mount-points and --collector.filesystem.mount-points-exclude are mutually exclusive")
@ -101,7 +100,7 @@ func NewFilesystemCollector(logger log.Logger) (Collector, error) {
if *oldFSTypesExcluded != "" {
if !fsTypesExcludeSet {
level.Warn(logger).Log("msg", "--collector.filesystem.ignored-fs-types is DEPRECATED and will be removed in 2.0.0, use --collector.filesystem.fs-types-exclude")
logger.Warn("--collector.filesystem.ignored-fs-types is DEPRECATED and will be removed in 2.0.0, use --collector.filesystem.fs-types-exclude")
*fsTypesExclude = *oldFSTypesExcluded
} else {
return nil, errors.New("--collector.filesystem.ignored-fs-types and --collector.filesystem.fs-types-exclude are mutually exclusive")
@ -109,9 +108,9 @@ func NewFilesystemCollector(logger log.Logger) (Collector, error) {
}
subsystem := "filesystem"
level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.mount-points-exclude", "flag", *mountPointsExclude)
logger.Info("Parsed flag --collector.filesystem.mount-points-exclude", "flag", *mountPointsExclude)
mountPointPattern := regexp.MustCompile(*mountPointsExclude)
level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.fs-types-exclude", "flag", *fsTypesExclude)
logger.Info("Parsed flag --collector.filesystem.fs-types-exclude", "flag", *fsTypesExclude)
filesystemsTypesPattern := regexp.MustCompile(*fsTypesExclude)
sizeDesc := prometheus.NewDesc(

View file

@ -17,8 +17,8 @@
package collector
import (
"github.com/go-kit/log/level"
"golang.org/x/sys/unix"
"log/slog"
)
const (
@ -41,19 +41,19 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
for _, fs := range buf {
mountpoint := unix.ByteSliceToString(fs.Mntonname[:])
if c.excludedMountPointsPattern.MatchString(mountpoint) {
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint)
c.logger.Debug("Ignoring mount point", "mountpoint", mountpoint)
continue
}
device := unix.ByteSliceToString(fs.Mntfromname[:])
fstype := unix.ByteSliceToString(fs.Fstypename[:])
if c.excludedFSTypesPattern.MatchString(fstype) {
level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype)
c.logger.Debug("Ignoring fs type", "type", fstype)
continue
}
if (fs.Flags & unix.MNT_IGNORE) != 0 {
level.Debug(c.logger).Log("msg", "Ignoring mount flagged as ignore", "mountpoint", mountpoint)
c.logger.Debug("Ignoring mount flagged as ignore", "mountpoint", mountpoint)
continue
}

View file

@ -21,14 +21,13 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"os"
"strings"
"sync"
"time"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"golang.org/x/sys/unix"
)
@ -75,11 +74,11 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
go func() {
for _, labels := range mps {
if c.excludedMountPointsPattern.MatchString(labels.mountPoint) {
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", labels.mountPoint)
c.logger.Debug("Ignoring mount point", "mountpoint", labels.mountPoint)
continue
}
if c.excludedFSTypesPattern.MatchString(labels.fsType) {
level.Debug(c.logger).Log("msg", "Ignoring fs", "type", labels.fsType)
c.logger.Debug("Ignoring fs", "type", labels.fsType)
continue
}
@ -90,7 +89,7 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
labels: labels,
deviceError: 1,
})
level.Debug(c.logger).Log("msg", "Mount point is in an unresponsive state", "mountpoint", labels.mountPoint)
c.logger.Debug("Mount point is in an unresponsive state", "mountpoint", labels.mountPoint)
stuckMountsMtx.Unlock()
continue
}
@ -128,14 +127,14 @@ func (c *filesystemCollector) processStat(labels filesystemLabels) filesystemSta
// If the mount has been marked as stuck, unmark it and log it's recovery.
if _, ok := stuckMounts[labels.mountPoint]; ok {
level.Debug(c.logger).Log("msg", "Mount point has recovered, monitoring will resume", "mountpoint", labels.mountPoint)
c.logger.Debug("Mount point has recovered, monitoring will resume", "mountpoint", labels.mountPoint)
delete(stuckMounts, labels.mountPoint)
}
stuckMountsMtx.Unlock()
if err != nil {
labels.deviceError = err.Error()
level.Debug(c.logger).Log("msg", "Error on statfs() system call", "rootfs", rootfsFilePath(labels.mountPoint), "err", err)
c.logger.Debug("Error on statfs() system call", "rootfs", rootfsFilePath(labels.mountPoint), "err", err)
return filesystemStats{
labels: labels,
deviceError: 1,
@ -157,7 +156,7 @@ func (c *filesystemCollector) processStat(labels filesystemLabels) filesystemSta
// stuckMountWatcher listens on the given success channel and if the channel closes
// then the watcher does nothing. If instead the timeout is reached, the
// mount point that is being watched is marked as stuck.
func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logger) {
func stuckMountWatcher(mountPoint string, success chan struct{}, logger *slog.Logger) {
mountCheckTimer := time.NewTimer(*mountTimeout)
defer mountCheckTimer.Stop()
select {
@ -170,18 +169,18 @@ func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logg
case <-success:
// Success came in just after the timeout was reached, don't label the mount as stuck
default:
level.Debug(logger).Log("msg", "Mount point timed out, it is being labeled as stuck and will not be monitored", "mountpoint", mountPoint)
logger.Debug("Mount point timed out, it is being labeled as stuck and will not be monitored", "mountpoint", mountPoint)
stuckMounts[mountPoint] = struct{}{}
}
stuckMountsMtx.Unlock()
}
}
func mountPointDetails(logger log.Logger) ([]filesystemLabels, error) {
func mountPointDetails(logger *slog.Logger) ([]filesystemLabels, error) {
file, err := os.Open(procFilePath("1/mountinfo"))
if errors.Is(err, os.ErrNotExist) {
// Fallback to `/proc/self/mountinfo` if `/proc/1/mountinfo` is missing due hidepid.
level.Debug(logger).Log("msg", "Reading root mounts failed, falling back to self mounts", "err", err)
logger.Debug("Reading root mounts failed, falling back to self mounts", "err", err)
file, err = os.Open(procFilePath("self/mountinfo"))
}
if err != nil {

View file

@ -17,11 +17,12 @@
package collector
import (
"io"
"log/slog"
"strings"
"testing"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
)
func Test_parseFilesystemLabelsError(t *testing.T) {
@ -82,7 +83,7 @@ func TestMountPointDetails(t *testing.T) {
"/var/lib/kubelet/plugins/kubernetes.io/vsphere-volume/mounts/[vsanDatastore] bafb9e5a-8856-7e6c-699c-801844e77a4a/kubernetes-dynamic-pvc-3eba5bba-48a3-11e8-89ab-005056b92113.vmdk": "",
}
filesystems, err := mountPointDetails(log.NewNopLogger())
filesystems, err := mountPointDetails(slog.New(slog.NewTextHandler(io.Discard, nil)))
if err != nil {
t.Log(err)
}
@ -111,7 +112,7 @@ func TestMountsFallback(t *testing.T) {
"/": "",
}
filesystems, err := mountPointDetails(log.NewNopLogger())
filesystems, err := mountPointDetails(slog.New(slog.NewTextHandler(io.Discard, nil)))
if err != nil {
t.Log(err)
}
@ -139,7 +140,7 @@ func TestPathRootfs(t *testing.T) {
"/sys/fs/cgroup": "",
}
filesystems, err := mountPointDetails(log.NewNopLogger())
filesystems, err := mountPointDetails(slog.New(slog.NewTextHandler(io.Discard, nil)))
if err != nil {
t.Log(err)
}

View file

@ -17,8 +17,8 @@
package collector
import (
"github.com/go-kit/log/level"
"golang.org/x/sys/unix"
"log/slog"
)
const (
@ -43,14 +43,14 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
for _, v := range mnt {
mountpoint := unix.ByteSliceToString(v.F_mntonname[:])
if c.excludedMountPointsPattern.MatchString(mountpoint) {
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint)
c.logger.Debug("Ignoring mount point", "mountpoint", mountpoint)
continue
}
device := unix.ByteSliceToString(v.F_mntfromname[:])
fstype := unix.ByteSliceToString(v.F_fstypename[:])
if c.excludedFSTypesPattern.MatchString(fstype) {
level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype)
c.logger.Debug("Ignoring fs type", "type", fstype)
continue
}

View file

@ -18,6 +18,7 @@ package collector
import (
"errors"
"log/slog"
"os"
"path/filepath"
"regexp"
@ -25,8 +26,6 @@ import (
"strings"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)
@ -55,12 +54,12 @@ func init() {
type hwMonCollector struct {
deviceFilter deviceFilter
sensorFilter deviceFilter
logger log.Logger
logger *slog.Logger
}
// NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats
// (similar to lm-sensors).
func NewHwMonCollector(logger log.Logger) (Collector, error) {
func NewHwMonCollector(logger *slog.Logger) (Collector, error) {
return &hwMonCollector{
logger: logger,
@ -168,7 +167,7 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) er
}
if c.deviceFilter.ignored(hwmonName) {
level.Debug(c.logger).Log("msg", "ignoring hwmon chip", "chip", hwmonName)
c.logger.Debug("ignoring hwmon chip", "chip", hwmonName)
return nil
}
@ -211,7 +210,7 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) er
// sensors on specific devices. For example, to exclude the sensor "temp3" on
// the device "platform_coretemp_0", use "platform_coretemp_0;temp3"
if c.sensorFilter.ignored(hwmonName + ";" + sensor) {
level.Debug(c.logger).Log("msg", "ignoring sensor", "sensor", sensor)
c.logger.Debug("ignoring sensor", "sensor", sensor)
continue
}
@ -450,7 +449,7 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error {
hwmonFiles, err := os.ReadDir(hwmonPathName)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "hwmon collector metrics are not available for this system")
c.logger.Debug("hwmon collector metrics are not available for this system")
return ErrNoData
}

View file

@ -19,11 +19,10 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"strconv"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
)
@ -31,7 +30,7 @@ import (
type infinibandCollector struct {
fs sysfs.FS
metricDescs map[string]*prometheus.Desc
logger log.Logger
logger *slog.Logger
subsystem string
}
@ -40,7 +39,7 @@ func init() {
}
// NewInfiniBandCollector returns a new Collector exposing InfiniBand stats.
func NewInfiniBandCollector(logger log.Logger) (Collector, error) {
func NewInfiniBandCollector(logger *slog.Logger) (Collector, error) {
var i infinibandCollector
var err error
@ -116,7 +115,7 @@ func (c *infinibandCollector) Update(ch chan<- prometheus.Metric) error {
devices, err := c.fs.InfiniBandClass()
if err != nil {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "infiniband statistics not found, skipping")
c.logger.Debug("infiniband statistics not found, skipping")
return ErrNoData
}
return fmt.Errorf("error obtaining InfiniBand class info: %w", err)

View file

@ -19,13 +19,13 @@ package collector
import (
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"log/slog"
)
type interruptsCollector struct {
desc typedDesc
logger log.Logger
logger *slog.Logger
nameFilter deviceFilter
includeZeros bool
}
@ -41,7 +41,7 @@ var (
)
// NewInterruptsCollector returns a new Collector exposing interrupts stats.
func NewInterruptsCollector(logger log.Logger) (Collector, error) {
func NewInterruptsCollector(logger *slog.Logger) (Collector, error) {
return &interruptsCollector{
desc: typedDesc{prometheus.NewDesc(
namespace+"_interrupts_total",

View file

@ -25,7 +25,6 @@ import (
"strconv"
"strings"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
@ -42,7 +41,7 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) (err error) {
for cpuNo, value := range interrupt.values {
filterName := name + ";" + interrupt.info + ";" + interrupt.devices
if c.nameFilter.ignored(filterName) {
level.Debug(c.logger).Log("msg", "ignoring interrupt name", "filter_name", filterName)
c.logger.Debug("ignoring interrupt name", "filter_name", filterName)
continue
}
fv, err := strconv.ParseFloat(value, 64)
@ -50,7 +49,7 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) (err error) {
return fmt.Errorf("invalid value %s in interrupts: %w", value, err)
}
if !c.includeZeros && fv == 0.0 {
level.Debug(c.logger).Log("msg", "ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo)
c.logger.Debug("ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo)
continue
}
ch <- c.desc.mustNewConstMetric(fv, strconv.Itoa(cpuNo), name, interrupt.info, interrupt.devices)

View file

@ -18,9 +18,9 @@ package collector
import (
"fmt"
"log/slog"
"strconv"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
@ -110,11 +110,11 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) error {
interruptType := fmt.Sprintf("%d", interrupt.vector)
filterName := interruptType + ";" + dev
if c.nameFilter.ignored(filterName) {
level.Debug(c.logger).Log("msg", "ignoring interrupt name", "filter_name", filterName)
c.logger.Debug("ignoring interrupt name", "filter_name", filterName)
continue
}
if !c.includeZeros && value == 0.0 {
level.Debug(c.logger).Log("msg", "ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo)
c.logger.Debug("ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo)
continue
}
ch <- c.desc.mustNewConstMetric(

View file

@ -18,10 +18,10 @@ package collector
import (
"fmt"
"log/slog"
"strconv"
"unsafe"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)
@ -81,11 +81,11 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) error {
interruptType := fmt.Sprintf("%d", interrupt.vector)
filterName := interruptType + ";" + dev
if c.nameFilter.ignored(filterName) {
level.Debug(c.logger).Log("msg", "ignoring interrupt name", "filter_name", filterName)
c.logger.Debug("ignoring interrupt name", "filter_name", filterName)
continue
}
if !c.includeZeros && value == 0.0 {
level.Debug(c.logger).Log("msg", "ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo)
c.logger.Debug("ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo)
continue
}
ch <- c.desc.mustNewConstMetric(

View file

@ -19,14 +19,13 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"sort"
"strconv"
"strings"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)
@ -37,7 +36,7 @@ type ipvsCollector struct {
backendLabels []string
backendConnectionsActive, backendConnectionsInact, backendWeight typedDesc
connections, incomingPackets, outgoingPackets, incomingBytes, outgoingBytes typedDesc
logger log.Logger
logger *slog.Logger
}
type ipvsBackendStatus struct {
@ -73,11 +72,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) {
func NewIPVSCollector(logger *slog.Logger) (Collector, error) {
return newIPVSCollector(logger)
}
func newIPVSCollector(logger log.Logger) (*ipvsCollector, error) {
func newIPVSCollector(logger *slog.Logger) (*ipvsCollector, error) {
var (
c ipvsCollector
err error
@ -143,7 +142,7 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
// Cannot access ipvs metrics, report no error.
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "ipvs collector metrics are not available for this system")
c.logger.Debug("ipvs collector metrics are not available for this system")
return ErrNoData
}
return fmt.Errorf("could not get IPVS stats: %w", err)

View file

@ -19,14 +19,14 @@ package collector
import (
"errors"
"fmt"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"github.com/go-kit/log"
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
@ -114,7 +114,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(slog.New(slog.NewTextHandler(io.Discard, nil)))
if err != nil {
if test.err == nil {
t.Fatal(err)
@ -182,7 +182,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(slog.New(slog.NewTextHandler(io.Discard, nil)))
if err != nil {
t.Fatal(err)
}

View file

@ -18,9 +18,9 @@ package collector
import (
"fmt"
"log/slog"
"path/filepath"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -31,7 +31,7 @@ var (
type ksmdCollector struct {
metricDescs map[string]*prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -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(logger *slog.Logger) (Collector, error) {
subsystem := "ksmd"
descs := make(map[string]*prometheus.Desc)

View file

@ -19,6 +19,7 @@ package collector
import (
"fmt"
"log/slog"
"sync"
)

View file

@ -18,22 +18,22 @@ package collector
import (
"fmt"
"log/slog"
"strconv"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)
type lnstatCollector struct {
logger log.Logger
logger *slog.Logger
}
func init() {
registerCollector("lnstat", defaultDisabled, NewLnstatCollector)
}
func NewLnstatCollector(logger log.Logger) (Collector, error) {
func NewLnstatCollector(logger *slog.Logger) (Collector, error) {
return &lnstatCollector{logger}, nil
}

View file

@ -19,15 +19,14 @@ package collector
import (
"fmt"
"log/slog"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
type loadavgCollector struct {
metric []typedDesc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -35,7 +34,7 @@ func init() {
}
// NewLoadavgCollector returns a new Collector exposing load average stats.
func NewLoadavgCollector(logger log.Logger) (Collector, error) {
func NewLoadavgCollector(logger *slog.Logger) (Collector, error) {
return &loadavgCollector{
metric: []typedDesc{
{prometheus.NewDesc(namespace+"_load1", "1m load average.", nil, nil), prometheus.GaugeValue},
@ -52,7 +51,7 @@ func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) error {
return fmt.Errorf("couldn't get load: %w", err)
}
for i, load := range loads {
level.Debug(c.logger).Log("msg", "return load", "index", i, "load", load)
c.logger.Debug("return load", "index", i, "load", load)
ch <- c.metric[i].mustNewConstMetric(load)
}
return err

View file

@ -18,6 +18,7 @@
package collector
import (
"log/slog"
"unsafe"
"golang.org/x/sys/unix"

View file

@ -18,6 +18,7 @@ package collector
import (
"fmt"
"log/slog"
"strconv"
"github.com/illumos/go-kstat"

View file

@ -18,10 +18,10 @@ package collector
import (
"fmt"
"log/slog"
"os"
"strconv"
"github.com/go-kit/log"
"github.com/godbus/dbus/v5"
"github.com/prometheus/client_golang/prometheus"
)
@ -46,7 +46,7 @@ var (
)
type logindCollector struct {
logger log.Logger
logger *slog.Logger
}
type logindDbus struct {
@ -86,7 +86,7 @@ func init() {
}
// NewLogindCollector returns a new Collector exposing logind statistics.
func NewLogindCollector(logger log.Logger) (Collector, error) {
func NewLogindCollector(logger *slog.Logger) (Collector, error) {
return &logindCollector{logger}, nil
}

View file

@ -19,16 +19,15 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)
type mdadmCollector struct {
logger log.Logger
logger *slog.Logger
}
func init() {
@ -36,7 +35,7 @@ func init() {
}
// NewMdadmCollector returns a new Collector exposing raid statistics.
func NewMdadmCollector(logger log.Logger) (Collector, error) {
func NewMdadmCollector(logger *slog.Logger) (Collector, error) {
return &mdadmCollector{logger}, nil
}
@ -112,7 +111,7 @@ func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "Not collecting mdstat, file does not exist", "file", *procPath)
c.logger.Debug("Not collecting mdstat, file does not exist", "file", *procPath)
return ErrNoData
}
@ -120,7 +119,7 @@ func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error {
}
for _, mdStat := range mdStats {
level.Debug(c.logger).Log("msg", "collecting metrics for device", "device", mdStat.Name)
c.logger.Debug("collecting metrics for device", "device", mdStat.Name)
stateVals := make(map[string]float64)
stateVals[mdStat.ActivityState] = 1

View file

@ -21,7 +21,6 @@ import (
"fmt"
"strings"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
@ -41,7 +40,7 @@ func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
return fmt.Errorf("couldn't get meminfo: %w", err)
}
level.Debug(c.logger).Log("msg", "Set node_mem", "memInfo", fmt.Sprintf("%v", memInfo))
c.logger.Debug("Set node_mem", "memInfo", fmt.Sprintf("%v", memInfo))
for k, v := range memInfo {
if strings.HasSuffix(k, "_total") {
metricType = prometheus.CounterValue

View file

@ -24,18 +24,18 @@ import "C"
import (
"encoding/binary"
"fmt"
"log/slog"
"unsafe"
"github.com/go-kit/log"
"golang.org/x/sys/unix"
)
type meminfoCollector struct {
logger log.Logger
logger *slog.Logger
}
// NewMeminfoCollector returns a new Collector exposing memory stats.
func NewMeminfoCollector(logger log.Logger) (Collector, error) {
func NewMeminfoCollector(logger *slog.Logger) (Collector, error) {
return &meminfoCollector{
logger: logger,
}, nil

View file

@ -18,18 +18,18 @@ package collector
import (
"fmt"
"log/slog"
"github.com/go-kit/log"
"github.com/prometheus/procfs"
)
type meminfoCollector struct {
fs procfs.FS
logger log.Logger
logger *slog.Logger
}
// NewMeminfoCollector returns a new Collector exposing memory stats.
func NewMeminfoCollector(logger log.Logger) (Collector, error) {
func NewMeminfoCollector(logger *slog.Logger) (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)

View file

@ -17,15 +17,14 @@
package collector
import (
"os"
"io"
"log/slog"
"testing"
"github.com/go-kit/log"
)
func TestMemInfo(t *testing.T) {
*procPath = "fixtures/proc"
logger := log.NewLogfmtLogger(os.Stderr)
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
collector, err := NewMeminfoCollector(logger)
if err != nil {

View file

@ -17,16 +17,16 @@
package collector
import (
"github.com/go-kit/log"
"golang.org/x/sys/unix"
"log/slog"
)
type meminfoCollector struct {
logger log.Logger
logger *slog.Logger
}
// NewMeminfoCollector returns a new Collector exposing memory stats.
func NewMeminfoCollector(logger log.Logger) (Collector, error) {
func NewMeminfoCollector(logger *slog.Logger) (Collector, error) {
return &meminfoCollector{
logger: logger,
}, nil

View file

@ -20,13 +20,13 @@ import (
"bufio"
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -45,7 +45,7 @@ type meminfoMetric struct {
type meminfoNumaCollector struct {
metricDescs map[string]*prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -53,7 +53,7 @@ func init() {
}
// NewMeminfoNumaCollector returns a new Collector exposing memory stats.
func NewMeminfoNumaCollector(logger log.Logger) (Collector, error) {
func NewMeminfoNumaCollector(logger *slog.Logger) (Collector, error) {
return &meminfoNumaCollector{
metricDescs: map[string]*prometheus.Desc{},
logger: logger,

View file

@ -18,8 +18,7 @@ package collector
import (
"fmt"
"github.com/go-kit/log"
"log/slog"
)
/*
@ -56,11 +55,11 @@ sysctl_bcstats(struct bcachestats *bcstats)
import "C"
type meminfoCollector struct {
logger log.Logger
logger *slog.Logger
}
// NewMeminfoCollector returns a new Collector exposing memory stats.
func NewMeminfoCollector(logger log.Logger) (Collector, error) {
func NewMeminfoCollector(logger *slog.Logger) (Collector, error) {
return &meminfoCollector{
logger: logger,
}, nil

View file

@ -17,9 +17,9 @@
package collector
import (
"log/slog"
"unsafe"
"github.com/go-kit/log"
"golang.org/x/sys/unix"
)
@ -51,11 +51,11 @@ type bcachestats struct {
}
type meminfoCollector struct {
logger log.Logger
logger *slog.Logger
}
// NewMeminfoCollector returns a new Collector exposing memory stats.
func NewMeminfoCollector(logger log.Logger) (Collector, error) {
func NewMeminfoCollector(logger *slog.Logger) (Collector, error) {
return &meminfoCollector{
logger: logger,
}, nil

View file

@ -19,8 +19,8 @@ package collector
import (
"fmt"
"log/slog"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)
@ -33,7 +33,7 @@ type memoryCollector struct {
pageSize uint64
sysctls []bsdSysctl
kvm kvm
logger log.Logger
logger *slog.Logger
}
func init() {
@ -41,7 +41,7 @@ func init() {
}
// NewMemoryCollector returns a new Collector exposing memory stats.
func NewMemoryCollector(logger log.Logger) (Collector, error) {
func NewMemoryCollector(logger *slog.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)

View file

@ -18,9 +18,8 @@ package collector
import (
"fmt"
"log/slog"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)
@ -96,7 +95,7 @@ type mountStatsCollector struct {
proc procfs.Proc
logger log.Logger
logger *slog.Logger
}
// used to uniquely identify an NFS mount to prevent duplicates
@ -111,7 +110,7 @@ func init() {
}
// NewMountStatsCollector returns a new Collector exposing NFS statistics.
func NewMountStatsCollector(logger log.Logger) (Collector, error) {
func NewMountStatsCollector(logger *slog.Logger) (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)
@ -542,7 +541,7 @@ func (c *mountStatsCollector) Update(ch chan<- prometheus.Metric) error {
deviceIdentifier := nfsDeviceIdentifier{m.Device, stats.Transport[k].Protocol, mountAddress}
i := deviceList[deviceIdentifier]
if i {
level.Debug(c.logger).Log("msg", "Skipping duplicate device entry", "device", deviceIdentifier)
c.logger.Debug("Skipping duplicate device entry", "device", deviceIdentifier)
break
}
deviceList[deviceIdentifier] = true

View file

@ -19,14 +19,13 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"net"
"os"
"regexp"
"sync"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
)
@ -43,7 +42,7 @@ type netClassCollector struct {
ignoredDevicesPattern *regexp.Regexp
metricDescs map[string]*prometheus.Desc
metricDescsMu sync.Mutex
logger log.Logger
logger *slog.Logger
}
func init() {
@ -51,7 +50,7 @@ func init() {
}
// NewNetClassCollector returns a new Collector exposing network class stats.
func NewNetClassCollector(logger log.Logger) (Collector, error) {
func NewNetClassCollector(logger *slog.Logger) (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)
@ -77,7 +76,7 @@ func (c *netClassCollector) netClassSysfsUpdate(ch chan<- prometheus.Metric) err
netClass, err := c.getNetClassInfo()
if err != nil {
if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) {
level.Debug(c.logger).Log("msg", "Could not read netclass file", "err", err)
c.logger.Debug("Could not read netclass file", "err", err)
return ErrNoData
}
return fmt.Errorf("could not get net class info: %w", err)

View file

@ -23,7 +23,6 @@ import (
"path/filepath"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log/level"
"github.com/jsimonetti/rtnetlink"
"github.com/mdlayher/ethtool"
"github.com/prometheus/client_golang/prometheus"
@ -45,7 +44,7 @@ func (c *netClassCollector) netClassRTNLUpdate(ch chan<- prometheus.Metric) erro
if !errors.Is(errors.Unwrap(err), fs.ErrNotExist) {
return fmt.Errorf("could not get link modes: %w", err)
}
level.Info(c.logger).Log("msg", "ETHTOOL netlink interface unavailable, duplex and linkspeed are not scraped.")
c.logger.Info("ETHTOOL netlink interface unavailable, duplex and linkspeed are not scraped.")
} else {
for _, lm := range lms {
if c.ignoredDevicesPattern.MatchString(lm.Interface.Name) {

View file

@ -19,9 +19,7 @@ package collector
import (
"errors"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"log/slog"
)
/*
@ -34,7 +32,7 @@ import (
*/
import "C"
func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) {
func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) {
netDev := netDevStats{}
var ifap, ifa *C.struct_ifaddrs
@ -50,7 +48,7 @@ func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error
dev := C.GoString(ifa.ifa_name)
if filter.ignored(dev) {
level.Debug(logger).Log("msg", "Ignoring device", "device", dev)
logger.Debug("Ignoring device", "device", dev)
continue
}

View file

@ -20,13 +20,12 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"net"
"strconv"
"sync"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
@ -44,7 +43,7 @@ type netDevCollector struct {
deviceFilter deviceFilter
metricDescsMutex sync.Mutex
metricDescs map[string]*prometheus.Desc
logger log.Logger
logger *slog.Logger
}
type netDevStats map[string]map[string]uint64
@ -54,10 +53,10 @@ func init() {
}
// NewNetDevCollector returns a new Collector exposing network device stats.
func NewNetDevCollector(logger log.Logger) (Collector, error) {
func NewNetDevCollector(logger *slog.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")
logger.Warn("--collector.netdev.device-whitelist is DEPRECATED and will be removed in 2.0.0, use --collector.netdev.device-include")
*netdevDeviceInclude = *oldNetdevDeviceInclude
} else {
return nil, errors.New("--collector.netdev.device-whitelist and --collector.netdev.device-include are mutually exclusive")
@ -66,7 +65,7 @@ func NewNetDevCollector(logger log.Logger) (Collector, error) {
if *oldNetdevDeviceExclude != "" {
if *netdevDeviceExclude == "" {
level.Warn(logger).Log("msg", "--collector.netdev.device-blacklist is DEPRECATED and will be removed in 2.0.0, use --collector.netdev.device-exclude")
logger.Warn("--collector.netdev.device-blacklist is DEPRECATED and will be removed in 2.0.0, use --collector.netdev.device-exclude")
*netdevDeviceExclude = *oldNetdevDeviceExclude
} else {
return nil, errors.New("--collector.netdev.device-blacklist and --collector.netdev.device-exclude are mutually exclusive")
@ -78,11 +77,11 @@ func NewNetDevCollector(logger log.Logger) (Collector, error) {
}
if *netdevDeviceExclude != "" {
level.Info(logger).Log("msg", "Parsed flag --collector.netdev.device-exclude", "flag", *netdevDeviceExclude)
logger.Info("Parsed flag --collector.netdev.device-exclude", "flag", *netdevDeviceExclude)
}
if *netdevDeviceInclude != "" {
level.Info(logger).Log("msg", "Parsed Flag --collector.netdev.device-include", "flag", *netdevDeviceInclude)
logger.Info("Parsed Flag --collector.netdev.device-include", "flag", *netdevDeviceInclude)
}
return &netDevCollector{

View file

@ -20,14 +20,13 @@ import (
"bytes"
"encoding/binary"
"fmt"
"log/slog"
"net"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"golang.org/x/sys/unix"
)
func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) {
func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) {
netDev := netDevStats{}
ifs, err := net.Interfaces()
@ -37,13 +36,13 @@ func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error
for _, iface := range ifs {
if filter.ignored(iface.Name) {
level.Debug(logger).Log("msg", "Ignoring device", "device", iface.Name)
logger.Debug("Ignoring device", "device", iface.Name)
continue
}
ifaceData, err := getIfaceData(iface.Index)
if err != nil {
level.Debug(logger).Log("msg", "failed to load data for interface", "device", iface.Name, "err", err)
logger.Debug("failed to load data for interface", "device", iface.Name, "err", err)
continue
}

View file

@ -18,10 +18,9 @@ package collector
import (
"fmt"
"log/slog"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/jsimonetti/rtnetlink"
"github.com/prometheus/procfs"
)
@ -30,14 +29,14 @@ var (
netDevNetlink = kingpin.Flag("collector.netdev.netlink", "Use netlink to gather stats instead of /proc/net/dev.").Default("true").Bool()
)
func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) {
func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) {
if *netDevNetlink {
return netlinkStats(filter, logger)
}
return procNetDevStats(filter, logger)
}
func netlinkStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) {
func netlinkStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) {
conn, err := rtnetlink.Dial(nil)
if err != nil {
return nil, err
@ -52,12 +51,12 @@ func netlinkStats(filter *deviceFilter, logger log.Logger) (netDevStats, error)
return parseNetlinkStats(links, filter, logger), nil
}
func parseNetlinkStats(links []rtnetlink.LinkMessage, filter *deviceFilter, logger log.Logger) netDevStats {
func parseNetlinkStats(links []rtnetlink.LinkMessage, filter *deviceFilter, logger *slog.Logger) netDevStats {
metrics := netDevStats{}
for _, msg := range links {
if msg.Attributes == nil {
level.Debug(logger).Log("msg", "No netlink attributes, skipping")
logger.Debug("No netlink attributes, skipping")
continue
}
name := msg.Attributes.Name
@ -93,13 +92,13 @@ func parseNetlinkStats(links []rtnetlink.LinkMessage, filter *deviceFilter, logg
}
if filter.ignored(name) {
level.Debug(logger).Log("msg", "Ignoring device", "device", name)
logger.Debug("Ignoring device", "device", name)
continue
}
// Make sure we don't panic when accessing `stats` attributes below.
if stats == nil {
level.Debug(logger).Log("msg", "No netlink stats, skipping")
logger.Debug("No netlink stats, skipping")
continue
}
@ -141,7 +140,7 @@ func parseNetlinkStats(links []rtnetlink.LinkMessage, filter *deviceFilter, logg
return metrics
}
func procNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) {
func procNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) {
metrics := netDevStats{}
fs, err := procfs.NewFS(*procPath)
@ -158,7 +157,7 @@ func procNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, erro
name := stats.Name
if filter.ignored(name) {
level.Debug(logger).Log("msg", "Ignoring device", "device", name)
logger.Debug("Ignoring device", "device", name)
continue
}

View file

@ -17,10 +17,10 @@
package collector
import (
"io"
"log/slog"
"testing"
"github.com/go-kit/log"
"github.com/jsimonetti/rtnetlink"
)
@ -166,7 +166,7 @@ var links = []rtnetlink.LinkMessage{
func TestNetDevStatsIgnore(t *testing.T) {
filter := newDeviceFilter("^veth", "")
netStats := parseNetlinkStats(links, &filter, log.NewNopLogger())
netStats := parseNetlinkStats(links, &filter, slog.New(slog.NewTextHandler(io.Discard, nil)))
if want, got := uint64(10437182923), netStats["wlan0"]["receive_bytes"]; want != got {
t.Errorf("want netstat wlan0 bytes %v, got %v", want, got)
@ -199,7 +199,7 @@ func TestNetDevStatsIgnore(t *testing.T) {
func TestNetDevStatsAccept(t *testing.T) {
filter := newDeviceFilter("", "^💩0$")
netStats := parseNetlinkStats(links, &filter, log.NewNopLogger())
netStats := parseNetlinkStats(links, &filter, slog.New(slog.NewTextHandler(io.Discard, nil)))
if want, got := 1, len(netStats); want != got {
t.Errorf("want count of devices to be %d, got %d", want, got)
@ -230,7 +230,7 @@ func TestNetDevLegacyMetricNames(t *testing.T) {
}
filter := newDeviceFilter("", "")
netStats := parseNetlinkStats(links, &filter, log.NewNopLogger())
netStats := parseNetlinkStats(links, &filter, slog.New(slog.NewTextHandler(io.Discard, nil)))
for dev, devStats := range netStats {
legacy(devStats)
@ -263,7 +263,7 @@ func TestNetDevLegacyMetricValues(t *testing.T) {
}
filter := newDeviceFilter("", "^enp0s0f0$")
netStats := parseNetlinkStats(links, &filter, log.NewNopLogger())
netStats := parseNetlinkStats(links, &filter, slog.New(slog.NewTextHandler(io.Discard, nil)))
metrics, ok := netStats["enp0s0f0"]
if !ok {
t.Error("expected stats for interface enp0s0f0")
@ -285,7 +285,7 @@ func TestNetDevLegacyMetricValues(t *testing.T) {
func TestNetDevMetricValues(t *testing.T) {
filter := newDeviceFilter("", "")
netStats := parseNetlinkStats(links, &filter, log.NewNopLogger())
netStats := parseNetlinkStats(links, &filter, slog.New(slog.NewTextHandler(io.Discard, nil)))
for _, msg := range links {
device := msg.Attributes.Name

View file

@ -18,9 +18,7 @@ package collector
import (
"errors"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"log/slog"
)
/*
@ -31,7 +29,7 @@ import (
*/
import "C"
func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) {
func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) {
netDev := netDevStats{}
var ifap, ifa *C.struct_ifaddrs
@ -47,7 +45,7 @@ func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error
dev := C.GoString(ifa.ifa_name)
if filter.ignored(dev) {
level.Debug(logger).Log("msg", "Ignoring device", "device", dev)
logger.Debug("Ignoring device", "device", dev)
continue
}

View file

@ -17,14 +17,13 @@
package collector
import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"log/slog"
"golang.org/x/sys/unix"
"unsafe"
)
func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) {
func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) {
netDev := netDevStats{}
mib := [6]_C_int{unix.CTL_NET, unix.AF_ROUTE, 0, 0, unix.NET_RT_IFLIST, 0}
@ -54,7 +53,7 @@ func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error
data := ifm.Data
dev := int8ToString(dl.Data[:dl.Nlen])
if filter.ignored(dev) {
level.Debug(logger).Log("msg", "Ignoring device", "device", dev)
logger.Debug("Ignoring device", "device", dev)
continue
}

View file

@ -18,14 +18,14 @@ package collector
import (
"fmt"
"log/slog"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
type netisrCollector struct {
sysctls []bsdSysctl
logger log.Logger
logger *slog.Logger
}
const (
@ -36,7 +36,7 @@ func init() {
registerCollector("netisr", defaultEnabled, NewNetisrCollector)
}
func NewNetisrCollector(logger log.Logger) (Collector, error) {
func NewNetisrCollector(logger *slog.Logger) (Collector, error) {
return &netisrCollector{
sysctls: []bsdSysctl{
{

View file

@ -21,13 +21,13 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"os"
"regexp"
"strconv"
"strings"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -41,7 +41,7 @@ var (
type netStatCollector struct {
fieldPattern *regexp.Regexp
logger log.Logger
logger *slog.Logger
}
func init() {
@ -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(logger *slog.Logger) (Collector, error) {
pattern := regexp.MustCompile(*netStatFields)
return &netStatCollector{
fieldPattern: pattern,

View file

@ -19,10 +19,10 @@ package collector
import (
"fmt"
"golang.org/x/sys/unix"
"log/slog"
"net"
"strconv"
"github.com/go-kit/log"
"github.com/jsimonetti/rtnetlink"
"github.com/prometheus/client_golang/prometheus"
)
@ -30,7 +30,7 @@ import (
type networkRouteCollector struct {
routeInfoDesc *prometheus.Desc
routesDesc *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -38,7 +38,7 @@ func init() {
}
// NewNetworkRouteCollector returns a new Collector exposing systemd statistics.
func NewNetworkRouteCollector(logger log.Logger) (Collector, error) {
func NewNetworkRouteCollector(logger *slog.Logger) (Collector, error) {
const subsystem = "network"
routeInfoDesc := prometheus.NewDesc(

View file

@ -19,11 +19,10 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"reflect"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/nfs"
)
@ -40,7 +39,7 @@ type nfsCollector struct {
nfsRPCRetransmissionsDesc *prometheus.Desc
nfsRPCAuthenticationRefreshesDesc *prometheus.Desc
nfsProceduresDesc *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -48,7 +47,7 @@ func init() {
}
// NewNfsCollector returns a new Collector exposing NFS statistics.
func NewNfsCollector(logger log.Logger) (Collector, error) {
func NewNfsCollector(logger *slog.Logger) (Collector, error) {
fs, err := nfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)
@ -100,7 +99,7 @@ func (c *nfsCollector) Update(ch chan<- prometheus.Metric) error {
stats, err := c.fs.ClientRPCStats()
if err != nil {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "Not collecting NFS metrics", "err", err)
c.logger.Debug("Not collecting NFS metrics", "err", err)
return ErrNoData
}
return fmt.Errorf("failed to retrieve nfs stats: %w", err)

View file

@ -19,10 +19,9 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/nfs"
)
@ -32,7 +31,7 @@ import (
type nfsdCollector struct {
fs nfs.FS
requestsDesc *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -44,7 +43,7 @@ const (
)
// NewNFSdCollector returns a new Collector exposing /proc/net/rpc/nfsd statistics.
func NewNFSdCollector(logger log.Logger) (Collector, error) {
func NewNFSdCollector(logger *slog.Logger) (Collector, error) {
fs, err := nfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)
@ -66,7 +65,7 @@ func (c *nfsdCollector) Update(ch chan<- prometheus.Metric) error {
stats, err := c.fs.ServerRPCStats()
if err != nil {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "Not collecting NFSd metrics", "err", err)
c.logger.Debug("Not collecting NFSd metrics", "err", err)
return ErrNoData
}
return fmt.Errorf("failed to retrieve nfsd stats: %w", err)

View file

@ -18,14 +18,13 @@ package collector
import (
"fmt"
"log/slog"
"net"
"sync"
"time"
"github.com/alecthomas/kingpin/v2"
"github.com/beevik/ntp"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
@ -51,7 +50,7 @@ var (
type ntpCollector struct {
stratum, leap, rtt, offset, reftime, rootDelay, rootDispersion, sanity typedDesc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -62,7 +61,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(logger *slog.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")
@ -80,7 +79,7 @@ func NewNtpCollector(logger log.Logger) (Collector, error) {
return nil, fmt.Errorf("invalid NTP port number %d; must be between 1 and 65535 inclusive", *ntpServerPort)
}
level.Warn(logger).Log("msg", "This collector is deprecated and will be removed in the next major version release.")
logger.Warn("This collector is deprecated and will be removed in the next major version release.")
return &ntpCollector{
stratum: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, ntpSubsystem, "stratum"),

View file

@ -19,17 +19,16 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
)
type nvmeCollector struct {
fs sysfs.FS
logger log.Logger
logger *slog.Logger
}
func init() {
@ -37,7 +36,7 @@ func init() {
}
// NewNVMeCollector returns a new Collector exposing NVMe stats.
func NewNVMeCollector(logger log.Logger) (Collector, error) {
func NewNVMeCollector(logger *slog.Logger) (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)
@ -53,7 +52,7 @@ func (c *nvmeCollector) Update(ch chan<- prometheus.Metric) error {
devices, err := c.fs.NVMeClass()
if err != nil {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "nvme statistics not found, skipping")
c.logger.Debug("nvme statistics not found, skipping")
return ErrNoData
}
return fmt.Errorf("error obtaining NVMe class info: %w", err)

View file

@ -17,6 +17,7 @@ import (
"encoding/xml"
"errors"
"io"
"log/slog"
"os"
"regexp"
"strconv"
@ -24,8 +25,6 @@ import (
"sync"
"time"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
envparse "github.com/hashicorp/go-envparse"
"github.com/prometheus/client_golang/prometheus"
)
@ -58,7 +57,7 @@ type osRelease struct {
type osReleaseCollector struct {
infoDesc *prometheus.Desc
logger log.Logger
logger *slog.Logger
os *osRelease
osMutex sync.RWMutex
osReleaseFilenames []string // all os-release file names to check
@ -82,7 +81,7 @@ func init() {
}
// NewOSCollector returns a new Collector exposing os-release information.
func NewOSCollector(logger log.Logger) (Collector, error) {
func NewOSCollector(logger *slog.Logger) (Collector, error) {
return &osReleaseCollector{
logger: logger,
infoDesc: prometheus.NewDesc(
@ -178,7 +177,7 @@ func (c *osReleaseCollector) Update(ch chan<- prometheus.Metric) error {
}
if errors.Is(err, os.ErrNotExist) {
if i >= (len(c.osReleaseFilenames) - 1) {
level.Debug(c.logger).Log("msg", "no os-release file found", "files", strings.Join(c.osReleaseFilenames, ","))
c.logger.Debug("no os-release file found", "files", strings.Join(c.osReleaseFilenames, ","))
return ErrNoData
}
continue

View file

@ -14,12 +14,12 @@
package collector
import (
"io"
"log/slog"
"os"
"reflect"
"strings"
"testing"
"github.com/go-kit/log"
)
const debianBullseye string = `PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
@ -129,7 +129,7 @@ func TestUpdateStruct(t *testing.T) {
}
wantedVersion := 20.04
collector, err := NewOSCollector(log.NewNopLogger())
collector, err := NewOSCollector(slog.New(slog.NewTextHandler(io.Discard, nil)))
if err != nil {
t.Fatal(err)
}

View file

@ -18,13 +18,12 @@ package collector
import (
"fmt"
"log/slog"
"runtime"
"strconv"
"strings"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/hodgesds/perf-utils"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
@ -189,7 +188,7 @@ type perfCollector struct {
perfSwProfilers map[int]*perf.SoftwareProfiler
perfCacheProfilers map[int]*perf.CacheProfiler
desc map[string]*prometheus.Desc
logger log.Logger
logger *slog.Logger
tracepointCollector *perfTracepointCollector
}
@ -199,7 +198,7 @@ type perfTracepointCollector struct {
// collection order is the sorted configured collection order of the profiler.
collectionOrder []string
logger log.Logger
logger *slog.Logger
profilers map[int]perf.GroupProfiler
}
@ -218,7 +217,7 @@ func (c *perfTracepointCollector) updateCPU(cpu int, ch chan<- prometheus.Metric
profiler := c.profilers[cpu]
p := &perf.GroupProfileValue{}
if err := profiler.Profile(p); err != nil {
level.Error(c.logger).Log("msg", "Failed to collect tracepoint profile", "err", err)
c.logger.Error("Failed to collect tracepoint profile", "err", err)
return err
}
@ -240,7 +239,7 @@ func (c *perfTracepointCollector) updateCPU(cpu int, ch chan<- prometheus.Metric
// newPerfTracepointCollector returns a configured perfTracepointCollector.
func newPerfTracepointCollector(
logger log.Logger,
logger *slog.Logger,
tracepointsFlag []string,
cpus []int,
) (*perfTracepointCollector, error) {
@ -301,7 +300,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(logger *slog.Logger) (Collector, error) {
collector := &perfCollector{
perfHwProfilers: map[int]*perf.HardwareProfiler{},
perfSwProfilers: map[int]*perf.SoftwareProfiler{},

View file

@ -17,13 +17,14 @@
package collector
import (
"io"
"log/slog"
"os"
"runtime"
"strconv"
"strings"
"testing"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -44,7 +45,7 @@ func canTestPerf(t *testing.T) {
func TestPerfCollector(t *testing.T) {
canTestPerf(t)
collector, err := NewPerfCollector(log.NewNopLogger())
collector, err := NewPerfCollector(slog.New(slog.NewTextHandler(io.Discard, nil)))
if err != nil {
t.Fatal(err)
}
@ -97,7 +98,7 @@ func TestPerfCollectorStride(t *testing.T) {
}
}
perfCPUsFlag = &test.flag
collector, err := NewPerfCollector(log.NewNopLogger())
collector, err := NewPerfCollector(slog.New(slog.NewTextHandler(io.Discard, nil)))
if err != nil {
t.Fatal(err)
}

View file

@ -18,10 +18,10 @@
package collector
import (
"log/slog"
"regexp"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -33,14 +33,14 @@ type powerSupplyClassCollector struct {
subsystem string
ignoredPattern *regexp.Regexp
metricDescs map[string]*prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
registerCollector("powersupplyclass", defaultEnabled, NewPowerSupplyClassCollector)
}
func NewPowerSupplyClassCollector(logger log.Logger) (Collector, error) {
func NewPowerSupplyClassCollector(logger *slog.Logger) (Collector, error) {
pattern := regexp.MustCompile(*powerSupplyClassIgnoredPowerSupplies)
return &powerSupplyClassCollector{
subsystem: "power_supply",

View file

@ -183,6 +183,7 @@ import "C"
import (
"fmt"
"log/slog"
"strconv"
"github.com/prometheus/client_golang/prometheus"

View file

@ -19,11 +19,10 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"syscall"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)
@ -42,7 +41,7 @@ type pressureStatsCollector struct {
fs procfs.FS
logger log.Logger
logger *slog.Logger
}
func init() {
@ -50,7 +49,7 @@ func init() {
}
// NewPressureStatsCollector returns a Collector exposing pressure stall information
func NewPressureStatsCollector(logger log.Logger) (Collector, error) {
func NewPressureStatsCollector(logger *slog.Logger) (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)
@ -95,15 +94,15 @@ func NewPressureStatsCollector(logger log.Logger) (Collector, error) {
// Update calls procfs.NewPSIStatsForResource for the different resources and updates the values
func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error {
for _, res := range psiResources {
level.Debug(c.logger).Log("msg", "collecting statistics for resource", "resource", res)
c.logger.Debug("collecting statistics for resource", "resource", res)
vals, err := c.fs.PSIStatsForResource(res)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
level.Debug(c.logger).Log("msg", "pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel")
c.logger.Debug("pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel")
return ErrNoData
}
if errors.Is(err, syscall.ENOTSUP) {
level.Debug(c.logger).Log("msg", "pressure information is disabled, add psi=1 kernel command line to enable it")
c.logger.Debug("pressure information is disabled, add psi=1 kernel command line to enable it")
return ErrNoData
}
return fmt.Errorf("failed to retrieve pressure stats: %w", err)
@ -111,11 +110,11 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error {
// IRQ pressure does not have 'some' data.
// See https://github.com/torvalds/linux/blob/v6.9/include/linux/psi_types.h#L65
if vals.Some == nil && res != "irq" {
level.Debug(c.logger).Log("msg", "pressure information returned no 'some' data")
c.logger.Debug("pressure information returned no 'some' data")
return ErrNoData
}
if vals.Full == nil && res != "cpu" {
level.Debug(c.logger).Log("msg", "pressure information returned no 'full' data")
c.logger.Debug("pressure information returned no 'full' data")
return ErrNoData
}
switch res {
@ -130,7 +129,7 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error {
case "irq":
ch <- prometheus.MustNewConstMetric(c.irqFull, prometheus.CounterValue, float64(vals.Full.Total)/1000.0/1000.0)
default:
level.Debug(c.logger).Log("msg", "did not account for resource", "resource", res)
c.logger.Debug("did not account for resource", "resource", res)
}
}

View file

@ -19,14 +19,13 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"os"
"path"
"strconv"
"strings"
"syscall"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)
@ -39,7 +38,7 @@ type processCollector struct {
procsState *prometheus.Desc
pidUsed *prometheus.Desc
pidMax *prometheus.Desc
logger log.Logger
logger *slog.Logger
}
func init() {
@ -47,7 +46,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(logger *slog.Logger) (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)
@ -130,10 +129,10 @@ func (c *processCollector) getAllocatedThreads() (int, map[string]int32, int, ma
if err != nil {
// PIDs can vanish between getting the list and getting stats.
if c.isIgnoredError(err) {
level.Debug(c.logger).Log("msg", "file not found when retrieving stats for pid", "pid", pid.PID, "err", err)
c.logger.Debug("file not found when retrieving stats for pid", "pid", pid.PID, "err", err)
continue
}
level.Debug(c.logger).Log("msg", "error reading stat for pid", "pid", pid.PID, "err", err)
c.logger.Debug("error reading stat for pid", "pid", pid.PID, "err", err)
return 0, nil, 0, nil, fmt.Errorf("error reading stat for pid %d: %w", pid.PID, err)
}
pids++
@ -151,17 +150,17 @@ func (c *processCollector) getThreadStates(pid int, pidStat procfs.ProcStat, thr
fs, err := procfs.NewFS(procFilePath(path.Join(strconv.Itoa(pid), "task")))
if err != nil {
if c.isIgnoredError(err) {
level.Debug(c.logger).Log("msg", "file not found when retrieving tasks for pid", "pid", pid, "err", err)
c.logger.Debug("file not found when retrieving tasks for pid", "pid", pid, "err", err)
return nil
}
level.Debug(c.logger).Log("msg", "error reading tasks for pid", "pid", pid, "err", err)
c.logger.Debug("error reading tasks for pid", "pid", pid, "err", err)
return fmt.Errorf("error reading task for pid %d: %w", pid, err)
}
t, err := fs.AllProcs()
if err != nil {
if c.isIgnoredError(err) {
level.Debug(c.logger).Log("msg", "file not found when retrieving tasks for pid", "pid", pid, "err", err)
c.logger.Debug("file not found when retrieving tasks for pid", "pid", pid, "err", err)
return nil
}
return fmt.Errorf("unable to list all threads for pid: %d %w", pid, err)
@ -175,10 +174,10 @@ func (c *processCollector) getThreadStates(pid int, pidStat procfs.ProcStat, thr
threadStat, err := thread.Stat()
if err != nil {
if c.isIgnoredError(err) {
level.Debug(c.logger).Log("msg", "file not found when retrieving stats for thread", "pid", pid, "threadId", thread.PID, "err", err)
c.logger.Debug("file not found when retrieving stats for thread", "pid", pid, "threadId", thread.PID, "err", err)
continue
}
level.Debug(c.logger).Log("msg", "error reading stat for thread", "pid", pid, "threadId", thread.PID, "err", err)
c.logger.Debug("error reading stat for thread", "pid", pid, "threadId", thread.PID, "err", err)
return fmt.Errorf("error reading stat for pid:%d thread:%d err:%w", pid, thread.PID, err)
}
threadStates[threadStat.State]++

Some files were not shown because too many files have changed in this diff Show more