From 20892edbbf6e91181b1275822b9343edbfd5f816 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Thu, 29 Aug 2024 10:58:11 +0200 Subject: [PATCH] Update logging Switch from promlog/go-kit to promslog/slog for logging. Signed-off-by: Ben Kochie --- collector/arp_linux.go | 6 +-- collector/bcache_linux.go | 6 +-- collector/bonding_linux.go | 9 ++-- collector/bonding_linux_test.go | 1 + collector/boot_time_bsd.go | 6 +-- collector/boot_time_solaris.go | 6 +-- collector/btrfs_linux.go | 21 ++++----- collector/btrfs_linux_test.go | 1 + collector/buddyinfo.go | 9 ++-- collector/cgroups_linux.go | 6 +-- collector/collector.go | 21 ++++----- collector/conntrack_linux.go | 9 ++-- collector/cpu_darwin.go | 6 +-- collector/cpu_dragonfly.go | 6 +-- collector/cpu_dragonfly_test.go | 1 + collector/cpu_freebsd.go | 11 ++--- collector/cpu_linux.go | 43 +++++++++-------- collector/cpu_linux_test.go | 2 +- collector/cpu_netbsd.go | 9 ++-- collector/cpu_netbsd_test.go | 1 + collector/cpu_openbsd.go | 6 +-- collector/cpu_solaris.go | 6 +-- collector/cpu_vulnerabilities_linux.go | 4 +- collector/cpufreq_linux.go | 6 +-- collector/cpufreq_solaris.go | 6 +-- collector/device_filter_test.go | 1 + collector/devstat_dragonfly.go | 6 +-- collector/devstat_freebsd.go | 6 +-- collector/diskstats_common.go | 11 ++--- collector/diskstats_darwin.go | 6 +-- collector/diskstats_linux.go | 15 +++--- collector/diskstats_linux_test.go | 4 +- collector/diskstats_openbsd.go | 6 +-- collector/diskstats_openbsd_amd64.go | 6 +-- collector/dmi.go | 7 ++- collector/drbd_linux.go | 13 +++--- collector/drm_linux.go | 6 +-- collector/edac_linux.go | 6 +-- collector/entropy_linux.go | 6 +-- collector/ethtool_linux.go | 37 +++++++-------- collector/ethtool_linux_test.go | 6 +-- collector/exec_bsd.go | 6 +-- collector/fibrechannel_linux.go | 9 ++-- collector/filefd_linux.go | 6 +-- collector/filesystem_bsd.go | 7 ++- collector/filesystem_common.go | 15 +++--- collector/filesystem_freebsd.go | 8 ++-- collector/filesystem_linux.go | 21 ++++----- collector/filesystem_linux_test.go | 2 +- collector/filesystem_openbsd.go | 6 +-- collector/helper_test.go | 1 + collector/hwmon_linux.go | 13 +++--- collector/infiniband_linux.go | 9 ++-- collector/interrupts_common.go | 6 +-- collector/interrupts_linux.go | 5 +- collector/interrupts_linux_test.go | 1 + collector/interrupts_openbsd.go | 6 +-- collector/interrupts_openbsd_amd64.go | 6 +-- collector/ipvs_linux.go | 11 ++--- collector/ipvs_linux_test.go | 3 +- collector/ksmd_linux.go | 6 +-- collector/kvm_bsd.go | 1 + collector/lnstat_linux.go | 6 +-- collector/loadavg.go | 9 ++-- collector/loadavg_bsd.go | 1 + collector/loadavg_solaris.go | 1 + collector/logind_linux.go | 6 +-- collector/logind_linux_test.go | 1 + collector/mdadm_linux.go | 11 ++--- collector/meminfo.go | 3 +- collector/meminfo_darwin.go | 6 +-- collector/meminfo_linux.go | 6 +-- collector/meminfo_linux_test.go | 3 +- collector/meminfo_netbsd.go | 6 +-- collector/meminfo_numa_linux.go | 6 +-- collector/meminfo_numa_linux_test.go | 1 + collector/meminfo_openbsd.go | 7 ++- collector/meminfo_openbsd_amd64.go | 6 +-- collector/memory_bsd.go | 6 +-- collector/mountstats_linux.go | 9 ++-- collector/netclass_linux.go | 9 ++-- collector/netclass_rtnl_linux.go | 3 +- collector/netdev_bsd.go | 8 ++-- collector/netdev_common.go | 15 +++--- collector/netdev_darwin.go | 9 ++-- collector/netdev_linux.go | 19 ++++---- collector/netdev_linux_test.go | 3 +- collector/netdev_openbsd.go | 8 ++-- collector/netdev_openbsd_amd64.go | 7 ++- collector/netisr_freebsd.go | 6 +-- collector/netstat_linux.go | 6 +-- collector/netstat_linux_test.go | 1 + collector/network_route_linux.go | 6 +-- collector/nfs_linux.go | 9 ++-- collector/nfsd_linux.go | 9 ++-- collector/ntp.go | 9 ++-- collector/nvme_linux.go | 9 ++-- collector/os_release.go | 9 ++-- collector/os_release_test.go | 3 +- collector/paths_test.go | 1 + collector/perf_linux.go | 13 +++--- collector/perf_linux_test.go | 2 +- collector/powersupplyclass.go | 6 +-- collector/powersupplyclass_darwin.go | 1 + collector/pressure_linux.go | 19 ++++---- collector/processes_linux.go | 21 ++++----- collector/processes_linux_test.go | 2 +- collector/qdisc_linux.go | 11 ++--- collector/rapl_linux.go | 13 +++--- collector/runit.go | 13 +++--- collector/schedstat_linux.go | 9 ++-- collector/selinux_linux.go | 6 +-- collector/slabinfo_linux.go | 6 +-- collector/sockstat_linux.go | 11 ++--- collector/softirqs_common.go | 6 +-- collector/softnet_linux.go | 6 +-- collector/stat_linux.go | 6 +-- collector/supervisord.go | 11 ++--- collector/sysctl_bsd.go | 1 + collector/sysctl_linux.go | 6 +-- collector/sysctl_openbsd_amd64.go | 1 + collector/systemd_linux.go | 65 +++++++++++++------------- collector/systemd_linux_test.go | 2 +- collector/tapestats_linux.go | 11 ++--- collector/tcpstat_linux.go | 6 +-- collector/tcpstat_linux_test.go | 1 + collector/textfile.go | 17 ++++--- collector/textfile_test.go | 10 ++-- collector/thermal_darwin.go | 6 +-- collector/thermal_zone_linux.go | 9 ++-- collector/time.go | 11 ++--- collector/time_linux.go | 3 +- collector/time_other.go | 1 + collector/timex.go | 9 ++-- collector/udp_queues_linux.go | 11 ++--- collector/uname.go | 6 +-- collector/uname_bsd.go | 1 + collector/vmstat_linux.go | 6 +-- collector/watchdog.go | 9 ++-- collector/watchdog_test.go | 2 +- collector/wifi_linux.go | 17 ++++--- collector/xfrm.go | 6 +-- collector/xfrm_test.go | 2 +- collector/xfs_linux.go | 6 +-- collector/zfs.go | 11 ++--- collector/zfs_freebsd.go | 9 ++-- collector/zfs_linux.go | 11 ++--- collector/zfs_linux_test.go | 1 + collector/zfs_solaris.go | 6 +-- collector/zoneinfo_linux.go | 7 ++- go.mod | 15 +++--- go.sum | 24 ++++++---- node_exporter.go | 45 +++++++++--------- 153 files changed, 607 insertions(+), 650 deletions(-) diff --git a/collector/arp_linux.go b/collector/arp_linux.go index c7861156..c3c665b6 100644 --- a/collector/arp_linux.go +++ b/collector/arp_linux.go @@ -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) diff --git a/collector/bcache_linux.go b/collector/bcache_linux.go index 1d402d3f..f22bf75e 100644 --- a/collector/bcache_linux.go +++ b/collector/bcache_linux.go @@ -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) diff --git a/collector/bonding_linux.go b/collector/bonding_linux.go index d9d04e22..e237e6e6 100644 --- a/collector/bonding_linux.go +++ b/collector/bonding_linux.go @@ -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 diff --git a/collector/bonding_linux_test.go b/collector/bonding_linux_test.go index 98af73fa..0ad2421d 100644 --- a/collector/bonding_linux_test.go +++ b/collector/bonding_linux_test.go @@ -17,6 +17,7 @@ package collector import ( + "log/slog" "testing" ) diff --git a/collector/boot_time_bsd.go b/collector/boot_time_bsd.go index 8a9c17b3..90f7cdfa 100644 --- a/collector/boot_time_bsd.go +++ b/collector/boot_time_bsd.go @@ -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 diff --git a/collector/boot_time_solaris.go b/collector/boot_time_solaris.go index 15955121..9ec32d8d 100644 --- a/collector/boot_time_solaris.go +++ b/collector/boot_time_solaris.go @@ -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( diff --git a/collector/btrfs_linux.go b/collector/btrfs_linux.go index 1e5ef293..5c4c2955 100644 --- a/collector/btrfs_linux.go +++ b/collector/btrfs_linux.go @@ -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,7 +128,7 @@ 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( + c.logger.Debug( "msg", "Error inspecting btrfs mountpoint", "mountPoint", mountPath, "err", err) @@ -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 diff --git a/collector/btrfs_linux_test.go b/collector/btrfs_linux_test.go index c2ed57e5..2b4db30b 100644 --- a/collector/btrfs_linux_test.go +++ b/collector/btrfs_linux_test.go @@ -17,6 +17,7 @@ package collector import ( + "log/slog" "strings" "testing" diff --git a/collector/buddyinfo.go b/collector/buddyinfo.go index c3cc5e04..edcc4463 100644 --- a/collector/buddyinfo.go +++ b/collector/buddyinfo.go @@ -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( diff --git a/collector/cgroups_linux.go b/collector/cgroups_linux.go index 9f6d01a4..c938c12b 100644 --- a/collector/cgroups_linux.go +++ b/collector/cgroups_linux.go @@ -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) diff --git a/collector/collector.go b/collector/collector.go index 3112c789..31738759 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -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) diff --git a/collector/conntrack_linux.go b/collector/conntrack_linux.go index e4ea9549..052a183b 100644 --- a/collector/conntrack_linux.go +++ b/collector/conntrack_linux.go @@ -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) diff --git a/collector/cpu_darwin.go b/collector/cpu_darwin.go index 6c461cc3..d910cedc 100644 --- a/collector/cpu_darwin.go +++ b/collector/cpu_darwin.go @@ -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, diff --git a/collector/cpu_dragonfly.go b/collector/cpu_dragonfly.go index 61cba1ee..0b37a295 100644 --- a/collector/cpu_dragonfly.go +++ b/collector/cpu_dragonfly.go @@ -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, diff --git a/collector/cpu_dragonfly_test.go b/collector/cpu_dragonfly_test.go index 31f55c2e..0c79ade2 100644 --- a/collector/cpu_dragonfly_test.go +++ b/collector/cpu_dragonfly_test.go @@ -17,6 +17,7 @@ package collector import ( + "log/slog" "runtime" "testing" ) diff --git a/collector/cpu_freebsd.go b/collector/cpu_freebsd.go index 96b0f033..383a3016 100644 --- a/collector/cpu_freebsd.go +++ b/collector/cpu_freebsd.go @@ -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 } diff --git a/collector/cpu_linux.go b/collector/cpu_linux.go index 75d2a795..5df2c91e 100644 --- a/collector/cpu_linux.go +++ b/collector/cpu_linux.go @@ -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 diff --git a/collector/cpu_linux_test.go b/collector/cpu_linux_test.go index b148ffcd..5d20fa82 100644 --- a/collector/cpu_linux_test.go +++ b/collector/cpu_linux_test.go @@ -17,10 +17,10 @@ package collector import ( + "log/slog" "reflect" "testing" - "github.com/go-kit/log" "github.com/prometheus/procfs" ) diff --git a/collector/cpu_netbsd.go b/collector/cpu_netbsd.go index 7fc95c80..fe98d98e 100644 --- a/collector/cpu_netbsd.go +++ b/collector/cpu_netbsd.go @@ -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) } } diff --git a/collector/cpu_netbsd_test.go b/collector/cpu_netbsd_test.go index 08498d52..8658f640 100644 --- a/collector/cpu_netbsd_test.go +++ b/collector/cpu_netbsd_test.go @@ -17,6 +17,7 @@ package collector import ( + "log/slog" "runtime" "testing" ) diff --git a/collector/cpu_openbsd.go b/collector/cpu_openbsd.go index 8715ff98..01813ce8 100644 --- a/collector/cpu_openbsd.go +++ b/collector/cpu_openbsd.go @@ -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, diff --git a/collector/cpu_solaris.go b/collector/cpu_solaris.go index c7884542..16eaad83 100644 --- a/collector/cpu_solaris.go +++ b/collector/cpu_solaris.go @@ -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, diff --git a/collector/cpu_vulnerabilities_linux.go b/collector/cpu_vulnerabilities_linux.go index 69a2c587..88db118e 100644 --- a/collector/cpu_vulnerabilities_linux.go +++ b/collector/cpu_vulnerabilities_linux.go @@ -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 } diff --git a/collector/cpufreq_linux.go b/collector/cpufreq_linux.go index 3372be1a..b33fb8e7 100644 --- a/collector/cpufreq_linux.go +++ b/collector/cpufreq_linux.go @@ -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) diff --git a/collector/cpufreq_solaris.go b/collector/cpufreq_solaris.go index c3fb9ee6..d44c7e96 100644 --- a/collector/cpufreq_solaris.go +++ b/collector/cpufreq_solaris.go @@ -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 diff --git a/collector/device_filter_test.go b/collector/device_filter_test.go index 7332f1cd..87b7a070 100644 --- a/collector/device_filter_test.go +++ b/collector/device_filter_test.go @@ -14,6 +14,7 @@ package collector import ( + "log/slog" "testing" ) diff --git a/collector/devstat_dragonfly.go b/collector/devstat_dragonfly.go index 11678054..df40a5b9 100644 --- a/collector/devstat_dragonfly.go +++ b/collector/devstat_dragonfly.go @@ -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"), diff --git a/collector/devstat_freebsd.go b/collector/devstat_freebsd.go index 20cdc276..7209ad43 100644 --- a/collector/devstat_freebsd.go +++ b/collector/devstat_freebsd.go @@ -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( diff --git a/collector/diskstats_common.go b/collector/diskstats_common.go index 2ab84438..80f96912 100644 --- a/collector/diskstats_common.go +++ b/collector/diskstats_common.go @@ -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 diff --git a/collector/diskstats_darwin.go b/collector/diskstats_darwin.go index b5f6c538..6b90e15d 100644 --- a/collector/diskstats_darwin.go +++ b/collector/diskstats_darwin.go @@ -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) diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go index ed5d044a..933f1d02 100644 --- a/collector/diskstats_linux.go +++ b/collector/diskstats_linux.go @@ -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) } } } diff --git a/collector/diskstats_linux_test.go b/collector/diskstats_linux_test.go index 88d8c826..d6b2df08 100644 --- a/collector/diskstats_linux_test.go +++ b/collector/diskstats_linux_test.go @@ -18,11 +18,11 @@ package collector import ( "fmt" + "log/slog" "os" "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 diff --git a/collector/diskstats_openbsd.go b/collector/diskstats_openbsd.go index 2a69042a..a65a7f4c 100644 --- a/collector/diskstats_openbsd.go +++ b/collector/diskstats_openbsd.go @@ -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) diff --git a/collector/diskstats_openbsd_amd64.go b/collector/diskstats_openbsd_amd64.go index a39cabb5..bf1ca6a4 100644 --- a/collector/diskstats_openbsd_amd64.go +++ b/collector/diskstats_openbsd_amd64.go @@ -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) diff --git a/collector/dmi.go b/collector/dmi.go index 79475507..309eda3a 100644 --- a/collector/dmi.go +++ b/collector/dmi.go @@ -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) diff --git a/collector/drbd_linux.go b/collector/drbd_linux.go index f192a24c..6c7a6ca1 100644 --- a/collector/drbd_linux.go +++ b/collector/drbd_linux.go @@ -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() diff --git a/collector/drm_linux.go b/collector/drm_linux.go index 11b8c628..7e207891 100644 --- a/collector/drm_linux.go +++ b/collector/drm_linux.go @@ -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) diff --git a/collector/edac_linux.go b/collector/edac_linux.go index c7719b7a..4bf5669a 100644 --- a/collector/edac_linux.go +++ b/collector/edac_linux.go @@ -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"), diff --git a/collector/entropy_linux.go b/collector/entropy_linux.go index 909d2ff4..61e6f67b 100644 --- a/collector/entropy_linux.go +++ b/collector/entropy_linux.go @@ -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) diff --git a/collector/ethtool_linux.go b/collector/ethtool_linux.go index 45c35851..c429d752 100644 --- a/collector/ethtool_linux.go +++ b/collector/ethtool_linux.go @@ -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] = "" diff --git a/collector/ethtool_linux_test.go b/collector/ethtool_linux_test.go index ae7df0dd..cc5efa78 100644 --- a/collector/ethtool_linux_test.go +++ b/collector/ethtool_linux_test.go @@ -19,6 +19,7 @@ package collector import ( "bufio" "fmt" + "log/slog" "os" "path/filepath" "strconv" @@ -26,7 +27,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 +49,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 +255,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 diff --git a/collector/exec_bsd.go b/collector/exec_bsd.go index 87cb3cee..98ede8bf 100644 --- a/collector/exec_bsd.go +++ b/collector/exec_bsd.go @@ -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. // diff --git a/collector/fibrechannel_linux.go b/collector/fibrechannel_linux.go index 782ad33e..52504088 100644 --- a/collector/fibrechannel_linux.go +++ b/collector/fibrechannel_linux.go @@ -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) diff --git a/collector/filefd_linux.go b/collector/filefd_linux.go index 55069d6c..48e38064 100644 --- a/collector/filefd_linux.go +++ b/collector/filefd_linux.go @@ -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 } diff --git a/collector/filesystem_bsd.go b/collector/filesystem_bsd.go index d3025a01..8adaad11 100644 --- a/collector/filesystem_bsd.go +++ b/collector/filesystem_bsd.go @@ -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 } diff --git a/collector/filesystem_common.go b/collector/filesystem_common.go index d224e2c2..926cc594 100644 --- a/collector/filesystem_common.go +++ b/collector/filesystem_common.go @@ -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( diff --git a/collector/filesystem_freebsd.go b/collector/filesystem_freebsd.go index f05702d1..fc063b3f 100644 --- a/collector/filesystem_freebsd.go +++ b/collector/filesystem_freebsd.go @@ -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 } diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index 728e8cca..ee3f5607 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -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 { diff --git a/collector/filesystem_linux_test.go b/collector/filesystem_linux_test.go index e2938552..f2933613 100644 --- a/collector/filesystem_linux_test.go +++ b/collector/filesystem_linux_test.go @@ -17,11 +17,11 @@ package collector import ( + "log/slog" "strings" "testing" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" ) func Test_parseFilesystemLabelsError(t *testing.T) { diff --git a/collector/filesystem_openbsd.go b/collector/filesystem_openbsd.go index 1c1e479e..c081d479 100644 --- a/collector/filesystem_openbsd.go +++ b/collector/filesystem_openbsd.go @@ -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 } diff --git a/collector/helper_test.go b/collector/helper_test.go index 9c1296ed..269388ff 100644 --- a/collector/helper_test.go +++ b/collector/helper_test.go @@ -14,6 +14,7 @@ package collector import ( + "log/slog" "testing" ) diff --git a/collector/hwmon_linux.go b/collector/hwmon_linux.go index ed46f0f8..d5206fb3 100644 --- a/collector/hwmon_linux.go +++ b/collector/hwmon_linux.go @@ -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 } diff --git a/collector/infiniband_linux.go b/collector/infiniband_linux.go index b0928da3..e7d3262b 100644 --- a/collector/infiniband_linux.go +++ b/collector/infiniband_linux.go @@ -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) diff --git a/collector/interrupts_common.go b/collector/interrupts_common.go index a0996e91..555c43ea 100644 --- a/collector/interrupts_common.go +++ b/collector/interrupts_common.go @@ -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", diff --git a/collector/interrupts_linux.go b/collector/interrupts_linux.go index 3d3bd037..77caf423 100644 --- a/collector/interrupts_linux.go +++ b/collector/interrupts_linux.go @@ -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) diff --git a/collector/interrupts_linux_test.go b/collector/interrupts_linux_test.go index 82e536e4..d3b91549 100644 --- a/collector/interrupts_linux_test.go +++ b/collector/interrupts_linux_test.go @@ -17,6 +17,7 @@ package collector import ( + "log/slog" "os" "testing" ) diff --git a/collector/interrupts_openbsd.go b/collector/interrupts_openbsd.go index 049f6407..fc485c08 100644 --- a/collector/interrupts_openbsd.go +++ b/collector/interrupts_openbsd.go @@ -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( diff --git a/collector/interrupts_openbsd_amd64.go b/collector/interrupts_openbsd_amd64.go index 4ce4edfd..ef9b5cd7 100644 --- a/collector/interrupts_openbsd_amd64.go +++ b/collector/interrupts_openbsd_amd64.go @@ -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( diff --git a/collector/ipvs_linux.go b/collector/ipvs_linux.go index 63a3a1a8..4e6598e8 100644 --- a/collector/ipvs_linux.go +++ b/collector/ipvs_linux.go @@ -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) diff --git a/collector/ipvs_linux_test.go b/collector/ipvs_linux_test.go index 6ee41b29..34077f9c 100644 --- a/collector/ipvs_linux_test.go +++ b/collector/ipvs_linux_test.go @@ -19,14 +19,13 @@ package collector import ( "errors" "fmt" + "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" diff --git a/collector/ksmd_linux.go b/collector/ksmd_linux.go index 6d4142ae..8422ca22 100644 --- a/collector/ksmd_linux.go +++ b/collector/ksmd_linux.go @@ -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) diff --git a/collector/kvm_bsd.go b/collector/kvm_bsd.go index c4a4479a..c56d9504 100644 --- a/collector/kvm_bsd.go +++ b/collector/kvm_bsd.go @@ -19,6 +19,7 @@ package collector import ( "fmt" + "log/slog" "sync" ) diff --git a/collector/lnstat_linux.go b/collector/lnstat_linux.go index b3c90dc0..1a020371 100644 --- a/collector/lnstat_linux.go +++ b/collector/lnstat_linux.go @@ -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 } diff --git a/collector/loadavg.go b/collector/loadavg.go index cb7b2cb1..9a503dfa 100644 --- a/collector/loadavg.go +++ b/collector/loadavg.go @@ -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 diff --git a/collector/loadavg_bsd.go b/collector/loadavg_bsd.go index a1f5ae66..b8d653cd 100644 --- a/collector/loadavg_bsd.go +++ b/collector/loadavg_bsd.go @@ -18,6 +18,7 @@ package collector import ( + "log/slog" "unsafe" "golang.org/x/sys/unix" diff --git a/collector/loadavg_solaris.go b/collector/loadavg_solaris.go index 316233fa..a45afc45 100644 --- a/collector/loadavg_solaris.go +++ b/collector/loadavg_solaris.go @@ -18,6 +18,7 @@ package collector import ( "fmt" + "log/slog" "strconv" "github.com/illumos/go-kstat" diff --git a/collector/logind_linux.go b/collector/logind_linux.go index de5b0d18..b111cdf1 100644 --- a/collector/logind_linux.go +++ b/collector/logind_linux.go @@ -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 } diff --git a/collector/logind_linux_test.go b/collector/logind_linux_test.go index 5cfedff4..18a63da8 100644 --- a/collector/logind_linux_test.go +++ b/collector/logind_linux_test.go @@ -17,6 +17,7 @@ package collector import ( + "log/slog" "testing" "github.com/godbus/dbus/v5" diff --git a/collector/mdadm_linux.go b/collector/mdadm_linux.go index 89c56b75..a695145b 100644 --- a/collector/mdadm_linux.go +++ b/collector/mdadm_linux.go @@ -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 diff --git a/collector/meminfo.go b/collector/meminfo.go index 0a6390d8..55e13604 100644 --- a/collector/meminfo.go +++ b/collector/meminfo.go @@ -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 diff --git a/collector/meminfo_darwin.go b/collector/meminfo_darwin.go index 21316fb5..27ea14d3 100644 --- a/collector/meminfo_darwin.go +++ b/collector/meminfo_darwin.go @@ -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 diff --git a/collector/meminfo_linux.go b/collector/meminfo_linux.go index 40e06990..c7532127 100644 --- a/collector/meminfo_linux.go +++ b/collector/meminfo_linux.go @@ -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) diff --git a/collector/meminfo_linux_test.go b/collector/meminfo_linux_test.go index 523426d0..a42854b3 100644 --- a/collector/meminfo_linux_test.go +++ b/collector/meminfo_linux_test.go @@ -17,10 +17,9 @@ package collector import ( + "log/slog" "os" "testing" - - "github.com/go-kit/log" ) func TestMemInfo(t *testing.T) { diff --git a/collector/meminfo_netbsd.go b/collector/meminfo_netbsd.go index f8b131e5..e1123ff3 100644 --- a/collector/meminfo_netbsd.go +++ b/collector/meminfo_netbsd.go @@ -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 diff --git a/collector/meminfo_numa_linux.go b/collector/meminfo_numa_linux.go index 5ce08e99..6ffdb4f7 100644 --- a/collector/meminfo_numa_linux.go +++ b/collector/meminfo_numa_linux.go @@ -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, diff --git a/collector/meminfo_numa_linux_test.go b/collector/meminfo_numa_linux_test.go index 33bc362e..65eac050 100644 --- a/collector/meminfo_numa_linux_test.go +++ b/collector/meminfo_numa_linux_test.go @@ -17,6 +17,7 @@ package collector import ( + "log/slog" "os" "testing" ) diff --git a/collector/meminfo_openbsd.go b/collector/meminfo_openbsd.go index 4a4682a3..296992a7 100644 --- a/collector/meminfo_openbsd.go +++ b/collector/meminfo_openbsd.go @@ -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 diff --git a/collector/meminfo_openbsd_amd64.go b/collector/meminfo_openbsd_amd64.go index 2f81c79e..1c8d637f 100644 --- a/collector/meminfo_openbsd_amd64.go +++ b/collector/meminfo_openbsd_amd64.go @@ -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 diff --git a/collector/memory_bsd.go b/collector/memory_bsd.go index 6af9d8aa..cb499750 100644 --- a/collector/memory_bsd.go +++ b/collector/memory_bsd.go @@ -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) diff --git a/collector/mountstats_linux.go b/collector/mountstats_linux.go index cdd84ea1..a71478fc 100644 --- a/collector/mountstats_linux.go +++ b/collector/mountstats_linux.go @@ -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 diff --git a/collector/netclass_linux.go b/collector/netclass_linux.go index 327c89aa..d59a2530 100644 --- a/collector/netclass_linux.go +++ b/collector/netclass_linux.go @@ -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) diff --git a/collector/netclass_rtnl_linux.go b/collector/netclass_rtnl_linux.go index ef963715..96feb8bc 100644 --- a/collector/netclass_rtnl_linux.go +++ b/collector/netclass_rtnl_linux.go @@ -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) { diff --git a/collector/netdev_bsd.go b/collector/netdev_bsd.go index 691bbec4..d379a0f4 100644 --- a/collector/netdev_bsd.go +++ b/collector/netdev_bsd.go @@ -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 } diff --git a/collector/netdev_common.go b/collector/netdev_common.go index 089f1e58..411dc0a3 100644 --- a/collector/netdev_common.go +++ b/collector/netdev_common.go @@ -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{ diff --git a/collector/netdev_darwin.go b/collector/netdev_darwin.go index c08f1f8e..444ff3a4 100644 --- a/collector/netdev_darwin.go +++ b/collector/netdev_darwin.go @@ -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 } diff --git a/collector/netdev_linux.go b/collector/netdev_linux.go index f3348cda..0893dcd6 100644 --- a/collector/netdev_linux.go +++ b/collector/netdev_linux.go @@ -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 } diff --git a/collector/netdev_linux_test.go b/collector/netdev_linux_test.go index 7909d018..445e35f3 100644 --- a/collector/netdev_linux_test.go +++ b/collector/netdev_linux_test.go @@ -17,10 +17,9 @@ package collector import ( + "log/slog" "testing" - "github.com/go-kit/log" - "github.com/jsimonetti/rtnetlink" ) diff --git a/collector/netdev_openbsd.go b/collector/netdev_openbsd.go index b90e3ba7..1cb87899 100644 --- a/collector/netdev_openbsd.go +++ b/collector/netdev_openbsd.go @@ -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 } diff --git a/collector/netdev_openbsd_amd64.go b/collector/netdev_openbsd_amd64.go index da8a81f3..fd8326e9 100644 --- a/collector/netdev_openbsd_amd64.go +++ b/collector/netdev_openbsd_amd64.go @@ -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 } diff --git a/collector/netisr_freebsd.go b/collector/netisr_freebsd.go index 442bcdc6..8c7cc6e5 100644 --- a/collector/netisr_freebsd.go +++ b/collector/netisr_freebsd.go @@ -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{ { diff --git a/collector/netstat_linux.go b/collector/netstat_linux.go index afbf8d58..9e054d79 100644 --- a/collector/netstat_linux.go +++ b/collector/netstat_linux.go @@ -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, diff --git a/collector/netstat_linux_test.go b/collector/netstat_linux_test.go index ec430bc3..85690d80 100644 --- a/collector/netstat_linux_test.go +++ b/collector/netstat_linux_test.go @@ -17,6 +17,7 @@ package collector import ( + "log/slog" "os" "testing" ) diff --git a/collector/network_route_linux.go b/collector/network_route_linux.go index c77e1751..7c2f930c 100644 --- a/collector/network_route_linux.go +++ b/collector/network_route_linux.go @@ -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( diff --git a/collector/nfs_linux.go b/collector/nfs_linux.go index e08acdba..41085fd5 100644 --- a/collector/nfs_linux.go +++ b/collector/nfs_linux.go @@ -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) diff --git a/collector/nfsd_linux.go b/collector/nfsd_linux.go index 8b310ea2..34af2519 100644 --- a/collector/nfsd_linux.go +++ b/collector/nfsd_linux.go @@ -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) diff --git a/collector/ntp.go b/collector/ntp.go index 8b8db8a9..825c47f0 100644 --- a/collector/ntp.go +++ b/collector/ntp.go @@ -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"), diff --git a/collector/nvme_linux.go b/collector/nvme_linux.go index 81d4ab29..df7d9bd3 100644 --- a/collector/nvme_linux.go +++ b/collector/nvme_linux.go @@ -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) diff --git a/collector/os_release.go b/collector/os_release.go index 4c86740e..122d316a 100644 --- a/collector/os_release.go +++ b/collector/os_release.go @@ -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 diff --git a/collector/os_release_test.go b/collector/os_release_test.go index b45ee0ed..2a57269c 100644 --- a/collector/os_release_test.go +++ b/collector/os_release_test.go @@ -14,12 +14,11 @@ package collector import ( + "log/slog" "os" "reflect" "strings" "testing" - - "github.com/go-kit/log" ) const debianBullseye string = `PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" diff --git a/collector/paths_test.go b/collector/paths_test.go index 9426fa4b..9e065d2f 100644 --- a/collector/paths_test.go +++ b/collector/paths_test.go @@ -14,6 +14,7 @@ package collector import ( + "log/slog" "testing" "github.com/alecthomas/kingpin/v2" diff --git a/collector/perf_linux.go b/collector/perf_linux.go index 8934371a..4199ac11 100644 --- a/collector/perf_linux.go +++ b/collector/perf_linux.go @@ -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{}, diff --git a/collector/perf_linux_test.go b/collector/perf_linux_test.go index fc557ffd..3f1d7494 100644 --- a/collector/perf_linux_test.go +++ b/collector/perf_linux_test.go @@ -17,13 +17,13 @@ package collector import ( + "log/slog" "os" "runtime" "strconv" "strings" "testing" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) diff --git a/collector/powersupplyclass.go b/collector/powersupplyclass.go index 7f231dac..2d5ee9f5 100644 --- a/collector/powersupplyclass.go +++ b/collector/powersupplyclass.go @@ -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", diff --git a/collector/powersupplyclass_darwin.go b/collector/powersupplyclass_darwin.go index 01d7f184..b08b09d8 100644 --- a/collector/powersupplyclass_darwin.go +++ b/collector/powersupplyclass_darwin.go @@ -183,6 +183,7 @@ import "C" import ( "fmt" + "log/slog" "strconv" "github.com/prometheus/client_golang/prometheus" diff --git a/collector/pressure_linux.go b/collector/pressure_linux.go index 36e06505..c0b1207b 100644 --- a/collector/pressure_linux.go +++ b/collector/pressure_linux.go @@ -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) } } diff --git a/collector/processes_linux.go b/collector/processes_linux.go index 798aeaeb..1b3a2d3d 100644 --- a/collector/processes_linux.go +++ b/collector/processes_linux.go @@ -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]++ diff --git a/collector/processes_linux_test.go b/collector/processes_linux_test.go index e2814a01..8c992d90 100644 --- a/collector/processes_linux_test.go +++ b/collector/processes_linux_test.go @@ -17,10 +17,10 @@ package collector import ( + "log/slog" "testing" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/procfs" ) diff --git a/collector/qdisc_linux.go b/collector/qdisc_linux.go index 06ab6a88..ff7f7483 100644 --- a/collector/qdisc_linux.go +++ b/collector/qdisc_linux.go @@ -19,18 +19,17 @@ package collector import ( "encoding/json" "fmt" + "log/slog" "os" "path/filepath" "github.com/alecthomas/kingpin/v2" "github.com/ema/qdisc" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) type qdiscStatCollector struct { - logger log.Logger + logger slog.Logger deviceFilter deviceFilter bytes typedDesc packets typedDesc @@ -54,10 +53,10 @@ func init() { } // NewQdiscStatCollector returns a new Collector exposing queuing discipline statistics. -func NewQdiscStatCollector(logger log.Logger) (Collector, error) { +func NewQdiscStatCollector(logger slog.Logger) (Collector, error) { if *oldCollectorQdiskDeviceInclude != "" { if *collectorQdiscDeviceInclude == "" { - level.Warn(logger).Log("msg", "--collector.qdisk.device-include is DEPRECATED and will be removed in 2.0.0, use --collector.qdisc.device-include") + logger.Warn("--collector.qdisk.device-include is DEPRECATED and will be removed in 2.0.0, use --collector.qdisc.device-include") *collectorQdiscDeviceInclude = *oldCollectorQdiskDeviceInclude } else { return nil, fmt.Errorf("--collector.qdisk.device-include and --collector.qdisc.device-include are mutually exclusive") @@ -66,7 +65,7 @@ func NewQdiscStatCollector(logger log.Logger) (Collector, error) { if *oldCollectorQdiskDeviceExclude != "" { if *collectorQdiscDeviceExclude == "" { - level.Warn(logger).Log("msg", "--collector.qdisk.device-exclude is DEPRECATED and will be removed in 2.0.0, use --collector.qdisc.device-exclude") + logger.Warn("--collector.qdisk.device-exclude is DEPRECATED and will be removed in 2.0.0, use --collector.qdisc.device-exclude") *collectorQdiscDeviceExclude = *oldCollectorQdiskDeviceExclude } else { return nil, fmt.Errorf("--collector.qdisk.device-exclude and --collector.qdisc.device-exclude are mutually exclusive") diff --git a/collector/rapl_linux.go b/collector/rapl_linux.go index 642de6c1..43b2f968 100644 --- a/collector/rapl_linux.go +++ b/collector/rapl_linux.go @@ -19,12 +19,11 @@ package collector import ( "errors" "fmt" + "log/slog" "os" "strconv" "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" ) @@ -33,7 +32,7 @@ const raplCollectorSubsystem = "rapl" type raplCollector struct { fs sysfs.FS - logger log.Logger + logger slog.Logger joulesMetricDesc *prometheus.Desc } @@ -47,7 +46,7 @@ var ( ) // NewRaplCollector returns a new Collector exposing RAPL metrics. -func NewRaplCollector(logger log.Logger) (Collector, error) { +func NewRaplCollector(logger slog.Logger) (Collector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { @@ -74,11 +73,11 @@ func (c *raplCollector) Update(ch chan<- prometheus.Metric) error { zones, err := sysfs.GetRaplZones(c.fs) if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "Platform doesn't have powercap files present", "err", err) + c.logger.Debug("Platform doesn't have powercap files present", "err", err) return ErrNoData } if errors.Is(err, os.ErrPermission) { - level.Debug(c.logger).Log("msg", "Can't access powercap files", "err", err) + c.logger.Debug("Can't access powercap files", "err", err) return ErrNoData } return fmt.Errorf("failed to retrieve rapl stats: %w", err) @@ -88,7 +87,7 @@ func (c *raplCollector) Update(ch chan<- prometheus.Metric) error { microJoules, err := rz.GetEnergyMicrojoules() if err != nil { if errors.Is(err, os.ErrPermission) { - level.Debug(c.logger).Log("msg", "Can't access energy_uj file", "zone", rz, "err", err) + c.logger.Debug("Can't access energy_uj file", "zone", rz, "err", err) return ErrNoData } return err diff --git a/collector/runit.go b/collector/runit.go index 3cae657c..609a600e 100644 --- a/collector/runit.go +++ b/collector/runit.go @@ -18,10 +18,9 @@ package collector import ( "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus-community/go-runit/runit" "github.com/prometheus/client_golang/prometheus" + "log/slog" ) var runitServiceDir = kingpin.Flag("collector.runit.servicedir", "Path to runit service directory.").Default("/etc/service").String() @@ -31,7 +30,7 @@ type runitCollector struct { stateDesired typedDesc stateNormal typedDesc stateTimestamp typedDesc - logger log.Logger + logger slog.Logger } func init() { @@ -39,14 +38,14 @@ func init() { } // NewRunitCollector returns a new Collector exposing runit statistics. -func NewRunitCollector(logger log.Logger) (Collector, error) { +func NewRunitCollector(logger slog.Logger) (Collector, error) { var ( subsystem = "service" constLabels = prometheus.Labels{"supervisor": "runit"} labelNames = []string{"service"} ) - 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 &runitCollector{ state: typedDesc{prometheus.NewDesc( @@ -82,11 +81,11 @@ func (c *runitCollector) Update(ch chan<- prometheus.Metric) error { for _, service := range services { status, err := service.Status() if err != nil { - level.Debug(c.logger).Log("msg", "Couldn't get status", "service", service.Name, "err", err) + c.logger.Debug("Couldn't get status", "service", service.Name, "err", err) continue } - level.Debug(c.logger).Log("msg", "duration", "service", service.Name, "status", status.State, "pid", status.Pid, "duration_seconds", status.Duration) + c.logger.Debug("duration", "service", service.Name, "status", status.State, "pid", status.Pid, "duration_seconds", status.Duration) ch <- c.state.mustNewConstMetric(float64(status.State), service.Name) ch <- c.stateDesired.mustNewConstMetric(float64(status.Want), service.Name) ch <- c.stateTimestamp.mustNewConstMetric(float64(status.Timestamp.Unix()), service.Name) diff --git a/collector/schedstat_linux.go b/collector/schedstat_linux.go index e5016561..c01add80 100644 --- a/collector/schedstat_linux.go +++ b/collector/schedstat_linux.go @@ -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" ) @@ -53,7 +52,7 @@ var ( ) // NewSchedstatCollector returns a new Collector exposing task scheduler statistics -func NewSchedstatCollector(logger log.Logger) (Collector, error) { +func NewSchedstatCollector(logger slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -64,7 +63,7 @@ func NewSchedstatCollector(logger log.Logger) (Collector, error) { type schedstatCollector struct { fs procfs.FS - logger log.Logger + logger slog.Logger } func init() { @@ -75,7 +74,7 @@ func (c *schedstatCollector) Update(ch chan<- prometheus.Metric) error { stats, err := c.fs.Schedstat() if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "schedstat file does not exist") + c.logger.Debug("schedstat file does not exist") return ErrNoData } return err diff --git a/collector/selinux_linux.go b/collector/selinux_linux.go index 79316362..89fa8c35 100644 --- a/collector/selinux_linux.go +++ b/collector/selinux_linux.go @@ -17,16 +17,16 @@ package collector import ( - "github.com/go-kit/log" "github.com/opencontainers/selinux/go-selinux" "github.com/prometheus/client_golang/prometheus" + "log/slog" ) type selinuxCollector struct { configMode *prometheus.Desc currentMode *prometheus.Desc enabled *prometheus.Desc - logger log.Logger + logger slog.Logger } func init() { @@ -34,7 +34,7 @@ func init() { } // NewSelinuxCollector returns a new Collector exposing SELinux statistics. -func NewSelinuxCollector(logger log.Logger) (Collector, error) { +func NewSelinuxCollector(logger slog.Logger) (Collector, error) { const subsystem = "selinux" return &selinuxCollector{ diff --git a/collector/slabinfo_linux.go b/collector/slabinfo_linux.go index 70241a08..0f2be407 100644 --- a/collector/slabinfo_linux.go +++ b/collector/slabinfo_linux.go @@ -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" ) @@ -32,7 +32,7 @@ var ( type slabinfoCollector struct { fs procfs.FS - logger log.Logger + logger slog.Logger subsystem string labels []string slabNameFilter deviceFilter @@ -42,7 +42,7 @@ func init() { registerCollector("slabinfo", defaultDisabled, NewSlabinfoCollector) } -func NewSlabinfoCollector(logger log.Logger) (Collector, error) { +func NewSlabinfoCollector(logger slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/sockstat_linux.go b/collector/sockstat_linux.go index 480c83b1..fdf55ca5 100644 --- a/collector/sockstat_linux.go +++ b/collector/sockstat_linux.go @@ -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" ) @@ -35,7 +34,7 @@ const ( var pageSize = os.Getpagesize() type sockStatCollector struct { - logger log.Logger + logger slog.Logger } func init() { @@ -43,7 +42,7 @@ func init() { } // NewSockStatCollector returns a new Collector exposing socket stats. -func NewSockStatCollector(logger log.Logger) (Collector, error) { +func NewSockStatCollector(logger slog.Logger) (Collector, error) { return &sockStatCollector{logger}, nil } @@ -58,7 +57,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { switch { case err == nil: case errors.Is(err, os.ErrNotExist): - level.Debug(c.logger).Log("msg", "IPv4 sockstat statistics not found, skipping") + c.logger.Debug("IPv4 sockstat statistics not found, skipping") default: return fmt.Errorf("failed to get IPv4 sockstat data: %w", err) } @@ -67,7 +66,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { switch { case err == nil: case errors.Is(err, os.ErrNotExist): - level.Debug(c.logger).Log("msg", "IPv6 sockstat statistics not found, skipping") + c.logger.Debug("IPv6 sockstat statistics not found, skipping") default: return fmt.Errorf("failed to get IPv6 sockstat data: %w", err) } diff --git a/collector/softirqs_common.go b/collector/softirqs_common.go index 08ef780f..d7fbe61f 100644 --- a/collector/softirqs_common.go +++ b/collector/softirqs_common.go @@ -18,15 +18,15 @@ package collector import ( "fmt" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" + "log/slog" ) type softirqsCollector struct { fs procfs.FS desc typedDesc - logger log.Logger + logger slog.Logger } func init() { @@ -34,7 +34,7 @@ func init() { } // NewSoftirqsCollector returns a new Collector exposing softirq stats. -func NewSoftirqsCollector(logger log.Logger) (Collector, error) { +func NewSoftirqsCollector(logger slog.Logger) (Collector, error) { desc := typedDesc{prometheus.NewDesc( namespace+"_softirqs_functions_total", "Softirq counts per CPU.", diff --git a/collector/softnet_linux.go b/collector/softnet_linux.go index 42d47780..5675e60e 100644 --- a/collector/softnet_linux.go +++ b/collector/softnet_linux.go @@ -18,9 +18,9 @@ package collector import ( "fmt" + "log/slog" "strconv" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -34,7 +34,7 @@ type softnetCollector struct { receivedRps *prometheus.Desc flowLimitCount *prometheus.Desc softnetBacklogLen *prometheus.Desc - logger log.Logger + logger slog.Logger } const ( @@ -46,7 +46,7 @@ func init() { } // NewSoftnetCollector returns a new Collector exposing softnet metrics. -func NewSoftnetCollector(logger log.Logger) (Collector, error) { +func NewSoftnetCollector(logger slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/stat_linux.go b/collector/stat_linux.go index 9974ae7a..f07d87c2 100644 --- a/collector/stat_linux.go +++ b/collector/stat_linux.go @@ -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" ) @@ -34,7 +34,7 @@ type statCollector struct { procsRunning *prometheus.Desc procsBlocked *prometheus.Desc softIRQ *prometheus.Desc - logger log.Logger + logger slog.Logger } var statSoftirqFlag = kingpin.Flag("collector.stat.softirq", "Export softirq calls per vector").Default("false").Bool() @@ -44,7 +44,7 @@ func init() { } // NewStatCollector returns a new Collector exposing kernel/system statistics. -func NewStatCollector(logger log.Logger) (Collector, error) { +func NewStatCollector(logger slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/supervisord.go b/collector/supervisord.go index 9b517f0a..20b30823 100644 --- a/collector/supervisord.go +++ b/collector/supervisord.go @@ -19,14 +19,13 @@ package collector import ( "context" "fmt" + "log/slog" "net" "net/http" "net/url" "time" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/mattn/go-xmlrpc" "github.com/prometheus/client_golang/prometheus" ) @@ -41,7 +40,7 @@ type supervisordCollector struct { stateDesc *prometheus.Desc exitStatusDesc *prometheus.Desc startTimeDesc *prometheus.Desc - logger log.Logger + logger slog.Logger } func init() { @@ -49,7 +48,7 @@ func init() { } // NewSupervisordCollector returns a new Collector exposing supervisord statistics. -func NewSupervisordCollector(logger log.Logger) (Collector, error) { +func NewSupervisordCollector(logger slog.Logger) (Collector, error) { var ( subsystem = "supervisord" labelNames = []string{"name", "group"} @@ -69,7 +68,7 @@ func NewSupervisordCollector(logger log.Logger) (Collector, error) { xrpc = xmlrpc.NewClient(*supervisordURL) } - 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 &supervisordCollector{ upDesc: prometheus.NewDesc( @@ -174,7 +173,7 @@ func (c *supervisordCollector) Update(ch chan<- prometheus.Metric) error { } else { ch <- prometheus.MustNewConstMetric(c.upDesc, prometheus.GaugeValue, 0, labels...) } - level.Debug(c.logger).Log("msg", "process info", "group", info.Group, "name", info.Name, "state", info.StateName, "pid", info.PID) + c.logger.Debug("process info", "group", info.Group, "name", info.Name, "state", info.StateName, "pid", info.PID) } return nil diff --git a/collector/sysctl_bsd.go b/collector/sysctl_bsd.go index 2ab248ed..5e431738 100644 --- a/collector/sysctl_bsd.go +++ b/collector/sysctl_bsd.go @@ -19,6 +19,7 @@ package collector import ( "fmt" + "log/slog" "unsafe" "github.com/prometheus/client_golang/prometheus" diff --git a/collector/sysctl_linux.go b/collector/sysctl_linux.go index c14341db..86268162 100644 --- a/collector/sysctl_linux.go +++ b/collector/sysctl_linux.go @@ -15,11 +15,11 @@ package collector import ( "fmt" + "log/slog" "strconv" "strings" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -33,7 +33,7 @@ var ( type sysctlCollector struct { fs procfs.FS - logger log.Logger + logger slog.Logger sysctls []*sysctl } @@ -41,7 +41,7 @@ func init() { registerCollector("sysctl", defaultDisabled, NewSysctlCollector) } -func NewSysctlCollector(logger log.Logger) (Collector, error) { +func NewSysctlCollector(logger slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) diff --git a/collector/sysctl_openbsd_amd64.go b/collector/sysctl_openbsd_amd64.go index 3d805109..317b2b38 100644 --- a/collector/sysctl_openbsd_amd64.go +++ b/collector/sysctl_openbsd_amd64.go @@ -15,6 +15,7 @@ package collector import ( "golang.org/x/sys/unix" + "log/slog" "syscall" "unsafe" ) diff --git a/collector/systemd_linux.go b/collector/systemd_linux.go index e0d35bcd..cd4a2766 100644 --- a/collector/systemd_linux.go +++ b/collector/systemd_linux.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "log/slog" "math" "regexp" "strconv" @@ -29,8 +30,6 @@ import ( "github.com/alecthomas/kingpin/v2" "github.com/coreos/go-systemd/v22/dbus" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -78,7 +77,7 @@ type systemdCollector struct { // Use regexps for more flexibility than device_filter.go allows systemdUnitIncludePattern *regexp.Regexp systemdUnitExcludePattern *regexp.Regexp - logger log.Logger + logger slog.Logger } var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"} @@ -88,7 +87,7 @@ func init() { } // NewSystemdCollector returns a new Collector exposing systemd statistics. -func NewSystemdCollector(logger log.Logger) (Collector, error) { +func NewSystemdCollector(logger slog.Logger) (Collector, error) { const subsystem = "systemd" unitDesc := prometheus.NewDesc( @@ -136,7 +135,7 @@ func NewSystemdCollector(logger log.Logger) (Collector, error) { if *oldSystemdUnitExclude != "" { if !systemdUnitExcludeSet { - level.Warn(logger).Log("msg", "--collector.systemd.unit-blacklist is DEPRECATED and will be removed in 2.0.0, use --collector.systemd.unit-exclude") + logger.Warn("--collector.systemd.unit-blacklist is DEPRECATED and will be removed in 2.0.0, use --collector.systemd.unit-exclude") *systemdUnitExclude = *oldSystemdUnitExclude } else { return nil, errors.New("--collector.systemd.unit-blacklist and --collector.systemd.unit-exclude are mutually exclusive") @@ -144,15 +143,15 @@ func NewSystemdCollector(logger log.Logger) (Collector, error) { } if *oldSystemdUnitInclude != "" { if !systemdUnitIncludeSet { - level.Warn(logger).Log("msg", "--collector.systemd.unit-whitelist is DEPRECATED and will be removed in 2.0.0, use --collector.systemd.unit-include") + logger.Warn("--collector.systemd.unit-whitelist is DEPRECATED and will be removed in 2.0.0, use --collector.systemd.unit-include") *systemdUnitInclude = *oldSystemdUnitInclude } else { return nil, errors.New("--collector.systemd.unit-whitelist and --collector.systemd.unit-include are mutually exclusive") } } - level.Info(logger).Log("msg", "Parsed flag --collector.systemd.unit-include", "flag", *systemdUnitInclude) + logger.Info("Parsed flag --collector.systemd.unit-include", "flag", *systemdUnitInclude) systemdUnitIncludePattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *systemdUnitInclude)) - level.Info(logger).Log("msg", "Parsed flag --collector.systemd.unit-exclude", "flag", *systemdUnitExclude) + logger.Info("Parsed flag --collector.systemd.unit-exclude", "flag", *systemdUnitExclude) systemdUnitExcludePattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *systemdUnitExclude)) return &systemdCollector{ @@ -186,7 +185,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { systemdVersion, systemdVersionFull := c.getSystemdVersion(conn) if systemdVersion < minSystemdVersionSystemState { - level.Debug(c.logger).Log("msg", "Detected systemd version is lower than minimum, some systemd state and timer metrics will not be available", "current", systemdVersion, "minimum", minSystemdVersionSystemState) + c.logger.Debug("Detected systemd version is lower than minimum, some systemd state and timer metrics will not be available", "current", systemdVersion, "minimum", minSystemdVersionSystemState) } ch <- prometheus.MustNewConstMetric( c.systemdVersionDesc, @@ -199,16 +198,16 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { if err != nil { return fmt.Errorf("couldn't get units: %w", err) } - level.Debug(c.logger).Log("msg", "getAllUnits took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("getAllUnits took", "duration_seconds", time.Since(begin).Seconds()) begin = time.Now() summary := summarizeUnits(allUnits) c.collectSummaryMetrics(ch, summary) - level.Debug(c.logger).Log("msg", "collectSummaryMetrics took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectSummaryMetrics took", "duration_seconds", time.Since(begin).Seconds()) begin = time.Now() units := filterUnits(allUnits, c.systemdUnitIncludePattern, c.systemdUnitExcludePattern, c.logger) - level.Debug(c.logger).Log("msg", "filterUnits took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("filterUnits took", "duration_seconds", time.Since(begin).Seconds()) var wg sync.WaitGroup defer wg.Wait() @@ -218,7 +217,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { defer wg.Done() begin = time.Now() c.collectUnitStatusMetrics(conn, ch, units) - level.Debug(c.logger).Log("msg", "collectUnitStatusMetrics took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectUnitStatusMetrics took", "duration_seconds", time.Since(begin).Seconds()) }() if *enableStartTimeMetrics { @@ -227,7 +226,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { defer wg.Done() begin = time.Now() c.collectUnitStartTimeMetrics(conn, ch, units) - level.Debug(c.logger).Log("msg", "collectUnitStartTimeMetrics took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectUnitStartTimeMetrics took", "duration_seconds", time.Since(begin).Seconds()) }() } @@ -237,7 +236,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { defer wg.Done() begin = time.Now() c.collectUnitTasksMetrics(conn, ch, units) - level.Debug(c.logger).Log("msg", "collectUnitTasksMetrics took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectUnitTasksMetrics took", "duration_seconds", time.Since(begin).Seconds()) }() } @@ -247,7 +246,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { defer wg.Done() begin = time.Now() c.collectTimers(conn, ch, units) - level.Debug(c.logger).Log("msg", "collectTimers took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectTimers took", "duration_seconds", time.Since(begin).Seconds()) }() } @@ -256,13 +255,13 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { defer wg.Done() begin = time.Now() c.collectSockets(conn, ch, units) - level.Debug(c.logger).Log("msg", "collectSockets took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectSockets took", "duration_seconds", time.Since(begin).Seconds()) }() if systemdVersion >= minSystemdVersionSystemState { begin = time.Now() err = c.collectSystemState(conn, ch) - level.Debug(c.logger).Log("msg", "collectSystemState took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectSystemState took", "duration_seconds", time.Since(begin).Seconds()) } return err @@ -274,14 +273,14 @@ func (c *systemdCollector) collectUnitStatusMetrics(conn *dbus.Conn, ch chan<- p if strings.HasSuffix(unit.Name, ".service") { serviceTypeProperty, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Service", "Type") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit type", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit type", "unit", unit.Name, "err", err) } else { serviceType = serviceTypeProperty.Value.Value().(string) } } else if strings.HasSuffix(unit.Name, ".mount") { serviceTypeProperty, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Mount", "Type") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit type", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit type", "unit", unit.Name, "err", err) } else { serviceType = serviceTypeProperty.Value.Value().(string) } @@ -299,7 +298,7 @@ func (c *systemdCollector) collectUnitStatusMetrics(conn *dbus.Conn, ch chan<- p // NRestarts wasn't added until systemd 235. restartsCount, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Service", "NRestarts") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit NRestarts", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit NRestarts", "unit", unit.Name, "err", err) } else { ch <- prometheus.MustNewConstMetric( c.nRestartsDesc, prometheus.CounterValue, @@ -317,7 +316,7 @@ func (c *systemdCollector) collectSockets(conn *dbus.Conn, ch chan<- prometheus. acceptedConnectionCount, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Socket", "NAccepted") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit NAccepted", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit NAccepted", "unit", unit.Name, "err", err) continue } ch <- prometheus.MustNewConstMetric( @@ -326,7 +325,7 @@ func (c *systemdCollector) collectSockets(conn *dbus.Conn, ch chan<- prometheus. currentConnectionCount, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Socket", "NConnections") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit NConnections", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit NConnections", "unit", unit.Name, "err", err) continue } ch <- prometheus.MustNewConstMetric( @@ -352,7 +351,7 @@ func (c *systemdCollector) collectUnitStartTimeMetrics(conn *dbus.Conn, ch chan< } else { timestampValue, err := conn.GetUnitPropertyContext(context.TODO(), unit.Name, "ActiveEnterTimestamp") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit StartTimeUsec", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit StartTimeUsec", "unit", unit.Name, "err", err) continue } startTimeUsec = timestampValue.Value.Value().(uint64) @@ -370,7 +369,7 @@ func (c *systemdCollector) collectUnitTasksMetrics(conn *dbus.Conn, ch chan<- pr if strings.HasSuffix(unit.Name, ".service") { tasksCurrentCount, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Service", "TasksCurrent") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit TasksCurrent", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit TasksCurrent", "unit", unit.Name, "err", err) } else { val = tasksCurrentCount.Value.Value().(uint64) // Don't set if tasksCurrent if dbus reports MaxUint64. @@ -382,7 +381,7 @@ func (c *systemdCollector) collectUnitTasksMetrics(conn *dbus.Conn, ch chan<- pr } tasksMaxCount, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Service", "TasksMax") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit TasksMax", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit TasksMax", "unit", unit.Name, "err", err) } else { val = tasksMaxCount.Value.Value().(uint64) // Don't set if tasksMax if dbus reports MaxUint64. @@ -404,7 +403,7 @@ func (c *systemdCollector) collectTimers(conn *dbus.Conn, ch chan<- prometheus.M lastTriggerValue, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Timer", "LastTriggerUSec") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit LastTriggerUSec", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit LastTriggerUSec", "unit", unit.Name, "err", err) continue } @@ -476,14 +475,14 @@ func summarizeUnits(units []unit) map[string]float64 { return summarized } -func filterUnits(units []unit, includePattern, excludePattern *regexp.Regexp, logger log.Logger) []unit { +func filterUnits(units []unit, includePattern, excludePattern *regexp.Regexp, logger slog.Logger) []unit { filtered := make([]unit, 0, len(units)) for _, unit := range units { if includePattern.MatchString(unit.Name) && !excludePattern.MatchString(unit.Name) && unit.LoadState == "loaded" { - level.Debug(logger).Log("msg", "Adding unit", "unit", unit.Name) + logger.Debug("Adding unit", "unit", unit.Name) filtered = append(filtered, unit) } else { - level.Debug(logger).Log("msg", "Ignoring unit", "unit", unit.Name) + logger.Debug("Ignoring unit", "unit", unit.Name) } } @@ -493,15 +492,15 @@ func filterUnits(units []unit, includePattern, excludePattern *regexp.Regexp, lo func (c *systemdCollector) getSystemdVersion(conn *dbus.Conn) (float64, string) { version, err := conn.GetManagerProperty("Version") if err != nil { - level.Debug(c.logger).Log("msg", "Unable to get systemd version property, defaulting to 0") + c.logger.Debug("Unable to get systemd version property, defaulting to 0") return 0, "" } version = strings.TrimPrefix(strings.TrimSuffix(version, `"`), `"`) - level.Debug(c.logger).Log("msg", "Got systemd version", "version", version) + c.logger.Debug("Got systemd version", "version", version) parsedVersion := systemdVersionRE.FindString(version) v, err := strconv.ParseFloat(parsedVersion, 64) if err != nil { - level.Debug(c.logger).Log("msg", "Got invalid systemd version", "version", version) + c.logger.Debug("Got invalid systemd version", "version", version) return 0, "" } return v, version diff --git a/collector/systemd_linux_test.go b/collector/systemd_linux_test.go index d4e300d1..68325edc 100644 --- a/collector/systemd_linux_test.go +++ b/collector/systemd_linux_test.go @@ -17,11 +17,11 @@ package collector import ( + "log/slog" "regexp" "testing" "github.com/coreos/go-systemd/v22/dbus" - "github.com/go-kit/log" ) // Creates mock UnitLists diff --git a/collector/tapestats_linux.go b/collector/tapestats_linux.go index 264c2210..52c5fcf6 100644 --- a/collector/tapestats_linux.go +++ b/collector/tapestats_linux.go @@ -18,12 +18,11 @@ package collector import ( "fmt" + "log/slog" "os" "regexp" "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" ) @@ -45,7 +44,7 @@ type tapestatsCollector struct { writeTimeSeconds *prometheus.Desc residualTotal *prometheus.Desc fs sysfs.FS - logger log.Logger + logger slog.Logger } func init() { @@ -54,7 +53,7 @@ func init() { // NewTapestatsCollector returns a new Collector exposing tape device stats. // Docs from https://www.kernel.org/doc/html/latest/scsi/st.html#sysfs-and-statistics-for-tape-devices -func NewTapestatsCollector(logger log.Logger) (Collector, error) { +func NewTapestatsCollector(logger slog.Logger) (Collector, error) { var tapeLabelNames = []string{"device"} fs, err := sysfs.NewFS(*sysPath) @@ -126,7 +125,7 @@ func (c *tapestatsCollector) Update(ch chan<- prometheus.Metric) error { tapes, err := c.fs.SCSITapeClass() if err != nil { if os.IsNotExist(err) { - level.Debug(c.logger).Log("msg", "scsi_tape stats not found, skipping") + c.logger.Debug("scsi_tape stats not found, skipping") return ErrNoData } return fmt.Errorf("error obtaining SCSITape class info: %s", err) @@ -134,7 +133,7 @@ func (c *tapestatsCollector) Update(ch chan<- prometheus.Metric) error { for _, tape := range tapes { if c.ignoredDevicesPattern.MatchString(tape.Name) { - level.Debug(c.logger).Log("msg", "Ignoring device", "device", tape.Name) + c.logger.Debug("Ignoring device", "device", tape.Name) continue } ch <- prometheus.MustNewConstMetric(c.ioNow, prometheus.GaugeValue, float64(tape.Counters.InFlight), tape.Name) diff --git a/collector/tcpstat_linux.go b/collector/tcpstat_linux.go index 99e33bc6..5de6e21e 100644 --- a/collector/tcpstat_linux.go +++ b/collector/tcpstat_linux.go @@ -18,11 +18,11 @@ package collector import ( "fmt" + "log/slog" "os" "syscall" "unsafe" - "github.com/go-kit/log" "github.com/mdlayher/netlink" "github.com/prometheus/client_golang/prometheus" ) @@ -60,7 +60,7 @@ const ( type tcpStatCollector struct { desc typedDesc - logger log.Logger + logger slog.Logger } func init() { @@ -68,7 +68,7 @@ func init() { } // NewTCPStatCollector returns a new Collector exposing network stats. -func NewTCPStatCollector(logger log.Logger) (Collector, error) { +func NewTCPStatCollector(logger slog.Logger) (Collector, error) { return &tcpStatCollector{ desc: typedDesc{prometheus.NewDesc( prometheus.BuildFQName(namespace, "tcp", "connection_states"), diff --git a/collector/tcpstat_linux_test.go b/collector/tcpstat_linux_test.go index e1bd090a..97d24350 100644 --- a/collector/tcpstat_linux_test.go +++ b/collector/tcpstat_linux_test.go @@ -19,6 +19,7 @@ package collector import ( "bytes" "encoding/binary" + "log/slog" "syscall" "testing" diff --git a/collector/textfile.go b/collector/textfile.go index 4f1fd0b8..c071b6ad 100644 --- a/collector/textfile.go +++ b/collector/textfile.go @@ -18,6 +18,7 @@ package collector import ( "fmt" + "log/slog" "os" "path/filepath" "sort" @@ -25,8 +26,6 @@ import ( "time" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "github.com/prometheus/common/expfmt" @@ -46,7 +45,7 @@ type textFileCollector struct { path string // Only set for testing to get predictable output. mtime *float64 - logger log.Logger + logger slog.Logger } func init() { @@ -55,7 +54,7 @@ func init() { // NewTextFileCollector returns a new Collector exposing metrics read from files // in the given textfile directory. -func NewTextFileCollector(logger log.Logger) (Collector, error) { +func NewTextFileCollector(logger slog.Logger) (Collector, error) { c := &textFileCollector{ path: *textFileDirectory, logger: logger, @@ -63,7 +62,7 @@ func NewTextFileCollector(logger log.Logger) (Collector, error) { return c, nil } -func convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Metric, logger log.Logger) { +func convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Metric, logger slog.Logger) { var valType prometheus.ValueType var val float64 @@ -79,7 +78,7 @@ func convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Me for _, metric := range metricFamily.Metric { if metric.TimestampMs != nil { - level.Warn(logger).Log("msg", "Ignoring unsupported custom timestamp on textfile collector metric", "metric", metric) + logger.Warn("Ignoring unsupported custom timestamp on textfile collector metric", "metric", metric) } labels := metric.GetLabel() @@ -207,7 +206,7 @@ func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error { files, err := os.ReadDir(path) if err != nil && path != "" { errored = true - level.Error(c.logger).Log("msg", "failed to read textfile collector directory", "path", path, "err", err) + c.logger.Error("failed to read textfile collector directory", "path", path, "err", err) } for _, f := range files { @@ -224,7 +223,7 @@ func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error { if mf.Help != nil && helpTexts[0] != *mf.Help || helpTexts[1] != "" { metricsNamesToHelpTexts[*mf.Name] = [2]string{helpTexts[0], *mf.Help} errored = true - level.Error(c.logger).Log("msg", "inconsistent metric help text", + c.logger.Error("inconsistent metric help text", "metric", *mf.Name, "original_help_text", helpTexts[0], "new_help_text", *mf.Help, @@ -242,7 +241,7 @@ func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error { if err != nil { errored = true - level.Error(c.logger).Log("msg", "failed to collect textfile data", "file", f.Name(), "err", err) + c.logger.Error("failed to collect textfile data", "file", f.Name(), "err", err) continue } diff --git a/collector/textfile_test.go b/collector/textfile_test.go index 95e5966f..c9aab402 100644 --- a/collector/textfile_test.go +++ b/collector/textfile_test.go @@ -18,17 +18,17 @@ package collector import ( "fmt" + "log/slog" "net/http" "net/http/httptest" "os" "testing" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/prometheus/common/promlog" - "github.com/prometheus/common/promlog/flag" + "github.com/prometheus/common/promslog" + "github.com/prometheus/common/promslog/flag" ) type collectorAdapter struct { @@ -126,8 +126,8 @@ func TestTextfileCollector(t *testing.T) { // Suppress a log message about `nonexistent_path` not existing, this is // expected and clutters the test output. - promlogConfig := &promlog.Config{} - flag.AddFlags(kingpin.CommandLine, promlogConfig) + promslogConfig := &promslog.Config{} + flag.AddFlags(kingpin.CommandLine, promslogConfig) if _, err := kingpin.CommandLine.Parse([]string{"--log.level", "debug"}); err != nil { t.Fatal(err) } diff --git a/collector/thermal_darwin.go b/collector/thermal_darwin.go index 25673dcc..4c3c08ce 100644 --- a/collector/thermal_darwin.go +++ b/collector/thermal_darwin.go @@ -47,9 +47,9 @@ import "C" import ( "errors" "fmt" + "log/slog" "unsafe" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -57,7 +57,7 @@ type thermCollector struct { cpuSchedulerLimit typedDesc cpuAvailableCPU typedDesc cpuSpeedLimit typedDesc - logger log.Logger + logger slog.Logger } const thermal = "thermal" @@ -67,7 +67,7 @@ func init() { } // NewThermCollector returns a new Collector exposing current CPU power levels. -func NewThermCollector(logger log.Logger) (Collector, error) { +func NewThermCollector(logger slog.Logger) (Collector, error) { return &thermCollector{ cpuSchedulerLimit: typedDesc{ desc: prometheus.NewDesc( diff --git a/collector/thermal_zone_linux.go b/collector/thermal_zone_linux.go index 6eff2732..841ec34d 100644 --- a/collector/thermal_zone_linux.go +++ b/collector/thermal_zone_linux.go @@ -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/sysfs" ) @@ -35,7 +34,7 @@ type thermalZoneCollector struct { coolingDeviceCurState *prometheus.Desc coolingDeviceMaxState *prometheus.Desc zoneTemp *prometheus.Desc - logger log.Logger + logger slog.Logger } func init() { @@ -43,7 +42,7 @@ func init() { } // NewThermalZoneCollector returns a new Collector exposing kernel/system statistics. -func NewThermalZoneCollector(logger log.Logger) (Collector, error) { +func NewThermalZoneCollector(logger slog.Logger) (Collector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) @@ -74,7 +73,7 @@ func (c *thermalZoneCollector) Update(ch chan<- prometheus.Metric) error { thermalZones, err := c.fs.ClassThermalZoneStats() if err != nil { if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) || errors.Is(err, os.ErrInvalid) { - level.Debug(c.logger).Log("msg", "Could not read thermal zone stats", "err", err) + c.logger.Debug("Could not read thermal zone stats", "err", err) return ErrNoData } return err diff --git a/collector/time.go b/collector/time.go index 31a6e74e..9e785127 100644 --- a/collector/time.go +++ b/collector/time.go @@ -17,10 +17,9 @@ package collector import ( + "log/slog" "time" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -29,7 +28,7 @@ type timeCollector struct { zone typedDesc clocksourcesAvailable typedDesc clocksourceCurrent typedDesc - logger log.Logger + logger slog.Logger } func init() { @@ -38,7 +37,7 @@ func init() { // NewTimeCollector returns a new Collector exposing the current system time in // seconds since epoch. -func NewTimeCollector(logger log.Logger) (Collector, error) { +func NewTimeCollector(logger slog.Logger) (Collector, error) { const subsystem = "time" return &timeCollector{ now: typedDesc{prometheus.NewDesc( @@ -70,9 +69,9 @@ func (c *timeCollector) Update(ch chan<- prometheus.Metric) error { nowSec := float64(now.UnixNano()) / 1e9 zone, zoneOffset := now.Zone() - level.Debug(c.logger).Log("msg", "Return time", "now", nowSec) + c.logger.Debug("Return time", "now", nowSec) ch <- c.now.mustNewConstMetric(nowSec) - level.Debug(c.logger).Log("msg", "Zone offset", "offset", zoneOffset, "time_zone", zone) + c.logger.Debug("Zone offset", "offset", zoneOffset, "time_zone", zone) ch <- c.zone.mustNewConstMetric(float64(zoneOffset), zone) return c.update(ch) } diff --git a/collector/time_linux.go b/collector/time_linux.go index dd4afe75..212ba228 100644 --- a/collector/time_linux.go +++ b/collector/time_linux.go @@ -20,7 +20,6 @@ import ( "fmt" "strconv" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) @@ -35,7 +34,7 @@ func (c *timeCollector) update(ch chan<- prometheus.Metric) error { if err != nil { return fmt.Errorf("couldn't get clocksources: %w", err) } - level.Debug(c.logger).Log("msg", "in Update", "clocksources", fmt.Sprintf("%v", clocksources)) + c.logger.Debug("in Update", "clocksources", fmt.Sprintf("%v", clocksources)) for i, clocksource := range clocksources { is := strconv.Itoa(i) diff --git a/collector/time_other.go b/collector/time_other.go index 8227435b..a04e6cd5 100644 --- a/collector/time_other.go +++ b/collector/time_other.go @@ -18,6 +18,7 @@ package collector import ( "github.com/prometheus/client_golang/prometheus" + "log/slog" ) func (c *timeCollector) update(ch chan<- prometheus.Metric) error { diff --git a/collector/timex.go b/collector/timex.go index 69cbc1a1..93f4b416 100644 --- a/collector/timex.go +++ b/collector/timex.go @@ -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" "golang.org/x/sys/unix" ) @@ -61,7 +60,7 @@ type timexCollector struct { stbcnt, tai, syncStatus typedDesc - logger log.Logger + logger slog.Logger } func init() { @@ -69,7 +68,7 @@ func init() { } // NewTimexCollector returns a new Collector exposing adjtime(3) stats. -func NewTimexCollector(logger log.Logger) (Collector, error) { +func NewTimexCollector(logger slog.Logger) (Collector, error) { const subsystem = "timex" return &timexCollector{ @@ -170,7 +169,7 @@ func (c *timexCollector) Update(ch chan<- prometheus.Metric) error { status, err := unix.Adjtimex(timex) if err != nil { if errors.Is(err, os.ErrPermission) { - level.Debug(c.logger).Log("msg", "Not collecting timex metrics", "err", err) + c.logger.Debug("Not collecting timex metrics", "err", err) return ErrNoData } return fmt.Errorf("failed to retrieve adjtimex stats: %w", err) diff --git a/collector/udp_queues_linux.go b/collector/udp_queues_linux.go index 3fac8691..ee3963e3 100644 --- a/collector/udp_queues_linux.go +++ b/collector/udp_queues_linux.go @@ -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" ) @@ -31,7 +30,7 @@ type ( udpQueuesCollector struct { fs procfs.FS desc *prometheus.Desc - logger log.Logger + logger slog.Logger } ) @@ -40,7 +39,7 @@ func init() { } // NewUDPqueuesCollector returns a new Collector exposing network udp queued bytes. -func NewUDPqueuesCollector(logger log.Logger) (Collector, error) { +func NewUDPqueuesCollector(logger slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -64,7 +63,7 @@ func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error { ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.RxQueueLength), "rx", "v4") } else { if errors.Is(errIPv4, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "not collecting ipv4 based metrics") + c.logger.Debug("not collecting ipv4 based metrics") } else { return fmt.Errorf("couldn't get udp queued bytes: %w", errIPv4) } @@ -76,7 +75,7 @@ func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error { ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.RxQueueLength), "rx", "v6") } else { if errors.Is(errIPv6, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "not collecting ipv6 based metrics") + c.logger.Debug("not collecting ipv6 based metrics") } else { return fmt.Errorf("couldn't get udp6 queued bytes: %w", errIPv6) } diff --git a/collector/uname.go b/collector/uname.go index 76e66b7e..db9fcbb6 100644 --- a/collector/uname.go +++ b/collector/uname.go @@ -18,8 +18,8 @@ package collector import ( - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" + "log/slog" ) var unameDesc = prometheus.NewDesc( @@ -37,7 +37,7 @@ var unameDesc = prometheus.NewDesc( ) type unameCollector struct { - logger log.Logger + logger slog.Logger } type uname struct { SysName string @@ -53,7 +53,7 @@ func init() { } // NewUnameCollector returns new unameCollector. -func newUnameCollector(logger log.Logger) (Collector, error) { +func newUnameCollector(logger slog.Logger) (Collector, error) { return &unameCollector{logger}, nil } diff --git a/collector/uname_bsd.go b/collector/uname_bsd.go index 69bf38e9..30255d99 100644 --- a/collector/uname_bsd.go +++ b/collector/uname_bsd.go @@ -18,6 +18,7 @@ package collector import ( + "log/slog" "strings" "golang.org/x/sys/unix" diff --git a/collector/vmstat_linux.go b/collector/vmstat_linux.go index cde2df5d..0cc18110 100644 --- a/collector/vmstat_linux.go +++ b/collector/vmstat_linux.go @@ -19,13 +19,13 @@ package collector import ( "bufio" "fmt" + "log/slog" "os" "regexp" "strconv" "strings" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -39,7 +39,7 @@ var ( type vmStatCollector struct { fieldPattern *regexp.Regexp - logger log.Logger + logger slog.Logger } func init() { @@ -47,7 +47,7 @@ func init() { } // NewvmStatCollector returns a new Collector exposing vmstat stats. -func NewvmStatCollector(logger log.Logger) (Collector, error) { +func NewvmStatCollector(logger slog.Logger) (Collector, error) { pattern := regexp.MustCompile(*vmStatFields) return &vmStatCollector{ fieldPattern: pattern, diff --git a/collector/watchdog.go b/collector/watchdog.go index 01351be9..98d0089d 100644 --- a/collector/watchdog.go +++ b/collector/watchdog.go @@ -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 watchdogCollector struct { fs sysfs.FS - logger log.Logger + logger slog.Logger } func init() { @@ -37,7 +36,7 @@ func init() { } // NewWatchdogCollector returns a new Collector exposing watchdog stats. -func NewWatchdogCollector(logger log.Logger) (Collector, error) { +func NewWatchdogCollector(logger slog.Logger) (Collector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -103,7 +102,7 @@ func (c *watchdogCollector) Update(ch chan<- prometheus.Metric) error { watchdogClass, err := c.fs.WatchdogClass() if err != nil { if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) || errors.Is(err, os.ErrInvalid) { - level.Debug(c.logger).Log("msg", "Could not read watchdog stats", "err", err) + c.logger.Debug("Could not read watchdog stats", "err", err) return ErrNoData } return err diff --git a/collector/watchdog_test.go b/collector/watchdog_test.go index e59382b4..38948dd3 100644 --- a/collector/watchdog_test.go +++ b/collector/watchdog_test.go @@ -18,11 +18,11 @@ package collector import ( "fmt" + "log/slog" "os" "strings" "testing" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" ) diff --git a/collector/wifi_linux.go b/collector/wifi_linux.go index aff8eb2d..9c6a4cff 100644 --- a/collector/wifi_linux.go +++ b/collector/wifi_linux.go @@ -20,12 +20,11 @@ import ( "encoding/json" "errors" "fmt" + "log/slog" "os" "path/filepath" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/mdlayher/wifi" "github.com/prometheus/client_golang/prometheus" ) @@ -45,7 +44,7 @@ type wifiCollector struct { stationTransmitFailedTotal *prometheus.Desc stationBeaconLossTotal *prometheus.Desc - logger log.Logger + logger slog.Logger } var ( @@ -67,7 +66,7 @@ type wifiStater interface { } // NewWifiCollector returns a new Collector exposing Wifi statistics. -func NewWifiCollector(logger log.Logger) (Collector, error) { +func NewWifiCollector(logger slog.Logger) (Collector, error) { const ( subsystem = "wifi" ) @@ -169,11 +168,11 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { if err != nil { // Cannot access wifi metrics, report no error. if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system") + c.logger.Debug("wifi collector metrics are not available for this system") return ErrNoData } if errors.Is(err, os.ErrPermission) { - level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics") + c.logger.Debug("wifi collector got permission denied when accessing metrics") return ErrNoData } @@ -192,7 +191,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { continue } - level.Debug(c.logger).Log("msg", "probing wifi device with type", "wifi", ifi.Name, "type", ifi.Type) + c.logger.Debug("probing wifi device with type", "wifi", ifi.Name, "type", ifi.Type) ch <- prometheus.MustNewConstMetric( c.interfaceFrequencyHertz, @@ -210,7 +209,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { case err == nil: c.updateBSSStats(ch, ifi.Name, bss) case errors.Is(err, os.ErrNotExist): - level.Debug(c.logger).Log("msg", "BSS information not found for wifi device", "name", ifi.Name) + c.logger.Debug("BSS information not found for wifi device", "name", ifi.Name) default: return fmt.Errorf("failed to retrieve BSS for device %s: %v", ifi.Name, err) @@ -223,7 +222,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { c.updateStationStats(ch, ifi.Name, station) } case errors.Is(err, os.ErrNotExist): - level.Debug(c.logger).Log("msg", "station information not found for wifi device", "name", ifi.Name) + c.logger.Debug("station information not found for wifi device", "name", ifi.Name) default: return fmt.Errorf("failed to retrieve station info for device %q: %v", ifi.Name, err) diff --git a/collector/xfrm.go b/collector/xfrm.go index cbdcc97f..ad9013b0 100644 --- a/collector/xfrm.go +++ b/collector/xfrm.go @@ -18,15 +18,15 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) type xfrmCollector struct { fs procfs.FS - logger log.Logger + logger slog.Logger } func init() { @@ -34,7 +34,7 @@ func init() { } // NewXfrmCollector returns a new Collector exposing XFRM stats. -func NewXfrmCollector(logger log.Logger) (Collector, error) { +func NewXfrmCollector(logger slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/xfrm_test.go b/collector/xfrm_test.go index 2e1ac028..e6b1a172 100644 --- a/collector/xfrm_test.go +++ b/collector/xfrm_test.go @@ -18,11 +18,11 @@ package collector import ( "fmt" + "log/slog" "os" "strings" "testing" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" ) diff --git a/collector/xfs_linux.go b/collector/xfs_linux.go index bb25acab..6400173d 100644 --- a/collector/xfs_linux.go +++ b/collector/xfs_linux.go @@ -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/xfs" ) @@ -27,7 +27,7 @@ import ( // An xfsCollector is a Collector which gathers metrics from XFS filesystems. type xfsCollector struct { fs xfs.FS - logger log.Logger + logger slog.Logger } func init() { @@ -35,7 +35,7 @@ func init() { } // NewXFSCollector returns a new Collector exposing XFS statistics. -func NewXFSCollector(logger log.Logger) (Collector, error) { +func NewXFSCollector(logger slog.Logger) (Collector, error) { fs, err := xfs.NewFS(*procPath, *sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) diff --git a/collector/zfs.go b/collector/zfs.go index 0abb1332..3e7f7336 100644 --- a/collector/zfs.go +++ b/collector/zfs.go @@ -18,10 +18,9 @@ package collector import ( "errors" + "log/slog" "strings" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -39,11 +38,11 @@ type zfsCollector struct { linuxZpoolObjsetPath string linuxZpoolStatePath string linuxPathMap map[string]string - logger log.Logger + logger slog.Logger } // NewZFSCollector returns a new Collector exposing ZFS statistics. -func NewZFSCollector(logger log.Logger) (Collector, error) { +func NewZFSCollector(logger slog.Logger) (Collector, error) { return &zfsCollector{ linuxProcpathBase: "spl/kstat/zfs", linuxZpoolIoPath: "/*/io", @@ -70,7 +69,7 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error { if _, err := c.openProcFile(c.linuxProcpathBase); err != nil { if err == errZFSNotAvailable { - level.Debug(c.logger).Log("err", err) + c.logger.Debug(err.Error()) return ErrNoData } } @@ -78,7 +77,7 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error { for subsystem := range c.linuxPathMap { if err := c.updateZfsStats(subsystem, ch); err != nil { if err == errZFSNotAvailable { - level.Debug(c.logger).Log("err", err) + c.logger.Debug(err.Error()) // ZFS /proc files are added as new features to ZFS arrive, it is ok to continue continue } diff --git a/collector/zfs_freebsd.go b/collector/zfs_freebsd.go index 804d4f58..f9d4d7ff 100644 --- a/collector/zfs_freebsd.go +++ b/collector/zfs_freebsd.go @@ -17,14 +17,13 @@ package collector import ( - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" + "log/slog" ) type zfsCollector struct { sysctls []bsdSysctl - logger log.Logger + logger slog.Logger } const ( @@ -35,7 +34,7 @@ func init() { registerCollector("zfs", defaultEnabled, NewZfsCollector) } -func NewZfsCollector(logger log.Logger) (Collector, error) { +func NewZfsCollector(logger slog.Logger) (Collector, error) { return &zfsCollector{ sysctls: []bsdSysctl{ { @@ -273,7 +272,7 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error { v, err := m.Value() if err != nil { // debug logging - level.Debug(c.logger).Log("name", m.name, "mib", m.mib, "couldn't get sysctl:", err) + c.logger.Debug(m.name, "mib", m.mib, "couldn't get sysctl:", err) continue } diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go index e1bf2c97..31e610d5 100644 --- a/collector/zfs_linux.go +++ b/collector/zfs_linux.go @@ -25,7 +25,6 @@ import ( "strconv" "strings" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -50,7 +49,7 @@ func (c *zfsCollector) openProcFile(path string) (*os.File, error) { // file not found error can occur if: // 1. zfs module is not loaded // 2. zfs version does not have the feature with metrics -- ok to ignore - level.Debug(c.logger).Log("msg", "Cannot open file for reading", "path", procFilePath(path)) + c.logger.Debug("Cannot open file for reading", "path", procFilePath(path)) return nil, errZFSNotAvailable } return file, nil @@ -85,7 +84,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) error { file, err := os.Open(zpoolPath) if err != nil { // this file should exist, but there is a race where an exporting pool can remove the files -- ok to ignore - level.Debug(c.logger).Log("msg", "Cannot open file for reading", "path", zpoolPath) + c.logger.Debug("Cannot open file for reading", "path", zpoolPath) return errZFSNotAvailable } @@ -107,7 +106,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) error { file, err := os.Open(zpoolPath) if err != nil { // This file should exist, but there is a race where an exporting pool can remove the files. Ok to ignore. - level.Debug(c.logger).Log("msg", "Cannot open file for reading", "path", zpoolPath) + c.logger.Debug("Cannot open file for reading", "path", zpoolPath) return errZFSNotAvailable } @@ -126,7 +125,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) error { } if zpoolStatePaths == nil { - level.Debug(c.logger).Log("msg", "No pool state files found") + c.logger.Debug("No pool state files found") return nil } @@ -134,7 +133,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) error { file, err := os.Open(zpoolPath) if err != nil { // This file should exist, but there is a race where an exporting pool can remove the files. Ok to ignore. - level.Debug(c.logger).Log("msg", "Cannot open file for reading", "path", zpoolPath) + c.logger.Debug("Cannot open file for reading", "path", zpoolPath) return errZFSNotAvailable } diff --git a/collector/zfs_linux_test.go b/collector/zfs_linux_test.go index 3b653f4c..c867349b 100644 --- a/collector/zfs_linux_test.go +++ b/collector/zfs_linux_test.go @@ -17,6 +17,7 @@ package collector import ( + "log/slog" "os" "path/filepath" "testing" diff --git a/collector/zfs_solaris.go b/collector/zfs_solaris.go index 52f2500f..e5c5394a 100644 --- a/collector/zfs_solaris.go +++ b/collector/zfs_solaris.go @@ -17,9 +17,9 @@ package collector import ( + "log/slog" "strings" - "github.com/go-kit/log" "github.com/illumos/go-kstat" "github.com/prometheus/client_golang/prometheus" ) @@ -54,7 +54,7 @@ type zfsCollector struct { arcstatsSize *prometheus.Desc zfetchstatsHits *prometheus.Desc zfetchstatsMisses *prometheus.Desc - logger log.Logger + logger slog.Logger } const ( @@ -65,7 +65,7 @@ func init() { registerCollector("zfs", defaultEnabled, NewZfsCollector) } -func NewZfsCollector(logger log.Logger) (Collector, error) { +func NewZfsCollector(logger slog.Logger) (Collector, error) { return &zfsCollector{ abdstatsLinearCount: prometheus.NewDesc( prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "abdstats_linear_count_total"), diff --git a/collector/zoneinfo_linux.go b/collector/zoneinfo_linux.go index 8f7e35d9..c38208fd 100644 --- a/collector/zoneinfo_linux.go +++ b/collector/zoneinfo_linux.go @@ -15,10 +15,9 @@ package collector import ( "fmt" + "log/slog" "reflect" - "github.com/go-kit/log" - "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -28,7 +27,7 @@ const zoneinfoSubsystem = "zoneinfo" type zoneinfoCollector struct { gaugeMetricDescs map[string]*prometheus.Desc counterMetricDescs map[string]*prometheus.Desc - logger log.Logger + logger slog.Logger fs procfs.FS } @@ -37,7 +36,7 @@ func init() { } // NewZoneinfoCollector returns a new Collector exposing zone stats. -func NewZoneinfoCollector(logger log.Logger) (Collector, error) { +func NewZoneinfoCollector(logger slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/go.mod b/go.mod index 4c1a572b..a9d6c568 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/coreos/go-systemd/v22 v22.5.0 github.com/dennwc/btrfs v0.0.0-20240418142341-0167142bde7a github.com/ema/qdisc v1.0.0 - github.com/go-kit/log v0.2.1 github.com/godbus/dbus/v5 v5.1.0 github.com/hashicorp/go-envparse v0.1.0 github.com/hodgesds/perf-utils v0.7.0 @@ -22,9 +21,9 @@ require ( github.com/mdlayher/wifi v0.2.0 github.com/opencontainers/selinux v1.11.0 github.com/prometheus-community/go-runit v0.1.0 - github.com/prometheus/client_golang v1.19.1 + github.com/prometheus/client_golang v1.20.0 github.com/prometheus/client_model v0.6.1 - github.com/prometheus/common v0.55.0 + github.com/prometheus/common v0.57.0 github.com/prometheus/exporter-toolkit v0.11.0 github.com/prometheus/procfs v0.15.1 github.com/safchain/ethtool v0.4.1 @@ -36,12 +35,14 @@ require ( require ( github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/dennwc/ioctl v1.0.0 // indirect + github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/jpillora/backoff v1.0.0 // indirect + github.com/klauspost/compress v1.17.9 // indirect + github.com/kylelemons/godebug v1.1.0 // indirect github.com/mdlayher/genetlink v1.3.2 // indirect github.com/mdlayher/socket v0.4.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect @@ -50,8 +51,8 @@ require ( github.com/xhit/go-str2duration/v2 v2.1.0 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect - golang.org/x/crypto v0.24.0 // indirect - golang.org/x/net v0.26.0 // indirect + golang.org/x/crypto v0.25.0 // indirect + golang.org/x/net v0.27.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/text v0.16.0 // indirect diff --git a/go.sum b/go.sum index bde5ad21..79cec0a2 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ github.com/beevik/ntp v1.4.3 h1:PlbTvE5NNy4QHmA4Mg57n7mcFTmr1W1j3gcK7L1lqho= github.com/beevik/ntp v1.4.3/go.mod h1:Unr8Zg+2dRn7d8bHFuehIMSvvUYssHMxW3Q5Nx4RW5Q= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cilium/ebpf v0.12.3 h1:8ht6F9MquybnY97at+VDZb3eQQr8ev79RueWeVaEcG4= github.com/cilium/ebpf v0.12.3/go.mod h1:TctK1ivibvI3znr66ljgi4hqOT8EYQjz1KWBfb1UVgM= github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= @@ -43,10 +43,14 @@ github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2E github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jsimonetti/rtnetlink v1.4.2 h1:Df9w9TZ3npHTyDn0Ev9e1uzmN2odmXd0QX+J5GTEn90= github.com/jsimonetti/rtnetlink v1.4.2/go.mod h1:92s6LJdE+1iOrw+F2/RO7LYI2Qd8pPpFNNUYW06gcoM= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lufia/iostat v1.2.1 h1:tnCdZBIglgxD47RyD55kfWQcJMGzO+1QBziSQfesf2k= github.com/lufia/iostat v1.2.1/go.mod h1:rEPNA0xXgjHQjuI5Cy05sLlS2oRcSlWHRLrvh/AQ+Pg= github.com/mattn/go-xmlrpc v0.0.3 h1:Y6WEMLEsqs3RviBrAa1/7qmbGB7DVD3brZIbqMbQdGY= @@ -71,12 +75,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus-community/go-runit v0.1.0 h1:uTWEj/Fn2RoLdfg/etSqwzgYNOYPrARx1BHUN052tGA= github.com/prometheus-community/go-runit v0.1.0/go.mod h1:AvJ9Jo3gAFu2lbM4+qfjdpq30FfiLDJZKbQ015u08IQ= -github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= -github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= +github.com/prometheus/client_golang v1.20.0 h1:jBzTZ7B099Rg24tny+qngoynol8LtVYlA2bqx3vEloI= +github.com/prometheus/client_golang v1.20.0/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= -github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= -github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= +github.com/prometheus/common v0.57.0 h1:Ro/rKjwdq9mZn1K5QPctzh+MA4Lp0BuYk5ZZEVhoNcY= +github.com/prometheus/common v0.57.0/go.mod h1:7uRPFSUTbfZWsJ7MHY56sqt7hLQu3bxXHDnNhl8E9qI= github.com/prometheus/exporter-toolkit v0.11.0 h1:yNTsuZ0aNCNFQ3aFTD2uhPOvr4iD7fdBvKPAEGkNf+g= github.com/prometheus/exporter-toolkit v0.11.0/go.mod h1:BVnENhnNecpwoTLiABx7mrPB/OLRIgN74qlQbV+FK1Q= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= @@ -98,12 +102,12 @@ go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY= golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= +golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= diff --git a/node_exporter.go b/node_exporter.go index c7285f6f..3dcd52db 100644 --- a/node_exporter.go +++ b/node_exporter.go @@ -15,7 +15,8 @@ package main import ( "fmt" - stdlog "log" + // stdlog "log" + "log/slog" "net/http" _ "net/http/pprof" "os" @@ -23,12 +24,10 @@ import ( "runtime" "sort" - "github.com/prometheus/common/promlog" - "github.com/prometheus/common/promlog/flag" + "github.com/prometheus/common/promslog" + "github.com/prometheus/common/promslog/flag" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" promcollectors "github.com/prometheus/client_golang/prometheus/collectors" versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version" @@ -49,10 +48,10 @@ type handler struct { exporterMetricsRegistry *prometheus.Registry includeExporterMetrics bool maxRequests int - logger log.Logger + logger slog.Logger } -func newHandler(includeExporterMetrics bool, maxRequests int, logger log.Logger) *handler { +func newHandler(includeExporterMetrics bool, maxRequests int, logger slog.Logger) *handler { h := &handler{ exporterMetricsRegistry: prometheus.NewRegistry(), includeExporterMetrics: includeExporterMetrics, @@ -76,7 +75,7 @@ func newHandler(includeExporterMetrics bool, maxRequests int, logger log.Logger) // ServeHTTP implements http.Handler. func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { filters := r.URL.Query()["collect[]"] - level.Debug(h.logger).Log("msg", "collect query:", "filters", filters) + h.logger.Debug("collect query:", "filters", filters) if len(filters) == 0 { // No filters, use the prepared unfiltered handler. @@ -86,7 +85,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // To serve filtered metrics, we create a filtering handler on the fly. filteredHandler, err := h.innerHandler(filters...) if err != nil { - level.Warn(h.logger).Log("msg", "Couldn't create filtered metrics handler:", "err", err) + h.logger.Warn("Couldn't create filtered metrics handler:", "err", err) w.WriteHeader(http.StatusBadRequest) w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err))) return @@ -108,14 +107,14 @@ func (h *handler) innerHandler(filters ...string) (http.Handler, error) { // Only log the creation of an unfiltered handler, which should happen // only once upon startup. if len(filters) == 0 { - level.Info(h.logger).Log("msg", "Enabled collectors") + h.logger.Info("Enabled collectors") collectors := []string{} for n := range nc.Collectors { collectors = append(collectors, n) } sort.Strings(collectors) for _, c := range collectors { - level.Info(h.logger).Log("collector", c) + h.logger.Info(c) } } @@ -130,7 +129,7 @@ func (h *handler) innerHandler(filters ...string) (http.Handler, error) { handler = promhttp.HandlerFor( prometheus.Gatherers{h.exporterMetricsRegistry, r}, promhttp.HandlerOpts{ - ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0), + // ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0), ErrorHandling: promhttp.ContinueOnError, MaxRequestsInFlight: h.maxRequests, Registry: h.exporterMetricsRegistry, @@ -145,7 +144,7 @@ func (h *handler) innerHandler(filters ...string) (http.Handler, error) { handler = promhttp.HandlerFor( r, promhttp.HandlerOpts{ - ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0), + // ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0), ErrorHandling: promhttp.ContinueOnError, MaxRequestsInFlight: h.maxRequests, }, @@ -179,26 +178,26 @@ func main() { toolkitFlags = kingpinflag.AddFlags(kingpin.CommandLine, ":9100") ) - promlogConfig := &promlog.Config{} - flag.AddFlags(kingpin.CommandLine, promlogConfig) + promslogConfig := &promslog.Config{} + flag.AddFlags(kingpin.CommandLine, promslogConfig) kingpin.Version(version.Print("node_exporter")) kingpin.CommandLine.UsageWriter(os.Stdout) kingpin.HelpFlag.Short('h') kingpin.Parse() - logger := promlog.New(promlogConfig) + logger := promslog.New(promslogConfig) if *disableDefaultCollectors { collector.DisableDefaultCollectors() } - level.Info(logger).Log("msg", "Starting node_exporter", "version", version.Info()) - level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext()) + logger.Info("Starting node_exporter", "version", version.Info()) + logger.Info("Build context", "build_context", version.BuildContext()) if user, err := user.Current(); err == nil && user.Uid == "0" { - level.Warn(logger).Log("msg", "Node Exporter is running as root user. This exporter is designed to run as unprivileged user, root is not required.") + logger.Warn("Node Exporter is running as root user. This exporter is designed to run as unprivileged user, root is not required.") } runtime.GOMAXPROCS(*maxProcs) - level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0)) + logger.Debug("Go MAXPROCS", "procs", runtime.GOMAXPROCS(0)) - http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, logger)) + http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, *logger)) if *metricsPath != "/" { landingConfig := web.LandingConfig{ Name: "Node Exporter", @@ -213,7 +212,7 @@ func main() { } landingPage, err := web.NewLandingPage(landingConfig) if err != nil { - level.Error(logger).Log("err", err) + logger.Error(err.Error()) os.Exit(1) } http.Handle("/", landingPage) @@ -221,7 +220,7 @@ func main() { server := &http.Server{} if err := web.ListenAndServe(server, toolkitFlags, logger); err != nil { - level.Error(logger).Log("err", err) + logger.Error(err) os.Exit(1) } }