From 204164e4e44cea0d1db041a72f525c90781f823c Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Thu, 4 Jun 2020 08:41:53 +0200 Subject: [PATCH 1/2] Include TCP OutRsts in netstat metrics TCP "OutRsts" is the number of TCP Resets sent by the node. This can be useful for monitoring connection failures and flooding. Signed-off-by: Ben Kochie --- CHANGELOG.md | 2 +- collector/fixtures/e2e-64k-page-output.txt | 3 +++ collector/fixtures/e2e-output.txt | 3 +++ collector/netstat_linux.go | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f32b944..36a1ad79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ * [CHANGE] * [FEATURE] -* [ENHANCEMENT] +* [ENHANCEMENT] Include TCP OutRsts in netstat metrics * [BUGFIX] ## 1.0.0 / 2020-05-25 diff --git a/collector/fixtures/e2e-64k-page-output.txt b/collector/fixtures/e2e-64k-page-output.txt index 3e9f6cb9..fe32915b 100644 --- a/collector/fixtures/e2e-64k-page-output.txt +++ b/collector/fixtures/e2e-64k-page-output.txt @@ -1886,6 +1886,9 @@ node_netstat_Tcp_InErrs 5 # HELP node_netstat_Tcp_InSegs Statistic TcpInSegs. # TYPE node_netstat_Tcp_InSegs untyped node_netstat_Tcp_InSegs 5.7252008e+07 +# HELP node_netstat_Tcp_OutRsts Statistic TcpOutRsts. +# TYPE node_netstat_Tcp_OutRsts untyped +node_netstat_Tcp_OutRsts 1003 # HELP node_netstat_Tcp_OutSegs Statistic TcpOutSegs. # TYPE node_netstat_Tcp_OutSegs untyped node_netstat_Tcp_OutSegs 5.4915039e+07 diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index df04679d..0edc65bb 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -1955,6 +1955,9 @@ node_netstat_Tcp_InErrs 5 # HELP node_netstat_Tcp_InSegs Statistic TcpInSegs. # TYPE node_netstat_Tcp_InSegs untyped node_netstat_Tcp_InSegs 5.7252008e+07 +# HELP node_netstat_Tcp_OutRsts Statistic TcpOutRsts. +# TYPE node_netstat_Tcp_OutRsts untyped +node_netstat_Tcp_OutRsts 1003 # HELP node_netstat_Tcp_OutSegs Statistic TcpOutSegs. # TYPE node_netstat_Tcp_OutSegs untyped node_netstat_Tcp_OutSegs 5.4915039e+07 diff --git a/collector/netstat_linux.go b/collector/netstat_linux.go index 9b4be49f..60bdbeaf 100644 --- a/collector/netstat_linux.go +++ b/collector/netstat_linux.go @@ -34,7 +34,7 @@ const ( ) var ( - netStatFields = kingpin.Flag("collector.netstat.fields", "Regexp of fields to return for netstat collector.").Default("^(.*_(InErrors|InErrs)|Ip_Forwarding|Ip(6|Ext)_(InOctets|OutOctets)|Icmp6?_(InMsgs|OutMsgs)|TcpExt_(Listen.*|Syncookies.*|TCPSynRetrans)|Tcp_(ActiveOpens|InSegs|OutSegs|PassiveOpens|RetransSegs|CurrEstab)|Udp6?_(InDatagrams|OutDatagrams|NoPorts|RcvbufErrors|SndbufErrors))$").String() + netStatFields = kingpin.Flag("collector.netstat.fields", "Regexp of fields to return for netstat collector.").Default("^(.*_(InErrors|InErrs)|Ip_Forwarding|Ip(6|Ext)_(InOctets|OutOctets)|Icmp6?_(InMsgs|OutMsgs)|TcpExt_(Listen.*|Syncookies.*|TCPSynRetrans)|Tcp_(ActiveOpens|InSegs|OutSegs|OutRsts|PassiveOpens|RetransSegs|CurrEstab)|Udp6?_(InDatagrams|OutDatagrams|NoPorts|RcvbufErrors|SndbufErrors))$").String() ) type netStatCollector struct { From dfa53f835a2916d8fa6d72f28d7d9d0617cbdbdb Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 15 Jun 2020 22:27:14 +0200 Subject: [PATCH 2/2] Use Go 1.13 error features * Use `errors.Is()` for unwrapping errors. * Use `%w` error verb in internal error formatting. Signed-off-by: Ben Kochie --- collector/arp_linux.go | 4 ++-- collector/bonding_linux.go | 5 +++-- collector/btrfs_linux.go | 4 ++-- collector/buddyinfo.go | 2 +- collector/diskstats_darwin.go | 2 +- collector/diskstats_linux.go | 4 ++-- collector/drbd_linux.go | 3 ++- collector/edac_linux.go | 12 ++++++------ collector/entropy_linux.go | 2 +- collector/filefd_linux.go | 4 ++-- collector/filesystem_linux.go | 3 ++- collector/hwmon_linux.go | 2 +- collector/infiniband_linux.go | 5 +++-- collector/interrupts_linux.go | 4 ++-- collector/interrupts_openbsd.go | 2 +- collector/ipvs_linux.go | 7 ++++--- collector/loadavg.go | 2 +- collector/loadavg_linux.go | 2 +- collector/logind_linux.go | 6 +++--- collector/mdadm_linux.go | 11 ++++++----- collector/meminfo.go | 2 +- collector/meminfo_linux.go | 2 +- collector/meminfo_numa_linux.go | 6 +++--- collector/meminfo_openbsd.go | 2 +- collector/memory_bsd.go | 6 +++--- collector/netclass_linux.go | 4 ++-- collector/netdev_common.go | 4 ++-- collector/netstat_linux.go | 11 ++++++----- collector/nfs_linux.go | 3 ++- collector/nfsd_linux.go | 3 ++- collector/ntp.go | 2 +- collector/powersupplyclass.go | 2 +- collector/processes_linux.go | 9 +++++---- collector/schedstat_linux.go | 3 ++- collector/sockstat_linux.go | 5 +++-- collector/softnet_linux.go | 2 +- collector/supervisord.go | 2 +- collector/systemd_linux.go | 6 +++--- collector/tcpstat_linux.go | 4 ++-- collector/textfile.go | 6 +++--- collector/udp_queues_linux.go | 13 +++++++------ collector/wifi_linux.go | 13 +++++++------ collector/zfs_freebsd.go | 2 +- collector/zfs_linux.go | 2 +- 44 files changed, 107 insertions(+), 93 deletions(-) diff --git a/collector/arp_linux.go b/collector/arp_linux.go index 6a188795..86cb78a1 100644 --- a/collector/arp_linux.go +++ b/collector/arp_linux.go @@ -84,7 +84,7 @@ func parseARPEntries(data io.Reader) (map[string]uint32, error) { } if err := scanner.Err(); err != nil { - return nil, fmt.Errorf("failed to parse ARP info: %s", err) + return nil, fmt.Errorf("failed to parse ARP info: %w", err) } return entries, nil @@ -93,7 +93,7 @@ func parseARPEntries(data io.Reader) (map[string]uint32, error) { func (c *arpCollector) Update(ch chan<- prometheus.Metric) error { entries, err := getARPEntries() if err != nil { - return fmt.Errorf("could not get ARP entries: %s", err) + return fmt.Errorf("could not get ARP entries: %w", err) } for device, entryCount := range entries { diff --git a/collector/bonding_linux.go b/collector/bonding_linux.go index 78e94b2f..863f62c2 100644 --- a/collector/bonding_linux.go +++ b/collector/bonding_linux.go @@ -16,6 +16,7 @@ package collector import ( + "errors" "fmt" "io/ioutil" "os" @@ -59,7 +60,7 @@ func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error { statusfile := sysFilePath("class/net") bondingStats, err := readBondingStats(statusfile) if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "Not collecting bonding, file does not exist", "file", statusfile) return ErrNoData } @@ -86,7 +87,7 @@ func readBondingStats(root string) (status map[string][2]int, err error) { sstat := [2]int{0, 0} for _, slave := range strings.Fields(string(slaves)) { state, err := ioutil.ReadFile(filepath.Join(root, master, fmt.Sprintf("lower_%s", slave), "bonding_slave", "mii_status")) - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { // some older? kernels use slave_ prefix state, err = ioutil.ReadFile(filepath.Join(root, master, fmt.Sprintf("slave_%s", slave), "bonding_slave", "mii_status")) } diff --git a/collector/btrfs_linux.go b/collector/btrfs_linux.go index 2336e655..4d4857b8 100644 --- a/collector/btrfs_linux.go +++ b/collector/btrfs_linux.go @@ -37,7 +37,7 @@ func init() { func NewBtrfsCollector(logger log.Logger) (Collector, error) { fs, err := btrfs.NewFS(*sysPath) if err != nil { - return nil, fmt.Errorf("failed to open sysfs: %v", err) + return nil, fmt.Errorf("failed to open sysfs: %w", err) } return &btrfsCollector{ @@ -51,7 +51,7 @@ func NewBtrfsCollector(logger log.Logger) (Collector, error) { func (c *btrfsCollector) Update(ch chan<- prometheus.Metric) error { stats, err := c.fs.Stats() if err != nil { - return fmt.Errorf("failed to retrieve Btrfs stats: %v", err) + return fmt.Errorf("failed to retrieve Btrfs stats: %w", err) } for _, s := range stats { diff --git a/collector/buddyinfo.go b/collector/buddyinfo.go index e94e283b..579c3e4c 100644 --- a/collector/buddyinfo.go +++ b/collector/buddyinfo.go @@ -59,7 +59,7 @@ func NewBuddyinfoCollector(logger log.Logger) (Collector, error) { func (c *buddyinfoCollector) Update(ch chan<- prometheus.Metric) error { buddyInfo, err := c.fs.BuddyInfo() if err != nil { - return fmt.Errorf("couldn't get buddyinfo: %s", err) + return fmt.Errorf("couldn't get buddyinfo: %w", err) } level.Debug(c.logger).Log("msg", "Set node_buddy", "buddyInfo", buddyInfo) diff --git a/collector/diskstats_darwin.go b/collector/diskstats_darwin.go index 89622a3c..864220bf 100644 --- a/collector/diskstats_darwin.go +++ b/collector/diskstats_darwin.go @@ -189,7 +189,7 @@ func NewDiskstatsCollector(logger log.Logger) (Collector, error) { func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { diskStats, err := iostat.ReadDriveStats() if err != nil { - return fmt.Errorf("couldn't get diskstats: %s", err) + return fmt.Errorf("couldn't get diskstats: %w", err) } for _, stats := range diskStats { diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go index 5d714227..b5ae82d8 100644 --- a/collector/diskstats_linux.go +++ b/collector/diskstats_linux.go @@ -187,7 +187,7 @@ func NewDiskstatsCollector(logger log.Logger) (Collector, error) { func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { diskStats, err := getDiskStats() if err != nil { - return fmt.Errorf("couldn't get diskstats: %s", err) + return fmt.Errorf("couldn't get diskstats: %w", err) } for dev, stats := range diskStats { @@ -203,7 +203,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { } v, err := strconv.ParseFloat(value, 64) if err != nil { - return fmt.Errorf("invalid value %s in diskstats: %s", value, err) + return fmt.Errorf("invalid value %s in diskstats: %w", value, err) } ch <- c.descs[i].mustNewConstMetric(v, dev) } diff --git a/collector/drbd_linux.go b/collector/drbd_linux.go index 4beb31db..281c079d 100644 --- a/collector/drbd_linux.go +++ b/collector/drbd_linux.go @@ -17,6 +17,7 @@ package collector import ( "bufio" + "errors" "fmt" "os" "strconv" @@ -188,7 +189,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error { statsFile := procFilePath("drbd") file, err := os.Open(statsFile) if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "stats file does not exist, skipping", "file", statsFile, "err", err) return ErrNoData } diff --git a/collector/edac_linux.go b/collector/edac_linux.go index 91b95100..1248e2e7 100644 --- a/collector/edac_linux.go +++ b/collector/edac_linux.go @@ -86,28 +86,28 @@ func (c *edacCollector) Update(ch chan<- prometheus.Metric) error { value, err := readUintFromFile(filepath.Join(controller, "ce_count")) if err != nil { - return fmt.Errorf("couldn't get ce_count for controller %s: %s", controllerNumber, err) + return fmt.Errorf("couldn't get ce_count for controller %s: %w", controllerNumber, err) } ch <- prometheus.MustNewConstMetric( c.ceCount, prometheus.CounterValue, float64(value), controllerNumber) value, err = readUintFromFile(filepath.Join(controller, "ce_noinfo_count")) if err != nil { - return fmt.Errorf("couldn't get ce_noinfo_count for controller %s: %s", controllerNumber, err) + return fmt.Errorf("couldn't get ce_noinfo_count for controller %s: %w", controllerNumber, err) } ch <- prometheus.MustNewConstMetric( c.csRowCECount, prometheus.CounterValue, float64(value), controllerNumber, "unknown") value, err = readUintFromFile(filepath.Join(controller, "ue_count")) if err != nil { - return fmt.Errorf("couldn't get ue_count for controller %s: %s", controllerNumber, err) + return fmt.Errorf("couldn't get ue_count for controller %s: %w", controllerNumber, err) } ch <- prometheus.MustNewConstMetric( c.ueCount, prometheus.CounterValue, float64(value), controllerNumber) value, err = readUintFromFile(filepath.Join(controller, "ue_noinfo_count")) if err != nil { - return fmt.Errorf("couldn't get ue_noinfo_count for controller %s: %s", controllerNumber, err) + return fmt.Errorf("couldn't get ue_noinfo_count for controller %s: %w", controllerNumber, err) } ch <- prometheus.MustNewConstMetric( c.csRowUECount, prometheus.CounterValue, float64(value), controllerNumber, "unknown") @@ -126,14 +126,14 @@ func (c *edacCollector) Update(ch chan<- prometheus.Metric) error { value, err = readUintFromFile(filepath.Join(csrow, "ce_count")) if err != nil { - return fmt.Errorf("couldn't get ce_count for controller/csrow %s/%s: %s", controllerNumber, csrowNumber, err) + return fmt.Errorf("couldn't get ce_count for controller/csrow %s/%s: %w", controllerNumber, csrowNumber, err) } ch <- prometheus.MustNewConstMetric( c.csRowCECount, prometheus.CounterValue, float64(value), controllerNumber, csrowNumber) value, err = readUintFromFile(filepath.Join(csrow, "ue_count")) if err != nil { - return fmt.Errorf("couldn't get ue_count for controller/csrow %s/%s: %s", controllerNumber, csrowNumber, err) + return fmt.Errorf("couldn't get ue_count for controller/csrow %s/%s: %w", controllerNumber, csrowNumber, err) } ch <- prometheus.MustNewConstMetric( c.csRowUECount, prometheus.CounterValue, float64(value), controllerNumber, csrowNumber) diff --git a/collector/entropy_linux.go b/collector/entropy_linux.go index e68eb958..3c42c3d0 100644 --- a/collector/entropy_linux.go +++ b/collector/entropy_linux.go @@ -46,7 +46,7 @@ func NewEntropyCollector(logger log.Logger) (Collector, error) { func (c *entropyCollector) Update(ch chan<- prometheus.Metric) error { value, err := readUintFromFile(procFilePath("sys/kernel/random/entropy_avail")) if err != nil { - return fmt.Errorf("couldn't get entropy_avail: %s", err) + return fmt.Errorf("couldn't get entropy_avail: %w", err) } ch <- prometheus.MustNewConstMetric( c.entropyAvail, prometheus.GaugeValue, float64(value)) diff --git a/collector/filefd_linux.go b/collector/filefd_linux.go index f8d3fcec..450c4e34 100644 --- a/collector/filefd_linux.go +++ b/collector/filefd_linux.go @@ -46,12 +46,12 @@ func NewFileFDStatCollector(logger log.Logger) (Collector, error) { func (c *fileFDStatCollector) Update(ch chan<- prometheus.Metric) error { fileFDStat, err := parseFileFDStats(procFilePath("sys/fs/file-nr")) if err != nil { - return fmt.Errorf("couldn't get file-nr: %s", err) + return fmt.Errorf("couldn't get file-nr: %w", err) } for name, value := range fileFDStat { v, err := strconv.ParseFloat(value, 64) if err != nil { - return fmt.Errorf("invalid value %s in file-nr: %s", value, err) + return fmt.Errorf("invalid value %s in file-nr: %w", value, err) } ch <- prometheus.MustNewConstMetric( prometheus.NewDesc( diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index e83b27aa..00a73231 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -17,6 +17,7 @@ package collector import ( "bufio" + "errors" "fmt" "io" "os" @@ -139,7 +140,7 @@ func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logg func mountPointDetails(logger log.Logger) ([]filesystemLabels, error) { file, err := os.Open(procFilePath("1/mounts")) - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { // Fallback to `/proc/mounts` if `/proc/1/mounts` is missing due hidepid. level.Debug(logger).Log("msg", "Reading root mounts failed, falling back to system mounts", "err", err) file, err = os.Open(procFilePath("mounts")) diff --git a/collector/hwmon_linux.go b/collector/hwmon_linux.go index 56499424..261a7c5a 100644 --- a/collector/hwmon_linux.go +++ b/collector/hwmon_linux.go @@ -424,7 +424,7 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error { hwmonFiles, err := ioutil.ReadDir(hwmonPathName) if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "hwmon collector metrics are not available for this system") return ErrNoData } diff --git a/collector/infiniband_linux.go b/collector/infiniband_linux.go index 1f453b82..d9382102 100644 --- a/collector/infiniband_linux.go +++ b/collector/infiniband_linux.go @@ -17,6 +17,7 @@ package collector import ( + "errors" "fmt" "os" "strconv" @@ -108,11 +109,11 @@ func (c *infinibandCollector) pushCounter(ch chan<- prometheus.Metric, name stri func (c *infinibandCollector) Update(ch chan<- prometheus.Metric) error { devices, err := c.fs.InfiniBandClass() if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "infiniband statistics not found, skipping") return ErrNoData } - return fmt.Errorf("error obtaining InfiniBand class info: %s", err) + return fmt.Errorf("error obtaining InfiniBand class info: %w", err) } for _, device := range devices { diff --git a/collector/interrupts_linux.go b/collector/interrupts_linux.go index cacfedaa..5fcbebc9 100644 --- a/collector/interrupts_linux.go +++ b/collector/interrupts_linux.go @@ -34,13 +34,13 @@ var ( func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) (err error) { interrupts, err := getInterrupts() if err != nil { - return fmt.Errorf("couldn't get interrupts: %s", err) + return fmt.Errorf("couldn't get interrupts: %w", err) } for name, interrupt := range interrupts { for cpuNo, value := range interrupt.values { fv, err := strconv.ParseFloat(value, 64) if err != nil { - return fmt.Errorf("invalid value %s in interrupts: %s", value, err) + return fmt.Errorf("invalid value %s in interrupts: %w", value, err) } ch <- c.desc.mustNewConstMetric(fv, strconv.Itoa(cpuNo), name, interrupt.info, interrupt.devices) } diff --git a/collector/interrupts_openbsd.go b/collector/interrupts_openbsd.go index c9aae3ca..bf38fe38 100644 --- a/collector/interrupts_openbsd.go +++ b/collector/interrupts_openbsd.go @@ -101,7 +101,7 @@ var ( func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) error { interrupts, err := getInterrupts() if err != nil { - return fmt.Errorf("couldn't get interrupts: %s", err) + return fmt.Errorf("couldn't get interrupts: %w", err) } for dev, interrupt := range interrupts { for cpuNo, value := range interrupt.values { diff --git a/collector/ipvs_linux.go b/collector/ipvs_linux.go index b5c8d73e..c2e9d709 100644 --- a/collector/ipvs_linux.go +++ b/collector/ipvs_linux.go @@ -16,6 +16,7 @@ package collector import ( + "errors" "fmt" "os" "sort" @@ -140,11 +141,11 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error { ipvsStats, err := c.fs.IPVSStats() if err != nil { // Cannot access ipvs metrics, report no error. - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "ipvs collector metrics are not available for this system") return ErrNoData } - return fmt.Errorf("could not get IPVS stats: %s", err) + return fmt.Errorf("could not get IPVS stats: %w", err) } ch <- c.connections.mustNewConstMetric(float64(ipvsStats.Connections)) ch <- c.incomingPackets.mustNewConstMetric(float64(ipvsStats.IncomingPackets)) @@ -154,7 +155,7 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error { backendStats, err := c.fs.IPVSBackendStatus() if err != nil { - return fmt.Errorf("could not get backend status: %s", err) + return fmt.Errorf("could not get backend status: %w", err) } sums := map[string]ipvsBackendStatus{} diff --git a/collector/loadavg.go b/collector/loadavg.go index 7c8bcff6..7c1fd996 100644 --- a/collector/loadavg.go +++ b/collector/loadavg.go @@ -48,7 +48,7 @@ func NewLoadavgCollector(logger log.Logger) (Collector, error) { func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) error { loads, err := getLoad() if err != nil { - return fmt.Errorf("couldn't get load: %s", err) + 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) diff --git a/collector/loadavg_linux.go b/collector/loadavg_linux.go index 668d3eda..7b89668e 100644 --- a/collector/loadavg_linux.go +++ b/collector/loadavg_linux.go @@ -45,7 +45,7 @@ func parseLoad(data string) (loads []float64, err error) { for i, load := range parts[0:3] { loads[i], err = strconv.ParseFloat(load, 64) if err != nil { - return nil, fmt.Errorf("could not parse load '%s': %s", load, err) + return nil, fmt.Errorf("could not parse load '%s': %w", load, err) } } return loads, nil diff --git a/collector/logind_linux.go b/collector/logind_linux.go index fb3cb570..19a29a2e 100644 --- a/collector/logind_linux.go +++ b/collector/logind_linux.go @@ -92,7 +92,7 @@ func NewLogindCollector(logger log.Logger) (Collector, error) { func (lc *logindCollector) Update(ch chan<- prometheus.Metric) error { c, err := newDbus() if err != nil { - return fmt.Errorf("unable to connect to dbus: %s", err) + return fmt.Errorf("unable to connect to dbus: %w", err) } defer c.conn.Close() @@ -102,12 +102,12 @@ func (lc *logindCollector) Update(ch chan<- prometheus.Metric) error { func collectMetrics(ch chan<- prometheus.Metric, c logindInterface) error { seats, err := c.listSeats() if err != nil { - return fmt.Errorf("unable to get seats: %s", err) + return fmt.Errorf("unable to get seats: %w", err) } sessionList, err := c.listSessions() if err != nil { - return fmt.Errorf("unable to get sessions: %s", err) + return fmt.Errorf("unable to get sessions: %w", err) } sessions := make(map[logindSession]float64) diff --git a/collector/mdadm_linux.go b/collector/mdadm_linux.go index 05f83eec..865553fe 100644 --- a/collector/mdadm_linux.go +++ b/collector/mdadm_linux.go @@ -16,6 +16,7 @@ package collector import ( + "errors" "fmt" "os" @@ -94,21 +95,21 @@ var ( ) func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error { - fs, errFs := procfs.NewFS(*procPath) + fs, err := procfs.NewFS(*procPath) - if errFs != nil { - return fmt.Errorf("failed to open procfs: %w", errFs) + if err != nil { + return fmt.Errorf("failed to open procfs: %w", err) } mdStats, err := fs.MDStat() if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "Not collecting mdstat, file does not exist", "file", *procPath) return ErrNoData } - return fmt.Errorf("error parsing mdstatus: %s", err) + return fmt.Errorf("error parsing mdstatus: %w", err) } for _, mdStat := range mdStats { diff --git a/collector/meminfo.go b/collector/meminfo.go index d3d3b8de..38b23268 100644 --- a/collector/meminfo.go +++ b/collector/meminfo.go @@ -48,7 +48,7 @@ func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error { var metricType prometheus.ValueType memInfo, err := c.getMemInfo() if err != nil { - return fmt.Errorf("couldn't get meminfo: %s", err) + return fmt.Errorf("couldn't get meminfo: %w", err) } level.Debug(c.logger).Log("msg", "Set node_mem", "memInfo", memInfo) for k, v := range memInfo { diff --git a/collector/meminfo_linux.go b/collector/meminfo_linux.go index 3b9e2e9a..88505da6 100644 --- a/collector/meminfo_linux.go +++ b/collector/meminfo_linux.go @@ -54,7 +54,7 @@ func parseMemInfo(r io.Reader) (map[string]float64, error) { } fv, err := strconv.ParseFloat(parts[1], 64) if err != nil { - return nil, fmt.Errorf("invalid value in meminfo: %s", err) + return nil, fmt.Errorf("invalid value in meminfo: %w", err) } key := parts[0][:len(parts[0])-1] // remove trailing : from key // Active(anon) -> Active_anon diff --git a/collector/meminfo_numa_linux.go b/collector/meminfo_numa_linux.go index d36f6a0b..f3d93073 100644 --- a/collector/meminfo_numa_linux.go +++ b/collector/meminfo_numa_linux.go @@ -62,7 +62,7 @@ func NewMeminfoNumaCollector(logger log.Logger) (Collector, error) { func (c *meminfoNumaCollector) Update(ch chan<- prometheus.Metric) error { metrics, err := getMemInfoNuma() if err != nil { - return fmt.Errorf("couldn't get NUMA meminfo: %s", err) + return fmt.Errorf("couldn't get NUMA meminfo: %w", err) } for _, v := range metrics { desc, ok := c.metricDescs[v.metricName] @@ -137,7 +137,7 @@ func parseMemInfoNuma(r io.Reader) ([]meminfoMetric, error) { fv, err := strconv.ParseFloat(parts[3], 64) if err != nil { - return nil, fmt.Errorf("invalid value in meminfo: %s", err) + return nil, fmt.Errorf("invalid value in meminfo: %w", err) } switch l := len(parts); { case l == 4: // no unit @@ -174,7 +174,7 @@ func parseMemInfoNumaStat(r io.Reader, nodeNumber string) ([]meminfoMetric, erro fv, err := strconv.ParseFloat(parts[1], 64) if err != nil { - return nil, fmt.Errorf("invalid value in numastat: %s", err) + return nil, fmt.Errorf("invalid value in numastat: %w", err) } numaStat = append(numaStat, meminfoMetric{parts[0] + "_total", prometheus.CounterValue, nodeNumber, fv}) diff --git a/collector/meminfo_openbsd.go b/collector/meminfo_openbsd.go index 073fbe7d..81102d59 100644 --- a/collector/meminfo_openbsd.go +++ b/collector/meminfo_openbsd.go @@ -62,7 +62,7 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { } if _, err := C.sysctl_bcstats(&bcstats); err != nil { - return nil, fmt.Errorf("sysctl CTL_VFS VFS_GENERIC VFS_BCACHESTAT failed: %v", err) + return nil, fmt.Errorf("sysctl CTL_VFS VFS_GENERIC VFS_BCACHESTAT failed: %w", err) } ps := float64(uvmexp.pagesize) diff --git a/collector/memory_bsd.go b/collector/memory_bsd.go index 4be5dddd..ac8b3010 100644 --- a/collector/memory_bsd.go +++ b/collector/memory_bsd.go @@ -43,7 +43,7 @@ func init() { func NewMemoryCollector(logger log.Logger) (Collector, error) { tmp32, err := unix.SysctlUint32("vm.stats.vm.v_page_size") if err != nil { - return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %s", err) + return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %w", err) } size := float64(tmp32) @@ -136,7 +136,7 @@ func (c *memoryCollector) Update(ch chan<- prometheus.Metric) error { for _, m := range c.sysctls { v, err := m.Value() if err != nil { - return fmt.Errorf("couldn't get memory: %s", err) + return fmt.Errorf("couldn't get memory: %w", err) } // Most are gauges. @@ -154,7 +154,7 @@ func (c *memoryCollector) Update(ch chan<- prometheus.Metric) error { swapUsed, err := c.kvm.SwapUsedPages() if err != nil { - return fmt.Errorf("couldn't get kvm: %s", err) + return fmt.Errorf("couldn't get kvm: %w", err) } ch <- prometheus.MustNewConstMetric( diff --git a/collector/netclass_linux.go b/collector/netclass_linux.go index cbfcb628..0fde2191 100644 --- a/collector/netclass_linux.go +++ b/collector/netclass_linux.go @@ -61,7 +61,7 @@ func NewNetClassCollector(logger log.Logger) (Collector, error) { func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error { netClass, err := c.getNetClassInfo() if err != nil { - return fmt.Errorf("could not get net class info: %s", err) + return fmt.Errorf("could not get net class info: %w", err) } for _, ifaceInfo := range netClass { upDesc := prometheus.NewDesc( @@ -175,7 +175,7 @@ func (c *netClassCollector) getNetClassInfo() (sysfs.NetClass, error) { netClass, err := c.fs.NetClass() if err != nil { - return netClass, fmt.Errorf("error obtaining net class info: %s", err) + return netClass, fmt.Errorf("error obtaining net class info: %w", err) } for device := range netClass { diff --git a/collector/netdev_common.go b/collector/netdev_common.go index 656e2aaf..a28bd43b 100644 --- a/collector/netdev_common.go +++ b/collector/netdev_common.go @@ -95,7 +95,7 @@ func NewNetDevCollector(logger log.Logger) (Collector, error) { func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error { netDev, err := getNetDevStats(c.deviceExcludePattern, c.deviceIncludePattern, c.logger) if err != nil { - return fmt.Errorf("couldn't get netstats: %s", err) + return fmt.Errorf("couldn't get netstats: %w", err) } for dev, devStats := range netDev { for key, value := range devStats { @@ -111,7 +111,7 @@ func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error { } v, err := strconv.ParseFloat(value, 64) if err != nil { - return fmt.Errorf("invalid value %s in netstats: %s", value, err) + return fmt.Errorf("invalid value %s in netstats: %w", value, err) } ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, dev) } diff --git a/collector/netstat_linux.go b/collector/netstat_linux.go index 9b4be49f..6fac0507 100644 --- a/collector/netstat_linux.go +++ b/collector/netstat_linux.go @@ -17,6 +17,7 @@ package collector import ( "bufio" + "errors" "fmt" "io" "os" @@ -59,15 +60,15 @@ func NewNetStatCollector(logger log.Logger) (Collector, error) { func (c *netStatCollector) Update(ch chan<- prometheus.Metric) error { netStats, err := getNetStats(procFilePath("net/netstat")) if err != nil { - return fmt.Errorf("couldn't get netstats: %s", err) + return fmt.Errorf("couldn't get netstats: %w", err) } snmpStats, err := getNetStats(procFilePath("net/snmp")) if err != nil { - return fmt.Errorf("couldn't get SNMP stats: %s", err) + return fmt.Errorf("couldn't get SNMP stats: %w", err) } snmp6Stats, err := getSNMP6Stats(procFilePath("net/snmp6")) if err != nil { - return fmt.Errorf("couldn't get SNMP6 stats: %s", err) + return fmt.Errorf("couldn't get SNMP6 stats: %w", err) } // Merge the results of snmpStats into netStats (collisions are possible, but // we know that the keys are always unique for the given use case). @@ -82,7 +83,7 @@ func (c *netStatCollector) Update(ch chan<- prometheus.Metric) error { key := protocol + "_" + name v, err := strconv.ParseFloat(value, 64) if err != nil { - return fmt.Errorf("invalid value %s in netstats: %s", value, err) + return fmt.Errorf("invalid value %s in netstats: %w", value, err) } if !c.fieldPattern.MatchString(key) { continue @@ -140,7 +141,7 @@ func getSNMP6Stats(fileName string) (map[string]map[string]string, error) { if err != nil { // On systems with IPv6 disabled, this file won't exist. // Do nothing. - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { return nil, nil } diff --git a/collector/nfs_linux.go b/collector/nfs_linux.go index a540bb30..60803eb0 100644 --- a/collector/nfs_linux.go +++ b/collector/nfs_linux.go @@ -16,6 +16,7 @@ package collector import ( + "errors" "fmt" "os" "reflect" @@ -97,7 +98,7 @@ func NewNfsCollector(logger log.Logger) (Collector, error) { func (c *nfsCollector) Update(ch chan<- prometheus.Metric) error { stats, err := c.fs.ClientRPCStats() if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "Not collecting NFS metrics", "err", err) return ErrNoData } diff --git a/collector/nfsd_linux.go b/collector/nfsd_linux.go index 8cb1e050..3dba8995 100644 --- a/collector/nfsd_linux.go +++ b/collector/nfsd_linux.go @@ -16,6 +16,7 @@ package collector import ( + "errors" "fmt" "os" @@ -63,7 +64,7 @@ func NewNFSdCollector(logger log.Logger) (Collector, error) { func (c *nfsdCollector) Update(ch chan<- prometheus.Metric) error { stats, err := c.fs.ServerRPCStats() if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "Not collecting NFSd metrics", "err", err) return ErrNoData } diff --git a/collector/ntp.go b/collector/ntp.go index 411ba25b..c7d55c99 100644 --- a/collector/ntp.go +++ b/collector/ntp.go @@ -125,7 +125,7 @@ func (c *ntpCollector) Update(ch chan<- prometheus.Metric) error { Timeout: time.Second, // default `ntpdate` timeout }) if err != nil { - return fmt.Errorf("couldn't get SNTP reply: %s", err) + return fmt.Errorf("couldn't get SNTP reply: %w", err) } ch <- c.stratum.mustNewConstMetric(float64(resp.Stratum)) diff --git a/collector/powersupplyclass.go b/collector/powersupplyclass.go index 309b08c2..adebf0e6 100644 --- a/collector/powersupplyclass.go +++ b/collector/powersupplyclass.go @@ -59,7 +59,7 @@ func (c *powerSupplyClassCollector) Update(ch chan<- prometheus.Metric) error { if errors.Is(err, os.ErrNotExist) { return ErrNoData } - return fmt.Errorf("could not get power_supply class info: %s", err) + return fmt.Errorf("could not get power_supply class info: %w", err) } for _, powerSupply := range powerSupplyClass { diff --git a/collector/processes_linux.go b/collector/processes_linux.go index 3d64cbd6..3d4e95d2 100644 --- a/collector/processes_linux.go +++ b/collector/processes_linux.go @@ -16,6 +16,7 @@ package collector import ( + "errors" "fmt" "os" @@ -75,13 +76,13 @@ func NewProcessStatCollector(logger log.Logger) (Collector, error) { func (c *processCollector) Update(ch chan<- prometheus.Metric) error { pids, states, threads, err := c.getAllocatedThreads() if err != nil { - return fmt.Errorf("unable to retrieve number of allocated threads: %q", err) + return fmt.Errorf("unable to retrieve number of allocated threads: %w", err) } ch <- prometheus.MustNewConstMetric(c.threadAlloc, prometheus.GaugeValue, float64(threads)) maxThreads, err := readUintFromFile(procFilePath("sys/kernel/threads-max")) if err != nil { - return fmt.Errorf("unable to retrieve limit number of threads: %q", err) + return fmt.Errorf("unable to retrieve limit number of threads: %w", err) } ch <- prometheus.MustNewConstMetric(c.threadLimit, prometheus.GaugeValue, float64(maxThreads)) @@ -91,7 +92,7 @@ func (c *processCollector) Update(ch chan<- prometheus.Metric) error { pidM, err := readUintFromFile(procFilePath("sys/kernel/pid_max")) if err != nil { - return fmt.Errorf("unable to retrieve limit number of maximum pids alloved: %q", err) + return fmt.Errorf("unable to retrieve limit number of maximum pids alloved: %w", err) } ch <- prometheus.MustNewConstMetric(c.pidUsed, prometheus.GaugeValue, float64(pids)) ch <- prometheus.MustNewConstMetric(c.pidMax, prometheus.GaugeValue, float64(pidM)) @@ -110,7 +111,7 @@ func (c *processCollector) getAllocatedThreads() (int, map[string]int32, int, er for _, pid := range p { stat, err := pid.Stat() // PIDs can vanish between getting the list and getting stats. - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "file not found when retrieving stats for pid", "pid", pid, "err", err) continue } diff --git a/collector/schedstat_linux.go b/collector/schedstat_linux.go index 9e5b744d..9f29a7e1 100644 --- a/collector/schedstat_linux.go +++ b/collector/schedstat_linux.go @@ -16,6 +16,7 @@ package collector import ( + "errors" "fmt" "os" @@ -72,7 +73,7 @@ func init() { func (c *schedstatCollector) Update(ch chan<- prometheus.Metric) error { stats, err := c.fs.Schedstat() if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "schedstat file does not exist") return ErrNoData } diff --git a/collector/sockstat_linux.go b/collector/sockstat_linux.go index c7596c9c..8f5a99fa 100644 --- a/collector/sockstat_linux.go +++ b/collector/sockstat_linux.go @@ -16,6 +16,7 @@ package collector import ( + "errors" "fmt" "os" @@ -55,7 +56,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { stat4, err := fs.NetSockstat() switch { case err == nil: - case os.IsNotExist(err): + case errors.Is(err, os.ErrNotExist): level.Debug(c.logger).Log("msg", "IPv4 sockstat statistics not found, skipping") default: return fmt.Errorf("failed to get IPv4 sockstat data: %w", err) @@ -64,7 +65,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { stat6, err := fs.NetSockstat6() switch { case err == nil: - case os.IsNotExist(err): + case errors.Is(err, os.ErrNotExist): level.Debug(c.logger).Log("msg", "IPv6 sockstat statistics not found, skipping") default: return fmt.Errorf("failed to get IPv6 sockstat data: %w", err) diff --git a/collector/softnet_linux.go b/collector/softnet_linux.go index e48f182c..befec8ed 100644 --- a/collector/softnet_linux.go +++ b/collector/softnet_linux.go @@ -72,7 +72,7 @@ func NewSoftnetCollector(logger log.Logger) (Collector, error) { func (c *softnetCollector) Update(ch chan<- prometheus.Metric) error { stats, err := c.fs.NetSoftnetStat() if err != nil { - return fmt.Errorf("could not get softnet statistics: %s", err) + return fmt.Errorf("could not get softnet statistics: %w", err) } for cpuNumber, cpuStats := range stats { diff --git a/collector/supervisord.go b/collector/supervisord.go index 33f3b8a1..6a6b9091 100644 --- a/collector/supervisord.go +++ b/collector/supervisord.go @@ -134,7 +134,7 @@ func (c *supervisordCollector) Update(ch chan<- prometheus.Metric) error { res, err := xrpc.Call("supervisor.getAllProcessInfo") if err != nil { - return fmt.Errorf("unable to call supervisord: %s", err) + return fmt.Errorf("unable to call supervisord: %w", err) } for _, p := range res.(xmlrpc.Array) { diff --git a/collector/systemd_linux.go b/collector/systemd_linux.go index 57e95945..b374b374 100644 --- a/collector/systemd_linux.go +++ b/collector/systemd_linux.go @@ -175,13 +175,13 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { begin := time.Now() conn, err := newSystemdDbusConn() if err != nil { - return fmt.Errorf("couldn't get dbus connection: %s", err) + return fmt.Errorf("couldn't get dbus connection: %w", err) } defer conn.Close() allUnits, err := c.getAllUnits(conn) if err != nil { - return fmt.Errorf("couldn't get units: %s", err) + return fmt.Errorf("couldn't get units: %w", err) } level.Debug(c.logger).Log("msg", "getAllUnits took", "duration_seconds", time.Since(begin).Seconds()) @@ -413,7 +413,7 @@ func (c *systemdCollector) collectSummaryMetrics(ch chan<- prometheus.Metric, su func (c *systemdCollector) collectSystemState(conn *dbus.Conn, ch chan<- prometheus.Metric) error { systemState, err := conn.GetManagerProperty("SystemState") if err != nil { - return fmt.Errorf("couldn't get system state: %s", err) + return fmt.Errorf("couldn't get system state: %w", err) } isSystemRunning := 0.0 if systemState == `"running"` { diff --git a/collector/tcpstat_linux.go b/collector/tcpstat_linux.go index db9c655f..af5ae981 100644 --- a/collector/tcpstat_linux.go +++ b/collector/tcpstat_linux.go @@ -82,7 +82,7 @@ func NewTCPStatCollector(logger log.Logger) (Collector, error) { func (c *tcpStatCollector) Update(ch chan<- prometheus.Metric) error { tcpStats, err := getTCPStats(procFilePath("net/tcp")) if err != nil { - return fmt.Errorf("couldn't get tcpstats: %s", err) + return fmt.Errorf("couldn't get tcpstats: %w", err) } // if enabled ipv6 system @@ -90,7 +90,7 @@ func (c *tcpStatCollector) Update(ch chan<- prometheus.Metric) error { if _, hasIPv6 := os.Stat(tcp6File); hasIPv6 == nil { tcp6Stats, err := getTCPStats(tcp6File) if err != nil { - return fmt.Errorf("couldn't get tcp6stats: %s", err) + return fmt.Errorf("couldn't get tcp6stats: %w", err) } for st, value := range tcp6Stats { diff --git a/collector/textfile.go b/collector/textfile.go index 64165e62..50c18075 100644 --- a/collector/textfile.go +++ b/collector/textfile.go @@ -238,14 +238,14 @@ func (c *textFileCollector) processFile(name string, ch chan<- prometheus.Metric path := filepath.Join(c.path, name) f, err := os.Open(path) if err != nil { - return nil, fmt.Errorf("failed to open textfile data file %q: %v", path, err) + return nil, fmt.Errorf("failed to open textfile data file %q: %w", path, err) } defer f.Close() var parser expfmt.TextParser families, err := parser.TextToMetricFamilies(f) if err != nil { - return nil, fmt.Errorf("failed to parse textfile data from %q: %v", path, err) + return nil, fmt.Errorf("failed to parse textfile data from %q: %w", path, err) } if hasTimestamps(families) { @@ -267,7 +267,7 @@ func (c *textFileCollector) processFile(name string, ch chan<- prometheus.Metric // a failure does not appear fresh. stat, err := f.Stat() if err != nil { - return nil, fmt.Errorf("failed to stat %q: %v", path, err) + return nil, fmt.Errorf("failed to stat %q: %w", path, err) } t := stat.ModTime() diff --git a/collector/udp_queues_linux.go b/collector/udp_queues_linux.go index 512c0100..e1b347ed 100644 --- a/collector/udp_queues_linux.go +++ b/collector/udp_queues_linux.go @@ -16,6 +16,7 @@ package collector import ( + "errors" "fmt" "os" @@ -41,7 +42,7 @@ func init() { func NewUDPqueuesCollector(logger log.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { - return nil, fmt.Errorf("failed to open procfs: %v", err) + return nil, fmt.Errorf("failed to open procfs: %w", err) } return &udpQueuesCollector{ fs: fs, @@ -61,10 +62,10 @@ func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error { ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.TxQueueLength), "tx", "v4") ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.RxQueueLength), "rx", "v4") } else { - if os.IsNotExist(errIPv4) { + if errors.Is(errIPv4, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "not collecting ipv4 based metrics") } else { - return fmt.Errorf("couldn't get upd queued bytes: %s", errIPv4) + return fmt.Errorf("couldn't get upd queued bytes: %w", errIPv4) } } @@ -73,14 +74,14 @@ func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error { ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.TxQueueLength), "tx", "v6") ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.RxQueueLength), "rx", "v6") } else { - if os.IsNotExist(errIPv6) { + if errors.Is(errIPv6, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "not collecting ipv6 based metrics") } else { - return fmt.Errorf("couldn't get upd6 queued bytes: %s", errIPv6) + return fmt.Errorf("couldn't get upd6 queued bytes: %w", errIPv6) } } - if os.IsNotExist(errIPv4) && os.IsNotExist(errIPv6) { + if errors.Is(errIPv4, os.ErrNotExist) && errors.Is(errIPv6, os.ErrNotExist) { return ErrNoData } return nil diff --git a/collector/wifi_linux.go b/collector/wifi_linux.go index b4b37593..076982d7 100644 --- a/collector/wifi_linux.go +++ b/collector/wifi_linux.go @@ -17,6 +17,7 @@ package collector import ( "encoding/json" + "errors" "fmt" "io/ioutil" "os" @@ -167,11 +168,11 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { stat, err := newWifiStater(*collectorWifi) if err != nil { // Cannot access wifi metrics, report no error. - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system") return ErrNoData } - if os.IsPermission(err) { + if errors.Is(err, os.ErrPermission) { level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics") return ErrNoData } @@ -201,14 +202,14 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { ) // When a statistic is not available for a given interface, package wifi - // returns an error compatible with os.IsNotExist. We leverage this to - // only export metrics which are actually valid for given interface types. + // returns a os.ErrNotExist error. We leverage this to only export + // metrics which are actually valid for given interface types. bss, err := stat.BSS(ifi) switch { case err == nil: c.updateBSSStats(ch, ifi.Name, bss) - case os.IsNotExist(err): + case errors.Is(err, os.ErrNotExist): level.Debug(c.logger).Log("msg", "BSS information not found for wifi device", "name", ifi.Name) default: return fmt.Errorf("failed to retrieve BSS for device %s: %v", @@ -221,7 +222,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { for _, station := range stations { c.updateStationStats(ch, ifi.Name, station) } - case os.IsNotExist(err): + case errors.Is(err, os.ErrNotExist): level.Debug(c.logger).Log("msg", "station information not found for wifi device", "name", ifi.Name) default: return fmt.Errorf("failed to retrieve station info for device %q: %v", diff --git a/collector/zfs_freebsd.go b/collector/zfs_freebsd.go index 92661e43..2f200967 100644 --- a/collector/zfs_freebsd.go +++ b/collector/zfs_freebsd.go @@ -250,7 +250,7 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error { for _, m := range c.sysctls { v, err := m.Value() if err != nil { - return fmt.Errorf("couldn't get sysctl: %s", err) + return fmt.Errorf("couldn't get sysctl: %w", err) } ch <- prometheus.MustNewConstMetric( diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go index 2449c263..f55d98a5 100644 --- a/collector/zfs_linux.go +++ b/collector/zfs_linux.go @@ -187,7 +187,7 @@ func (c *zfsCollector) parsePoolProcfsFile(reader io.Reader, zpoolPath string, h value, err := strconv.ParseUint(line[i], 10, 64) if err != nil { - return fmt.Errorf("could not parse expected integer value for %q: %v", key, err) + return fmt.Errorf("could not parse expected integer value for %q: %w", key, err) } handler(zpoolName, zfsSysctl(key), value) }