diff options
author | Ben Kochie <superq@gmail.com> | 2020-06-15 22:27:14 +0200 |
---|---|---|
committer | Ben Kochie <superq@gmail.com> | 2020-06-16 14:47:03 +0200 |
commit | dfa53f835a2916d8fa6d72f28d7d9d0617cbdbdb (patch) | |
tree | 15025568f0d4c2ea666ad1c473ae97942eb6bfa1 | |
parent | 3799895d414ef94822df11a80fe60565fc8bbd07 (diff) | |
download | prometheus_node_collector-dfa53f835a2916d8fa6d72f28d7d9d0617cbdbdb.tar.bz2 prometheus_node_collector-dfa53f835a2916d8fa6d72f28d7d9d0617cbdbdb.tar.xz prometheus_node_collector-dfa53f835a2916d8fa6d72f28d7d9d0617cbdbdb.zip |
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 <superq@gmail.com>
44 files changed, 107 insertions, 93 deletions
diff --git a/collector/arp_linux.go b/collector/arp_linux.go index 6a18879..86cb78a 100644 --- a/collector/arp_linux.go +++ b/collector/arp_linux.go | |||
@@ -84,7 +84,7 @@ func parseARPEntries(data io.Reader) (map[string]uint32, error) { | |||
84 | } | 84 | } |
85 | 85 | ||
86 | if err := scanner.Err(); err != nil { | 86 | if err := scanner.Err(); err != nil { |
87 | return nil, fmt.Errorf("failed to parse ARP info: %s", err) | 87 | return nil, fmt.Errorf("failed to parse ARP info: %w", err) |
88 | } | 88 | } |
89 | 89 | ||
90 | return entries, nil | 90 | return entries, nil |
@@ -93,7 +93,7 @@ func parseARPEntries(data io.Reader) (map[string]uint32, error) { | |||
93 | func (c *arpCollector) Update(ch chan<- prometheus.Metric) error { | 93 | func (c *arpCollector) Update(ch chan<- prometheus.Metric) error { |
94 | entries, err := getARPEntries() | 94 | entries, err := getARPEntries() |
95 | if err != nil { | 95 | if err != nil { |
96 | return fmt.Errorf("could not get ARP entries: %s", err) | 96 | return fmt.Errorf("could not get ARP entries: %w", err) |
97 | } | 97 | } |
98 | 98 | ||
99 | for device, entryCount := range entries { | 99 | for device, entryCount := range entries { |
diff --git a/collector/bonding_linux.go b/collector/bonding_linux.go index 78e94b2..863f62c 100644 --- a/collector/bonding_linux.go +++ b/collector/bonding_linux.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "errors" | ||
19 | "fmt" | 20 | "fmt" |
20 | "io/ioutil" | 21 | "io/ioutil" |
21 | "os" | 22 | "os" |
@@ -59,7 +60,7 @@ func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error { | |||
59 | statusfile := sysFilePath("class/net") | 60 | statusfile := sysFilePath("class/net") |
60 | bondingStats, err := readBondingStats(statusfile) | 61 | bondingStats, err := readBondingStats(statusfile) |
61 | if err != nil { | 62 | if err != nil { |
62 | if os.IsNotExist(err) { | 63 | if errors.Is(err, os.ErrNotExist) { |
63 | level.Debug(c.logger).Log("msg", "Not collecting bonding, file does not exist", "file", statusfile) | 64 | level.Debug(c.logger).Log("msg", "Not collecting bonding, file does not exist", "file", statusfile) |
64 | return ErrNoData | 65 | return ErrNoData |
65 | } | 66 | } |
@@ -86,7 +87,7 @@ func readBondingStats(root string) (status map[string][2]int, err error) { | |||
86 | sstat := [2]int{0, 0} | 87 | sstat := [2]int{0, 0} |
87 | for _, slave := range strings.Fields(string(slaves)) { | 88 | for _, slave := range strings.Fields(string(slaves)) { |
88 | state, err := ioutil.ReadFile(filepath.Join(root, master, fmt.Sprintf("lower_%s", slave), "bonding_slave", "mii_status")) | 89 | state, err := ioutil.ReadFile(filepath.Join(root, master, fmt.Sprintf("lower_%s", slave), "bonding_slave", "mii_status")) |
89 | if os.IsNotExist(err) { | 90 | if errors.Is(err, os.ErrNotExist) { |
90 | // some older? kernels use slave_ prefix | 91 | // some older? kernels use slave_ prefix |
91 | state, err = ioutil.ReadFile(filepath.Join(root, master, fmt.Sprintf("slave_%s", slave), "bonding_slave", "mii_status")) | 92 | state, err = ioutil.ReadFile(filepath.Join(root, master, fmt.Sprintf("slave_%s", slave), "bonding_slave", "mii_status")) |
92 | } | 93 | } |
diff --git a/collector/btrfs_linux.go b/collector/btrfs_linux.go index 2336e65..4d4857b 100644 --- a/collector/btrfs_linux.go +++ b/collector/btrfs_linux.go | |||
@@ -37,7 +37,7 @@ func init() { | |||
37 | func NewBtrfsCollector(logger log.Logger) (Collector, error) { | 37 | func NewBtrfsCollector(logger log.Logger) (Collector, error) { |
38 | fs, err := btrfs.NewFS(*sysPath) | 38 | fs, err := btrfs.NewFS(*sysPath) |
39 | if err != nil { | 39 | if err != nil { |
40 | return nil, fmt.Errorf("failed to open sysfs: %v", err) | 40 | return nil, fmt.Errorf("failed to open sysfs: %w", err) |
41 | } | 41 | } |
42 | 42 | ||
43 | return &btrfsCollector{ | 43 | return &btrfsCollector{ |
@@ -51,7 +51,7 @@ func NewBtrfsCollector(logger log.Logger) (Collector, error) { | |||
51 | func (c *btrfsCollector) Update(ch chan<- prometheus.Metric) error { | 51 | func (c *btrfsCollector) Update(ch chan<- prometheus.Metric) error { |
52 | stats, err := c.fs.Stats() | 52 | stats, err := c.fs.Stats() |
53 | if err != nil { | 53 | if err != nil { |
54 | return fmt.Errorf("failed to retrieve Btrfs stats: %v", err) | 54 | return fmt.Errorf("failed to retrieve Btrfs stats: %w", err) |
55 | } | 55 | } |
56 | 56 | ||
57 | for _, s := range stats { | 57 | for _, s := range stats { |
diff --git a/collector/buddyinfo.go b/collector/buddyinfo.go index e94e283..579c3e4 100644 --- a/collector/buddyinfo.go +++ b/collector/buddyinfo.go | |||
@@ -59,7 +59,7 @@ func NewBuddyinfoCollector(logger log.Logger) (Collector, error) { | |||
59 | func (c *buddyinfoCollector) Update(ch chan<- prometheus.Metric) error { | 59 | func (c *buddyinfoCollector) Update(ch chan<- prometheus.Metric) error { |
60 | buddyInfo, err := c.fs.BuddyInfo() | 60 | buddyInfo, err := c.fs.BuddyInfo() |
61 | if err != nil { | 61 | if err != nil { |
62 | return fmt.Errorf("couldn't get buddyinfo: %s", err) | 62 | return fmt.Errorf("couldn't get buddyinfo: %w", err) |
63 | } | 63 | } |
64 | 64 | ||
65 | level.Debug(c.logger).Log("msg", "Set node_buddy", "buddyInfo", buddyInfo) | 65 | level.Debug(c.logger).Log("msg", "Set node_buddy", "buddyInfo", buddyInfo) |
diff --git a/collector/diskstats_darwin.go b/collector/diskstats_darwin.go index 89622a3..864220b 100644 --- a/collector/diskstats_darwin.go +++ b/collector/diskstats_darwin.go | |||
@@ -189,7 +189,7 @@ func NewDiskstatsCollector(logger log.Logger) (Collector, error) { | |||
189 | func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { | 189 | func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { |
190 | diskStats, err := iostat.ReadDriveStats() | 190 | diskStats, err := iostat.ReadDriveStats() |
191 | if err != nil { | 191 | if err != nil { |
192 | return fmt.Errorf("couldn't get diskstats: %s", err) | 192 | return fmt.Errorf("couldn't get diskstats: %w", err) |
193 | } | 193 | } |
194 | 194 | ||
195 | for _, stats := range diskStats { | 195 | for _, stats := range diskStats { |
diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go index 5d71422..b5ae82d 100644 --- a/collector/diskstats_linux.go +++ b/collector/diskstats_linux.go | |||
@@ -187,7 +187,7 @@ func NewDiskstatsCollector(logger log.Logger) (Collector, error) { | |||
187 | func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { | 187 | func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { |
188 | diskStats, err := getDiskStats() | 188 | diskStats, err := getDiskStats() |
189 | if err != nil { | 189 | if err != nil { |
190 | return fmt.Errorf("couldn't get diskstats: %s", err) | 190 | return fmt.Errorf("couldn't get diskstats: %w", err) |
191 | } | 191 | } |
192 | 192 | ||
193 | for dev, stats := range diskStats { | 193 | for dev, stats := range diskStats { |
@@ -203,7 +203,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { | |||
203 | } | 203 | } |
204 | v, err := strconv.ParseFloat(value, 64) | 204 | v, err := strconv.ParseFloat(value, 64) |
205 | if err != nil { | 205 | if err != nil { |
206 | return fmt.Errorf("invalid value %s in diskstats: %s", value, err) | 206 | return fmt.Errorf("invalid value %s in diskstats: %w", value, err) |
207 | } | 207 | } |
208 | ch <- c.descs[i].mustNewConstMetric(v, dev) | 208 | ch <- c.descs[i].mustNewConstMetric(v, dev) |
209 | } | 209 | } |
diff --git a/collector/drbd_linux.go b/collector/drbd_linux.go index 4beb31d..281c079 100644 --- a/collector/drbd_linux.go +++ b/collector/drbd_linux.go | |||
@@ -17,6 +17,7 @@ package collector | |||
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "bufio" | 19 | "bufio" |
20 | "errors" | ||
20 | "fmt" | 21 | "fmt" |
21 | "os" | 22 | "os" |
22 | "strconv" | 23 | "strconv" |
@@ -188,7 +189,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error { | |||
188 | statsFile := procFilePath("drbd") | 189 | statsFile := procFilePath("drbd") |
189 | file, err := os.Open(statsFile) | 190 | file, err := os.Open(statsFile) |
190 | if err != nil { | 191 | if err != nil { |
191 | if os.IsNotExist(err) { | 192 | if errors.Is(err, os.ErrNotExist) { |
192 | level.Debug(c.logger).Log("msg", "stats file does not exist, skipping", "file", statsFile, "err", err) | 193 | level.Debug(c.logger).Log("msg", "stats file does not exist, skipping", "file", statsFile, "err", err) |
193 | return ErrNoData | 194 | return ErrNoData |
194 | } | 195 | } |
diff --git a/collector/edac_linux.go b/collector/edac_linux.go index 91b9510..1248e2e 100644 --- a/collector/edac_linux.go +++ b/collector/edac_linux.go | |||
@@ -86,28 +86,28 @@ func (c *edacCollector) Update(ch chan<- prometheus.Metric) error { | |||
86 | 86 | ||
87 | value, err := readUintFromFile(filepath.Join(controller, "ce_count")) | 87 | value, err := readUintFromFile(filepath.Join(controller, "ce_count")) |
88 | if err != nil { | 88 | if err != nil { |
89 | return fmt.Errorf("couldn't get ce_count for controller %s: %s", controllerNumber, err) | 89 | return fmt.Errorf("couldn't get ce_count for controller %s: %w", controllerNumber, err) |
90 | } | 90 | } |
91 | ch <- prometheus.MustNewConstMetric( | 91 | ch <- prometheus.MustNewConstMetric( |
92 | c.ceCount, prometheus.CounterValue, float64(value), controllerNumber) | 92 | c.ceCount, prometheus.CounterValue, float64(value), controllerNumber) |
93 | 93 | ||
94 | value, err = readUintFromFile(filepath.Join(controller, "ce_noinfo_count")) | 94 | value, err = readUintFromFile(filepath.Join(controller, "ce_noinfo_count")) |
95 | if err != nil { | 95 | if err != nil { |
96 | return fmt.Errorf("couldn't get ce_noinfo_count for controller %s: %s", controllerNumber, err) | 96 | return fmt.Errorf("couldn't get ce_noinfo_count for controller %s: %w", controllerNumber, err) |
97 | } | 97 | } |
98 | ch <- prometheus.MustNewConstMetric( | 98 | ch <- prometheus.MustNewConstMetric( |
99 | c.csRowCECount, prometheus.CounterValue, float64(value), controllerNumber, "unknown") | 99 | c.csRowCECount, prometheus.CounterValue, float64(value), controllerNumber, "unknown") |
100 | 100 | ||
101 | value, err = readUintFromFile(filepath.Join(controller, "ue_count")) | 101 | value, err = readUintFromFile(filepath.Join(controller, "ue_count")) |
102 | if err != nil { | 102 | if err != nil { |
103 | return fmt.Errorf("couldn't get ue_count for controller %s: %s", controllerNumber, err) | 103 | return fmt.Errorf("couldn't get ue_count for controller %s: %w", controllerNumber, err) |
104 | } | 104 | } |
105 | ch <- prometheus.MustNewConstMetric( | 105 | ch <- prometheus.MustNewConstMetric( |
106 | c.ueCount, prometheus.CounterValue, float64(value), controllerNumber) | 106 | c.ueCount, prometheus.CounterValue, float64(value), controllerNumber) |
107 | 107 | ||
108 | value, err = readUintFromFile(filepath.Join(controller, "ue_noinfo_count")) | 108 | value, err = readUintFromFile(filepath.Join(controller, "ue_noinfo_count")) |
109 | if err != nil { | 109 | if err != nil { |
110 | return fmt.Errorf("couldn't get ue_noinfo_count for controller %s: %s", controllerNumber, err) | 110 | return fmt.Errorf("couldn't get ue_noinfo_count for controller %s: %w", controllerNumber, err) |
111 | } | 111 | } |
112 | ch <- prometheus.MustNewConstMetric( | 112 | ch <- prometheus.MustNewConstMetric( |
113 | c.csRowUECount, prometheus.CounterValue, float64(value), controllerNumber, "unknown") | 113 | c.csRowUECount, prometheus.CounterValue, float64(value), controllerNumber, "unknown") |
@@ -126,14 +126,14 @@ func (c *edacCollector) Update(ch chan<- prometheus.Metric) error { | |||
126 | 126 | ||
127 | value, err = readUintFromFile(filepath.Join(csrow, "ce_count")) | 127 | value, err = readUintFromFile(filepath.Join(csrow, "ce_count")) |
128 | if err != nil { | 128 | if err != nil { |
129 | return fmt.Errorf("couldn't get ce_count for controller/csrow %s/%s: %s", controllerNumber, csrowNumber, err) | 129 | return fmt.Errorf("couldn't get ce_count for controller/csrow %s/%s: %w", controllerNumber, csrowNumber, err) |
130 | } | 130 | } |
131 | ch <- prometheus.MustNewConstMetric( | 131 | ch <- prometheus.MustNewConstMetric( |
132 | c.csRowCECount, prometheus.CounterValue, float64(value), controllerNumber, csrowNumber) | 132 | c.csRowCECount, prometheus.CounterValue, float64(value), controllerNumber, csrowNumber) |
133 | 133 | ||
134 | value, err = readUintFromFile(filepath.Join(csrow, "ue_count")) | 134 | value, err = readUintFromFile(filepath.Join(csrow, "ue_count")) |
135 | if err != nil { | 135 | if err != nil { |
136 | return fmt.Errorf("couldn't get ue_count for controller/csrow %s/%s: %s", controllerNumber, csrowNumber, err) | 136 | return fmt.Errorf("couldn't get ue_count for controller/csrow %s/%s: %w", controllerNumber, csrowNumber, err) |
137 | } | 137 | } |
138 | ch <- prometheus.MustNewConstMetric( | 138 | ch <- prometheus.MustNewConstMetric( |
139 | c.csRowUECount, prometheus.CounterValue, float64(value), controllerNumber, csrowNumber) | 139 | c.csRowUECount, prometheus.CounterValue, float64(value), controllerNumber, csrowNumber) |
diff --git a/collector/entropy_linux.go b/collector/entropy_linux.go index e68eb95..3c42c3d 100644 --- a/collector/entropy_linux.go +++ b/collector/entropy_linux.go | |||
@@ -46,7 +46,7 @@ func NewEntropyCollector(logger log.Logger) (Collector, error) { | |||
46 | func (c *entropyCollector) Update(ch chan<- prometheus.Metric) error { | 46 | func (c *entropyCollector) Update(ch chan<- prometheus.Metric) error { |
47 | value, err := readUintFromFile(procFilePath("sys/kernel/random/entropy_avail")) | 47 | value, err := readUintFromFile(procFilePath("sys/kernel/random/entropy_avail")) |
48 | if err != nil { | 48 | if err != nil { |
49 | return fmt.Errorf("couldn't get entropy_avail: %s", err) | 49 | return fmt.Errorf("couldn't get entropy_avail: %w", err) |
50 | } | 50 | } |
51 | ch <- prometheus.MustNewConstMetric( | 51 | ch <- prometheus.MustNewConstMetric( |
52 | c.entropyAvail, prometheus.GaugeValue, float64(value)) | 52 | c.entropyAvail, prometheus.GaugeValue, float64(value)) |
diff --git a/collector/filefd_linux.go b/collector/filefd_linux.go index f8d3fce..450c4e3 100644 --- a/collector/filefd_linux.go +++ b/collector/filefd_linux.go | |||
@@ -46,12 +46,12 @@ func NewFileFDStatCollector(logger log.Logger) (Collector, error) { | |||
46 | func (c *fileFDStatCollector) Update(ch chan<- prometheus.Metric) error { | 46 | func (c *fileFDStatCollector) Update(ch chan<- prometheus.Metric) error { |
47 | fileFDStat, err := parseFileFDStats(procFilePath("sys/fs/file-nr")) | 47 | fileFDStat, err := parseFileFDStats(procFilePath("sys/fs/file-nr")) |
48 | if err != nil { | 48 | if err != nil { |
49 | return fmt.Errorf("couldn't get file-nr: %s", err) | 49 | return fmt.Errorf("couldn't get file-nr: %w", err) |
50 | } | 50 | } |
51 | for name, value := range fileFDStat { | 51 | for name, value := range fileFDStat { |
52 | v, err := strconv.ParseFloat(value, 64) | 52 | v, err := strconv.ParseFloat(value, 64) |
53 | if err != nil { | 53 | if err != nil { |
54 | return fmt.Errorf("invalid value %s in file-nr: %s", value, err) | 54 | return fmt.Errorf("invalid value %s in file-nr: %w", value, err) |
55 | } | 55 | } |
56 | ch <- prometheus.MustNewConstMetric( | 56 | ch <- prometheus.MustNewConstMetric( |
57 | prometheus.NewDesc( | 57 | prometheus.NewDesc( |
diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index e83b27a..00a7323 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go | |||
@@ -17,6 +17,7 @@ package collector | |||
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "bufio" | 19 | "bufio" |
20 | "errors" | ||
20 | "fmt" | 21 | "fmt" |
21 | "io" | 22 | "io" |
22 | "os" | 23 | "os" |
@@ -139,7 +140,7 @@ func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logg | |||
139 | 140 | ||
140 | func mountPointDetails(logger log.Logger) ([]filesystemLabels, error) { | 141 | func mountPointDetails(logger log.Logger) ([]filesystemLabels, error) { |
141 | file, err := os.Open(procFilePath("1/mounts")) | 142 | file, err := os.Open(procFilePath("1/mounts")) |
142 | if os.IsNotExist(err) { | 143 | if errors.Is(err, os.ErrNotExist) { |
143 | // Fallback to `/proc/mounts` if `/proc/1/mounts` is missing due hidepid. | 144 | // Fallback to `/proc/mounts` if `/proc/1/mounts` is missing due hidepid. |
144 | level.Debug(logger).Log("msg", "Reading root mounts failed, falling back to system mounts", "err", err) | 145 | level.Debug(logger).Log("msg", "Reading root mounts failed, falling back to system mounts", "err", err) |
145 | file, err = os.Open(procFilePath("mounts")) | 146 | file, err = os.Open(procFilePath("mounts")) |
diff --git a/collector/hwmon_linux.go b/collector/hwmon_linux.go index 5649942..261a7c5 100644 --- a/collector/hwmon_linux.go +++ b/collector/hwmon_linux.go | |||
@@ -424,7 +424,7 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error { | |||
424 | 424 | ||
425 | hwmonFiles, err := ioutil.ReadDir(hwmonPathName) | 425 | hwmonFiles, err := ioutil.ReadDir(hwmonPathName) |
426 | if err != nil { | 426 | if err != nil { |
427 | if os.IsNotExist(err) { | 427 | if errors.Is(err, os.ErrNotExist) { |
428 | level.Debug(c.logger).Log("msg", "hwmon collector metrics are not available for this system") | 428 | level.Debug(c.logger).Log("msg", "hwmon collector metrics are not available for this system") |
429 | return ErrNoData | 429 | return ErrNoData |
430 | } | 430 | } |
diff --git a/collector/infiniband_linux.go b/collector/infiniband_linux.go index 1f453b8..d938210 100644 --- a/collector/infiniband_linux.go +++ b/collector/infiniband_linux.go | |||
@@ -17,6 +17,7 @@ | |||
17 | package collector | 17 | package collector |
18 | 18 | ||
19 | import ( | 19 | import ( |
20 | "errors" | ||
20 | "fmt" | 21 | "fmt" |
21 | "os" | 22 | "os" |
22 | "strconv" | 23 | "strconv" |
@@ -108,11 +109,11 @@ func (c *infinibandCollector) pushCounter(ch chan<- prometheus.Metric, name stri | |||
108 | func (c *infinibandCollector) Update(ch chan<- prometheus.Metric) error { | 109 | func (c *infinibandCollector) Update(ch chan<- prometheus.Metric) error { |
109 | devices, err := c.fs.InfiniBandClass() | 110 | devices, err := c.fs.InfiniBandClass() |
110 | if err != nil { | 111 | if err != nil { |
111 | if os.IsNotExist(err) { | 112 | if errors.Is(err, os.ErrNotExist) { |
112 | level.Debug(c.logger).Log("msg", "infiniband statistics not found, skipping") | 113 | level.Debug(c.logger).Log("msg", "infiniband statistics not found, skipping") |
113 | return ErrNoData | 114 | return ErrNoData |
114 | } | 115 | } |
115 | return fmt.Errorf("error obtaining InfiniBand class info: %s", err) | 116 | return fmt.Errorf("error obtaining InfiniBand class info: %w", err) |
116 | } | 117 | } |
117 | 118 | ||
118 | for _, device := range devices { | 119 | for _, device := range devices { |
diff --git a/collector/interrupts_linux.go b/collector/interrupts_linux.go index cacfeda..5fcbebc 100644 --- a/collector/interrupts_linux.go +++ b/collector/interrupts_linux.go | |||
@@ -34,13 +34,13 @@ var ( | |||
34 | func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) (err error) { | 34 | func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) (err error) { |
35 | interrupts, err := getInterrupts() | 35 | interrupts, err := getInterrupts() |
36 | if err != nil { | 36 | if err != nil { |
37 | return fmt.Errorf("couldn't get interrupts: %s", err) | 37 | return fmt.Errorf("couldn't get interrupts: %w", err) |
38 | } | 38 | } |
39 | for name, interrupt := range interrupts { | 39 | for name, interrupt := range interrupts { |
40 | for cpuNo, value := range interrupt.values { | 40 | for cpuNo, value := range interrupt.values { |
41 | fv, err := strconv.ParseFloat(value, 64) | 41 | fv, err := strconv.ParseFloat(value, 64) |
42 | if err != nil { | 42 | if err != nil { |
43 | return fmt.Errorf("invalid value %s in interrupts: %s", value, err) | 43 | return fmt.Errorf("invalid value %s in interrupts: %w", value, err) |
44 | } | 44 | } |
45 | ch <- c.desc.mustNewConstMetric(fv, strconv.Itoa(cpuNo), name, interrupt.info, interrupt.devices) | 45 | ch <- c.desc.mustNewConstMetric(fv, strconv.Itoa(cpuNo), name, interrupt.info, interrupt.devices) |
46 | } | 46 | } |
diff --git a/collector/interrupts_openbsd.go b/collector/interrupts_openbsd.go index c9aae3c..bf38fe3 100644 --- a/collector/interrupts_openbsd.go +++ b/collector/interrupts_openbsd.go | |||
@@ -101,7 +101,7 @@ var ( | |||
101 | func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) error { | 101 | func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) error { |
102 | interrupts, err := getInterrupts() | 102 | interrupts, err := getInterrupts() |
103 | if err != nil { | 103 | if err != nil { |
104 | return fmt.Errorf("couldn't get interrupts: %s", err) | 104 | return fmt.Errorf("couldn't get interrupts: %w", err) |
105 | } | 105 | } |
106 | for dev, interrupt := range interrupts { | 106 | for dev, interrupt := range interrupts { |
107 | for cpuNo, value := range interrupt.values { | 107 | for cpuNo, value := range interrupt.values { |
diff --git a/collector/ipvs_linux.go b/collector/ipvs_linux.go index b5c8d73..c2e9d70 100644 --- a/collector/ipvs_linux.go +++ b/collector/ipvs_linux.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "errors" | ||
19 | "fmt" | 20 | "fmt" |
20 | "os" | 21 | "os" |
21 | "sort" | 22 | "sort" |
@@ -140,11 +141,11 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error { | |||
140 | ipvsStats, err := c.fs.IPVSStats() | 141 | ipvsStats, err := c.fs.IPVSStats() |
141 | if err != nil { | 142 | if err != nil { |
142 | // Cannot access ipvs metrics, report no error. | 143 | // Cannot access ipvs metrics, report no error. |
143 | if os.IsNotExist(err) { | 144 | if errors.Is(err, os.ErrNotExist) { |
144 | level.Debug(c.logger).Log("msg", "ipvs collector metrics are not available for this system") | 145 | level.Debug(c.logger).Log("msg", "ipvs collector metrics are not available for this system") |
145 | return ErrNoData | 146 | return ErrNoData |
146 | } | 147 | } |
147 | return fmt.Errorf("could not get IPVS stats: %s", err) | 148 | return fmt.Errorf("could not get IPVS stats: %w", err) |
148 | } | 149 | } |
149 | ch <- c.connections.mustNewConstMetric(float64(ipvsStats.Connections)) | 150 | ch <- c.connections.mustNewConstMetric(float64(ipvsStats.Connections)) |
150 | ch <- c.incomingPackets.mustNewConstMetric(float64(ipvsStats.IncomingPackets)) | 151 | ch <- c.incomingPackets.mustNewConstMetric(float64(ipvsStats.IncomingPackets)) |
@@ -154,7 +155,7 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error { | |||
154 | 155 | ||
155 | backendStats, err := c.fs.IPVSBackendStatus() | 156 | backendStats, err := c.fs.IPVSBackendStatus() |
156 | if err != nil { | 157 | if err != nil { |
157 | return fmt.Errorf("could not get backend status: %s", err) | 158 | return fmt.Errorf("could not get backend status: %w", err) |
158 | } | 159 | } |
159 | 160 | ||
160 | sums := map[string]ipvsBackendStatus{} | 161 | sums := map[string]ipvsBackendStatus{} |
diff --git a/collector/loadavg.go b/collector/loadavg.go index 7c8bcff..7c1fd99 100644 --- a/collector/loadavg.go +++ b/collector/loadavg.go | |||
@@ -48,7 +48,7 @@ func NewLoadavgCollector(logger log.Logger) (Collector, error) { | |||
48 | func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) error { | 48 | func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) error { |
49 | loads, err := getLoad() | 49 | loads, err := getLoad() |
50 | if err != nil { | 50 | if err != nil { |
51 | return fmt.Errorf("couldn't get load: %s", err) | 51 | return fmt.Errorf("couldn't get load: %w", err) |
52 | } | 52 | } |
53 | for i, load := range loads { | 53 | for i, load := range loads { |
54 | level.Debug(c.logger).Log("msg", "return load", "index", i, "load", load) | 54 | 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 668d3ed..7b89668 100644 --- a/collector/loadavg_linux.go +++ b/collector/loadavg_linux.go | |||
@@ -45,7 +45,7 @@ func parseLoad(data string) (loads []float64, err error) { | |||
45 | for i, load := range parts[0:3] { | 45 | for i, load := range parts[0:3] { |
46 | loads[i], err = strconv.ParseFloat(load, 64) | 46 | loads[i], err = strconv.ParseFloat(load, 64) |
47 | if err != nil { | 47 | if err != nil { |
48 | return nil, fmt.Errorf("could not parse load '%s': %s", load, err) | 48 | return nil, fmt.Errorf("could not parse load '%s': %w", load, err) |
49 | } | 49 | } |
50 | } | 50 | } |
51 | return loads, nil | 51 | return loads, nil |
diff --git a/collector/logind_linux.go b/collector/logind_linux.go index fb3cb57..19a29a2 100644 --- a/collector/logind_linux.go +++ b/collector/logind_linux.go | |||
@@ -92,7 +92,7 @@ func NewLogindCollector(logger log.Logger) (Collector, error) { | |||
92 | func (lc *logindCollector) Update(ch chan<- prometheus.Metric) error { | 92 | func (lc *logindCollector) Update(ch chan<- prometheus.Metric) error { |
93 | c, err := newDbus() | 93 | c, err := newDbus() |
94 | if err != nil { | 94 | if err != nil { |
95 | return fmt.Errorf("unable to connect to dbus: %s", err) | 95 | return fmt.Errorf("unable to connect to dbus: %w", err) |
96 | } | 96 | } |
97 | defer c.conn.Close() | 97 | defer c.conn.Close() |
98 | 98 | ||
@@ -102,12 +102,12 @@ func (lc *logindCollector) Update(ch chan<- prometheus.Metric) error { | |||
102 | func collectMetrics(ch chan<- prometheus.Metric, c logindInterface) error { | 102 | func collectMetrics(ch chan<- prometheus.Metric, c logindInterface) error { |
103 | seats, err := c.listSeats() | 103 | seats, err := c.listSeats() |
104 | if err != nil { | 104 | if err != nil { |
105 | return fmt.Errorf("unable to get seats: %s", err) | 105 | return fmt.Errorf("unable to get seats: %w", err) |
106 | } | 106 | } |
107 | 107 | ||
108 | sessionList, err := c.listSessions() | 108 | sessionList, err := c.listSessions() |
109 | if err != nil { | 109 | if err != nil { |
110 | return fmt.Errorf("unable to get sessions: %s", err) | 110 | return fmt.Errorf("unable to get sessions: %w", err) |
111 | } | 111 | } |
112 | 112 | ||
113 | sessions := make(map[logindSession]float64) | 113 | sessions := make(map[logindSession]float64) |
diff --git a/collector/mdadm_linux.go b/collector/mdadm_linux.go index 05f83ee..865553f 100644 --- a/collector/mdadm_linux.go +++ b/collector/mdadm_linux.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "errors" | ||
19 | "fmt" | 20 | "fmt" |
20 | "os" | 21 | "os" |
21 | 22 | ||
@@ -94,21 +95,21 @@ var ( | |||
94 | ) | 95 | ) |
95 | 96 | ||
96 | func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error { | 97 | func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error { |
97 | fs, errFs := procfs.NewFS(*procPath) | 98 | fs, err := procfs.NewFS(*procPath) |
98 | 99 | ||
99 | if errFs != nil { | 100 | if err != nil { |
100 | return fmt.Errorf("failed to open procfs: %w", errFs) | 101 | return fmt.Errorf("failed to open procfs: %w", err) |
101 | } | 102 | } |
102 | 103 | ||
103 | mdStats, err := fs.MDStat() | 104 | mdStats, err := fs.MDStat() |
104 | 105 | ||
105 | if err != nil { | 106 | if err != nil { |
106 | if os.IsNotExist(err) { | 107 | if errors.Is(err, os.ErrNotExist) { |
107 | level.Debug(c.logger).Log("msg", "Not collecting mdstat, file does not exist", "file", *procPath) | 108 | level.Debug(c.logger).Log("msg", "Not collecting mdstat, file does not exist", "file", *procPath) |
108 | return ErrNoData | 109 | return ErrNoData |
109 | } | 110 | } |
110 | 111 | ||
111 | return fmt.Errorf("error parsing mdstatus: %s", err) | 112 | return fmt.Errorf("error parsing mdstatus: %w", err) |
112 | } | 113 | } |
113 | 114 | ||
114 | for _, mdStat := range mdStats { | 115 | for _, mdStat := range mdStats { |
diff --git a/collector/meminfo.go b/collector/meminfo.go index d3d3b8d..38b2326 100644 --- a/collector/meminfo.go +++ b/collector/meminfo.go | |||
@@ -48,7 +48,7 @@ func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error { | |||
48 | var metricType prometheus.ValueType | 48 | var metricType prometheus.ValueType |
49 | memInfo, err := c.getMemInfo() | 49 | memInfo, err := c.getMemInfo() |
50 | if err != nil { | 50 | if err != nil { |
51 | return fmt.Errorf("couldn't get meminfo: %s", err) | 51 | return fmt.Errorf("couldn't get meminfo: %w", err) |
52 | } | 52 | } |
53 | level.Debug(c.logger).Log("msg", "Set node_mem", "memInfo", memInfo) | 53 | level.Debug(c.logger).Log("msg", "Set node_mem", "memInfo", memInfo) |
54 | for k, v := range memInfo { | 54 | for k, v := range memInfo { |
diff --git a/collector/meminfo_linux.go b/collector/meminfo_linux.go index 3b9e2e9..88505da 100644 --- a/collector/meminfo_linux.go +++ b/collector/meminfo_linux.go | |||
@@ -54,7 +54,7 @@ func parseMemInfo(r io.Reader) (map[string]float64, error) { | |||
54 | } | 54 | } |
55 | fv, err := strconv.ParseFloat(parts[1], 64) | 55 | fv, err := strconv.ParseFloat(parts[1], 64) |
56 | if err != nil { | 56 | if err != nil { |
57 | return nil, fmt.Errorf("invalid value in meminfo: %s", err) | 57 | return nil, fmt.Errorf("invalid value in meminfo: %w", err) |
58 | } | 58 | } |
59 | key := parts[0][:len(parts[0])-1] // remove trailing : from key | 59 | key := parts[0][:len(parts[0])-1] // remove trailing : from key |
60 | // Active(anon) -> Active_anon | 60 | // Active(anon) -> Active_anon |
diff --git a/collector/meminfo_numa_linux.go b/collector/meminfo_numa_linux.go index d36f6a0..f3d9307 100644 --- a/collector/meminfo_numa_linux.go +++ b/collector/meminfo_numa_linux.go | |||
@@ -62,7 +62,7 @@ func NewMeminfoNumaCollector(logger log.Logger) (Collector, error) { | |||
62 | func (c *meminfoNumaCollector) Update(ch chan<- prometheus.Metric) error { | 62 | func (c *meminfoNumaCollector) Update(ch chan<- prometheus.Metric) error { |
63 | metrics, err := getMemInfoNuma() | 63 | metrics, err := getMemInfoNuma() |
64 | if err != nil { | 64 | if err != nil { |
65 | return fmt.Errorf("couldn't get NUMA meminfo: %s", err) | 65 | return fmt.Errorf("couldn't get NUMA meminfo: %w", err) |
66 | } | 66 | } |
67 | for _, v := range metrics { | 67 | for _, v := range metrics { |
68 | desc, ok := c.metricDescs[v.metricName] | 68 | desc, ok := c.metricDescs[v.metricName] |
@@ -137,7 +137,7 @@ func parseMemInfoNuma(r io.Reader) ([]meminfoMetric, error) { | |||
137 | 137 | ||
138 | fv, err := strconv.ParseFloat(parts[3], 64) | 138 | fv, err := strconv.ParseFloat(parts[3], 64) |
139 | if err != nil { | 139 | if err != nil { |
140 | return nil, fmt.Errorf("invalid value in meminfo: %s", err) | 140 | return nil, fmt.Errorf("invalid value in meminfo: %w", err) |
141 | } | 141 | } |
142 | switch l := len(parts); { | 142 | switch l := len(parts); { |
143 | case l == 4: // no unit | 143 | case l == 4: // no unit |
@@ -174,7 +174,7 @@ func parseMemInfoNumaStat(r io.Reader, nodeNumber string) ([]meminfoMetric, erro | |||
174 | 174 | ||
175 | fv, err := strconv.ParseFloat(parts[1], 64) | 175 | fv, err := strconv.ParseFloat(parts[1], 64) |
176 | if err != nil { | 176 | if err != nil { |
177 | return nil, fmt.Errorf("invalid value in numastat: %s", err) | 177 | return nil, fmt.Errorf("invalid value in numastat: %w", err) |
178 | } | 178 | } |
179 | 179 | ||
180 | numaStat = append(numaStat, meminfoMetric{parts[0] + "_total", prometheus.CounterValue, nodeNumber, fv}) | 180 | numaStat = append(numaStat, meminfoMetric{parts[0] + "_total", prometheus.CounterValue, nodeNumber, fv}) |
diff --git a/collector/meminfo_openbsd.go b/collector/meminfo_openbsd.go index 073fbe7..81102d5 100644 --- a/collector/meminfo_openbsd.go +++ b/collector/meminfo_openbsd.go | |||
@@ -62,7 +62,7 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { | |||
62 | } | 62 | } |
63 | 63 | ||
64 | if _, err := C.sysctl_bcstats(&bcstats); err != nil { | 64 | if _, err := C.sysctl_bcstats(&bcstats); err != nil { |
65 | return nil, fmt.Errorf("sysctl CTL_VFS VFS_GENERIC VFS_BCACHESTAT failed: %v", err) | 65 | return nil, fmt.Errorf("sysctl CTL_VFS VFS_GENERIC VFS_BCACHESTAT failed: %w", err) |
66 | } | 66 | } |
67 | 67 | ||
68 | ps := float64(uvmexp.pagesize) | 68 | ps := float64(uvmexp.pagesize) |
diff --git a/collector/memory_bsd.go b/collector/memory_bsd.go index 4be5ddd..ac8b301 100644 --- a/collector/memory_bsd.go +++ b/collector/memory_bsd.go | |||
@@ -43,7 +43,7 @@ func init() { | |||
43 | func NewMemoryCollector(logger log.Logger) (Collector, error) { | 43 | func NewMemoryCollector(logger log.Logger) (Collector, error) { |
44 | tmp32, err := unix.SysctlUint32("vm.stats.vm.v_page_size") | 44 | tmp32, err := unix.SysctlUint32("vm.stats.vm.v_page_size") |
45 | if err != nil { | 45 | if err != nil { |
46 | return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %s", err) | 46 | return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %w", err) |
47 | } | 47 | } |
48 | size := float64(tmp32) | 48 | size := float64(tmp32) |
49 | 49 | ||
@@ -136,7 +136,7 @@ func (c *memoryCollector) Update(ch chan<- prometheus.Metric) error { | |||
136 | for _, m := range c.sysctls { | 136 | for _, m := range c.sysctls { |
137 | v, err := m.Value() | 137 | v, err := m.Value() |
138 | if err != nil { | 138 | if err != nil { |
139 | return fmt.Errorf("couldn't get memory: %s", err) | 139 | return fmt.Errorf("couldn't get memory: %w", err) |
140 | } | 140 | } |
141 | 141 | ||
142 | // Most are gauges. | 142 | // Most are gauges. |
@@ -154,7 +154,7 @@ func (c *memoryCollector) Update(ch chan<- prometheus.Metric) error { | |||
154 | 154 | ||
155 | swapUsed, err := c.kvm.SwapUsedPages() | 155 | swapUsed, err := c.kvm.SwapUsedPages() |
156 | if err != nil { | 156 | if err != nil { |
157 | return fmt.Errorf("couldn't get kvm: %s", err) | 157 | return fmt.Errorf("couldn't get kvm: %w", err) |
158 | } | 158 | } |
159 | 159 | ||
160 | ch <- prometheus.MustNewConstMetric( | 160 | ch <- prometheus.MustNewConstMetric( |
diff --git a/collector/netclass_linux.go b/collector/netclass_linux.go index cbfcb62..0fde219 100644 --- a/collector/netclass_linux.go +++ b/collector/netclass_linux.go | |||
@@ -61,7 +61,7 @@ func NewNetClassCollector(logger log.Logger) (Collector, error) { | |||
61 | func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error { | 61 | func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error { |
62 | netClass, err := c.getNetClassInfo() | 62 | netClass, err := c.getNetClassInfo() |
63 | if err != nil { | 63 | if err != nil { |
64 | return fmt.Errorf("could not get net class info: %s", err) | 64 | return fmt.Errorf("could not get net class info: %w", err) |
65 | } | 65 | } |
66 | for _, ifaceInfo := range netClass { | 66 | for _, ifaceInfo := range netClass { |
67 | upDesc := prometheus.NewDesc( | 67 | upDesc := prometheus.NewDesc( |
@@ -175,7 +175,7 @@ func (c *netClassCollector) getNetClassInfo() (sysfs.NetClass, error) { | |||
175 | netClass, err := c.fs.NetClass() | 175 | netClass, err := c.fs.NetClass() |
176 | 176 | ||
177 | if err != nil { | 177 | if err != nil { |
178 | return netClass, fmt.Errorf("error obtaining net class info: %s", err) | 178 | return netClass, fmt.Errorf("error obtaining net class info: %w", err) |
179 | } | 179 | } |
180 | 180 | ||
181 | for device := range netClass { | 181 | for device := range netClass { |
diff --git a/collector/netdev_common.go b/collector/netdev_common.go index 656e2aa..a28bd43 100644 --- a/collector/netdev_common.go +++ b/collector/netdev_common.go | |||
@@ -95,7 +95,7 @@ func NewNetDevCollector(logger log.Logger) (Collector, error) { | |||
95 | func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error { | 95 | func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error { |
96 | netDev, err := getNetDevStats(c.deviceExcludePattern, c.deviceIncludePattern, c.logger) | 96 | netDev, err := getNetDevStats(c.deviceExcludePattern, c.deviceIncludePattern, c.logger) |
97 | if err != nil { | 97 | if err != nil { |
98 | return fmt.Errorf("couldn't get netstats: %s", err) | 98 | return fmt.Errorf("couldn't get netstats: %w", err) |
99 | } | 99 | } |
100 | for dev, devStats := range netDev { | 100 | for dev, devStats := range netDev { |
101 | for key, value := range devStats { | 101 | for key, value := range devStats { |
@@ -111,7 +111,7 @@ func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error { | |||
111 | } | 111 | } |
112 | v, err := strconv.ParseFloat(value, 64) | 112 | v, err := strconv.ParseFloat(value, 64) |
113 | if err != nil { | 113 | if err != nil { |
114 | return fmt.Errorf("invalid value %s in netstats: %s", value, err) | 114 | return fmt.Errorf("invalid value %s in netstats: %w", value, err) |
115 | } | 115 | } |
116 | ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, dev) | 116 | ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, dev) |
117 | } | 117 | } |
diff --git a/collector/netstat_linux.go b/collector/netstat_linux.go index 9b4be49..6fac050 100644 --- a/collector/netstat_linux.go +++ b/collector/netstat_linux.go | |||
@@ -17,6 +17,7 @@ package collector | |||
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "bufio" | 19 | "bufio" |
20 | "errors" | ||
20 | "fmt" | 21 | "fmt" |
21 | "io" | 22 | "io" |
22 | "os" | 23 | "os" |
@@ -59,15 +60,15 @@ func NewNetStatCollector(logger log.Logger) (Collector, error) { | |||
59 | func (c *netStatCollector) Update(ch chan<- prometheus.Metric) error { | 60 | func (c *netStatCollector) Update(ch chan<- prometheus.Metric) error { |
60 | netStats, err := getNetStats(procFilePath("net/netstat")) | 61 | netStats, err := getNetStats(procFilePath("net/netstat")) |
61 | if err != nil { | 62 | if err != nil { |
62 | return fmt.Errorf("couldn't get netstats: %s", err) | 63 | return fmt.Errorf("couldn't get netstats: %w", err) |
63 | } | 64 | } |
64 | snmpStats, err := getNetStats(procFilePath("net/snmp")) | 65 | snmpStats, err := getNetStats(procFilePath("net/snmp")) |
65 | if err != nil { | 66 | if err != nil { |
66 | return fmt.Errorf("couldn't get SNMP stats: %s", err) | 67 | return fmt.Errorf("couldn't get SNMP stats: %w", err) |
67 | } | 68 | } |
68 | snmp6Stats, err := getSNMP6Stats(procFilePath("net/snmp6")) | 69 | snmp6Stats, err := getSNMP6Stats(procFilePath("net/snmp6")) |
69 | if err != nil { | 70 | if err != nil { |
70 | return fmt.Errorf("couldn't get SNMP6 stats: %s", err) | 71 | return fmt.Errorf("couldn't get SNMP6 stats: %w", err) |
71 | } | 72 | } |
72 | // Merge the results of snmpStats into netStats (collisions are possible, but | 73 | // Merge the results of snmpStats into netStats (collisions are possible, but |
73 | // we know that the keys are always unique for the given use case). | 74 | // 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 { | |||
82 | key := protocol + "_" + name | 83 | key := protocol + "_" + name |
83 | v, err := strconv.ParseFloat(value, 64) | 84 | v, err := strconv.ParseFloat(value, 64) |
84 | if err != nil { | 85 | if err != nil { |
85 | return fmt.Errorf("invalid value %s in netstats: %s", value, err) | 86 | return fmt.Errorf("invalid value %s in netstats: %w", value, err) |
86 | } | 87 | } |
87 | if !c.fieldPattern.MatchString(key) { | 88 | if !c.fieldPattern.MatchString(key) { |
88 | continue | 89 | continue |
@@ -140,7 +141,7 @@ func getSNMP6Stats(fileName string) (map[string]map[string]string, error) { | |||
140 | if err != nil { | 141 | if err != nil { |
141 | // On systems with IPv6 disabled, this file won't exist. | 142 | // On systems with IPv6 disabled, this file won't exist. |
142 | // Do nothing. | 143 | // Do nothing. |
143 | if os.IsNotExist(err) { | 144 | if errors.Is(err, os.ErrNotExist) { |
144 | return nil, nil | 145 | return nil, nil |
145 | } | 146 | } |
146 | 147 | ||
diff --git a/collector/nfs_linux.go b/collector/nfs_linux.go index a540bb3..60803eb 100644 --- a/collector/nfs_linux.go +++ b/collector/nfs_linux.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "errors" | ||
19 | "fmt" | 20 | "fmt" |
20 | "os" | 21 | "os" |
21 | "reflect" | 22 | "reflect" |
@@ -97,7 +98,7 @@ func NewNfsCollector(logger log.Logger) (Collector, error) { | |||
97 | func (c *nfsCollector) Update(ch chan<- prometheus.Metric) error { | 98 | func (c *nfsCollector) Update(ch chan<- prometheus.Metric) error { |
98 | stats, err := c.fs.ClientRPCStats() | 99 | stats, err := c.fs.ClientRPCStats() |
99 | if err != nil { | 100 | if err != nil { |
100 | if os.IsNotExist(err) { | 101 | if errors.Is(err, os.ErrNotExist) { |
101 | level.Debug(c.logger).Log("msg", "Not collecting NFS metrics", "err", err) | 102 | level.Debug(c.logger).Log("msg", "Not collecting NFS metrics", "err", err) |
102 | return ErrNoData | 103 | return ErrNoData |
103 | } | 104 | } |
diff --git a/collector/nfsd_linux.go b/collector/nfsd_linux.go index 8cb1e05..3dba899 100644 --- a/collector/nfsd_linux.go +++ b/collector/nfsd_linux.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "errors" | ||
19 | "fmt" | 20 | "fmt" |
20 | "os" | 21 | "os" |
21 | 22 | ||
@@ -63,7 +64,7 @@ func NewNFSdCollector(logger log.Logger) (Collector, error) { | |||
63 | func (c *nfsdCollector) Update(ch chan<- prometheus.Metric) error { | 64 | func (c *nfsdCollector) Update(ch chan<- prometheus.Metric) error { |
64 | stats, err := c.fs.ServerRPCStats() | 65 | stats, err := c.fs.ServerRPCStats() |
65 | if err != nil { | 66 | if err != nil { |
66 | if os.IsNotExist(err) { | 67 | if errors.Is(err, os.ErrNotExist) { |
67 | level.Debug(c.logger).Log("msg", "Not collecting NFSd metrics", "err", err) | 68 | level.Debug(c.logger).Log("msg", "Not collecting NFSd metrics", "err", err) |
68 | return ErrNoData | 69 | return ErrNoData |
69 | } | 70 | } |
diff --git a/collector/ntp.go b/collector/ntp.go index 411ba25..c7d55c9 100644 --- a/collector/ntp.go +++ b/collector/ntp.go | |||
@@ -125,7 +125,7 @@ func (c *ntpCollector) Update(ch chan<- prometheus.Metric) error { | |||
125 | Timeout: time.Second, // default `ntpdate` timeout | 125 | Timeout: time.Second, // default `ntpdate` timeout |
126 | }) | 126 | }) |
127 | if err != nil { | 127 | if err != nil { |
128 | return fmt.Errorf("couldn't get SNTP reply: %s", err) | 128 | return fmt.Errorf("couldn't get SNTP reply: %w", err) |
129 | } | 129 | } |
130 | 130 | ||
131 | ch <- c.stratum.mustNewConstMetric(float64(resp.Stratum)) | 131 | ch <- c.stratum.mustNewConstMetric(float64(resp.Stratum)) |
diff --git a/collector/powersupplyclass.go b/collector/powersupplyclass.go index 309b08c..adebf0e 100644 --- a/collector/powersupplyclass.go +++ b/collector/powersupplyclass.go | |||
@@ -59,7 +59,7 @@ func (c *powerSupplyClassCollector) Update(ch chan<- prometheus.Metric) error { | |||
59 | if errors.Is(err, os.ErrNotExist) { | 59 | if errors.Is(err, os.ErrNotExist) { |
60 | return ErrNoData | 60 | return ErrNoData |
61 | } | 61 | } |
62 | return fmt.Errorf("could not get power_supply class info: %s", err) | 62 | return fmt.Errorf("could not get power_supply class info: %w", err) |
63 | } | 63 | } |
64 | for _, powerSupply := range powerSupplyClass { | 64 | for _, powerSupply := range powerSupplyClass { |
65 | 65 | ||
diff --git a/collector/processes_linux.go b/collector/processes_linux.go index 3d64cbd..3d4e95d 100644 --- a/collector/processes_linux.go +++ b/collector/processes_linux.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "errors" | ||
19 | "fmt" | 20 | "fmt" |
20 | "os" | 21 | "os" |
21 | 22 | ||
@@ -75,13 +76,13 @@ func NewProcessStatCollector(logger log.Logger) (Collector, error) { | |||
75 | func (c *processCollector) Update(ch chan<- prometheus.Metric) error { | 76 | func (c *processCollector) Update(ch chan<- prometheus.Metric) error { |
76 | pids, states, threads, err := c.getAllocatedThreads() | 77 | pids, states, threads, err := c.getAllocatedThreads() |
77 | if err != nil { | 78 | if err != nil { |
78 | return fmt.Errorf("unable to retrieve number of allocated threads: %q", err) | 79 | return fmt.Errorf("unable to retrieve number of allocated threads: %w", err) |
79 | } | 80 | } |
80 | 81 | ||
81 | ch <- prometheus.MustNewConstMetric(c.threadAlloc, prometheus.GaugeValue, float64(threads)) | 82 | ch <- prometheus.MustNewConstMetric(c.threadAlloc, prometheus.GaugeValue, float64(threads)) |
82 | maxThreads, err := readUintFromFile(procFilePath("sys/kernel/threads-max")) | 83 | maxThreads, err := readUintFromFile(procFilePath("sys/kernel/threads-max")) |
83 | if err != nil { | 84 | if err != nil { |
84 | return fmt.Errorf("unable to retrieve limit number of threads: %q", err) | 85 | return fmt.Errorf("unable to retrieve limit number of threads: %w", err) |
85 | } | 86 | } |
86 | ch <- prometheus.MustNewConstMetric(c.threadLimit, prometheus.GaugeValue, float64(maxThreads)) | 87 | ch <- prometheus.MustNewConstMetric(c.threadLimit, prometheus.GaugeValue, float64(maxThreads)) |
87 | 88 | ||
@@ -91,7 +92,7 @@ func (c *processCollector) Update(ch chan<- prometheus.Metric) error { | |||
91 | 92 | ||
92 | pidM, err := readUintFromFile(procFilePath("sys/kernel/pid_max")) | 93 | pidM, err := readUintFromFile(procFilePath("sys/kernel/pid_max")) |
93 | if err != nil { | 94 | if err != nil { |
94 | return fmt.Errorf("unable to retrieve limit number of maximum pids alloved: %q", err) | 95 | return fmt.Errorf("unable to retrieve limit number of maximum pids alloved: %w", err) |
95 | } | 96 | } |
96 | ch <- prometheus.MustNewConstMetric(c.pidUsed, prometheus.GaugeValue, float64(pids)) | 97 | ch <- prometheus.MustNewConstMetric(c.pidUsed, prometheus.GaugeValue, float64(pids)) |
97 | ch <- prometheus.MustNewConstMetric(c.pidMax, prometheus.GaugeValue, float64(pidM)) | 98 | ch <- prometheus.MustNewConstMetric(c.pidMax, prometheus.GaugeValue, float64(pidM)) |
@@ -110,7 +111,7 @@ func (c *processCollector) getAllocatedThreads() (int, map[string]int32, int, er | |||
110 | for _, pid := range p { | 111 | for _, pid := range p { |
111 | stat, err := pid.Stat() | 112 | stat, err := pid.Stat() |
112 | // PIDs can vanish between getting the list and getting stats. | 113 | // PIDs can vanish between getting the list and getting stats. |
113 | if os.IsNotExist(err) { | 114 | if errors.Is(err, os.ErrNotExist) { |
114 | level.Debug(c.logger).Log("msg", "file not found when retrieving stats for pid", "pid", pid, "err", err) | 115 | level.Debug(c.logger).Log("msg", "file not found when retrieving stats for pid", "pid", pid, "err", err) |
115 | continue | 116 | continue |
116 | } | 117 | } |
diff --git a/collector/schedstat_linux.go b/collector/schedstat_linux.go index 9e5b744..9f29a7e 100644 --- a/collector/schedstat_linux.go +++ b/collector/schedstat_linux.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "errors" | ||
19 | "fmt" | 20 | "fmt" |
20 | "os" | 21 | "os" |
21 | 22 | ||
@@ -72,7 +73,7 @@ func init() { | |||
72 | func (c *schedstatCollector) Update(ch chan<- prometheus.Metric) error { | 73 | func (c *schedstatCollector) Update(ch chan<- prometheus.Metric) error { |
73 | stats, err := c.fs.Schedstat() | 74 | stats, err := c.fs.Schedstat() |
74 | if err != nil { | 75 | if err != nil { |
75 | if os.IsNotExist(err) { | 76 | if errors.Is(err, os.ErrNotExist) { |
76 | level.Debug(c.logger).Log("msg", "schedstat file does not exist") | 77 | level.Debug(c.logger).Log("msg", "schedstat file does not exist") |
77 | return ErrNoData | 78 | return ErrNoData |
78 | } | 79 | } |
diff --git a/collector/sockstat_linux.go b/collector/sockstat_linux.go index c7596c9..8f5a99f 100644 --- a/collector/sockstat_linux.go +++ b/collector/sockstat_linux.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "errors" | ||
19 | "fmt" | 20 | "fmt" |
20 | "os" | 21 | "os" |
21 | 22 | ||
@@ -55,7 +56,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { | |||
55 | stat4, err := fs.NetSockstat() | 56 | stat4, err := fs.NetSockstat() |
56 | switch { | 57 | switch { |
57 | case err == nil: | 58 | case err == nil: |
58 | case os.IsNotExist(err): | 59 | case errors.Is(err, os.ErrNotExist): |
59 | level.Debug(c.logger).Log("msg", "IPv4 sockstat statistics not found, skipping") | 60 | level.Debug(c.logger).Log("msg", "IPv4 sockstat statistics not found, skipping") |
60 | default: | 61 | default: |
61 | return fmt.Errorf("failed to get IPv4 sockstat data: %w", err) | 62 | return fmt.Errorf("failed to get IPv4 sockstat data: %w", err) |
@@ -64,7 +65,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { | |||
64 | stat6, err := fs.NetSockstat6() | 65 | stat6, err := fs.NetSockstat6() |
65 | switch { | 66 | switch { |
66 | case err == nil: | 67 | case err == nil: |
67 | case os.IsNotExist(err): | 68 | case errors.Is(err, os.ErrNotExist): |
68 | level.Debug(c.logger).Log("msg", "IPv6 sockstat statistics not found, skipping") | 69 | level.Debug(c.logger).Log("msg", "IPv6 sockstat statistics not found, skipping") |
69 | default: | 70 | default: |
70 | return fmt.Errorf("failed to get IPv6 sockstat data: %w", err) | 71 | return fmt.Errorf("failed to get IPv6 sockstat data: %w", err) |
diff --git a/collector/softnet_linux.go b/collector/softnet_linux.go index e48f182..befec8e 100644 --- a/collector/softnet_linux.go +++ b/collector/softnet_linux.go | |||
@@ -72,7 +72,7 @@ func NewSoftnetCollector(logger log.Logger) (Collector, error) { | |||
72 | func (c *softnetCollector) Update(ch chan<- prometheus.Metric) error { | 72 | func (c *softnetCollector) Update(ch chan<- prometheus.Metric) error { |
73 | stats, err := c.fs.NetSoftnetStat() | 73 | stats, err := c.fs.NetSoftnetStat() |
74 | if err != nil { | 74 | if err != nil { |
75 | return fmt.Errorf("could not get softnet statistics: %s", err) | 75 | return fmt.Errorf("could not get softnet statistics: %w", err) |
76 | } | 76 | } |
77 | 77 | ||
78 | for cpuNumber, cpuStats := range stats { | 78 | for cpuNumber, cpuStats := range stats { |
diff --git a/collector/supervisord.go b/collector/supervisord.go index 33f3b8a..6a6b909 100644 --- a/collector/supervisord.go +++ b/collector/supervisord.go | |||
@@ -134,7 +134,7 @@ func (c *supervisordCollector) Update(ch chan<- prometheus.Metric) error { | |||
134 | 134 | ||
135 | res, err := xrpc.Call("supervisor.getAllProcessInfo") | 135 | res, err := xrpc.Call("supervisor.getAllProcessInfo") |
136 | if err != nil { | 136 | if err != nil { |
137 | return fmt.Errorf("unable to call supervisord: %s", err) | 137 | return fmt.Errorf("unable to call supervisord: %w", err) |
138 | } | 138 | } |
139 | 139 | ||
140 | for _, p := range res.(xmlrpc.Array) { | 140 | for _, p := range res.(xmlrpc.Array) { |
diff --git a/collector/systemd_linux.go b/collector/systemd_linux.go index 57e9594..b374b37 100644 --- a/collector/systemd_linux.go +++ b/collector/systemd_linux.go | |||
@@ -175,13 +175,13 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { | |||
175 | begin := time.Now() | 175 | begin := time.Now() |
176 | conn, err := newSystemdDbusConn() | 176 | conn, err := newSystemdDbusConn() |
177 | if err != nil { | 177 | if err != nil { |
178 | return fmt.Errorf("couldn't get dbus connection: %s", err) | 178 | return fmt.Errorf("couldn't get dbus connection: %w", err) |
179 | } | 179 | } |
180 | defer conn.Close() | 180 | defer conn.Close() |
181 | 181 | ||
182 | allUnits, err := c.getAllUnits(conn) | 182 | allUnits, err := c.getAllUnits(conn) |
183 | if err != nil { | 183 | if err != nil { |
184 | return fmt.Errorf("couldn't get units: %s", err) | 184 | return fmt.Errorf("couldn't get units: %w", err) |
185 | } | 185 | } |
186 | level.Debug(c.logger).Log("msg", "getAllUnits took", "duration_seconds", time.Since(begin).Seconds()) | 186 | level.Debug(c.logger).Log("msg", "getAllUnits took", "duration_seconds", time.Since(begin).Seconds()) |
187 | 187 | ||
@@ -413,7 +413,7 @@ func (c *systemdCollector) collectSummaryMetrics(ch chan<- prometheus.Metric, su | |||
413 | func (c *systemdCollector) collectSystemState(conn *dbus.Conn, ch chan<- prometheus.Metric) error { | 413 | func (c *systemdCollector) collectSystemState(conn *dbus.Conn, ch chan<- prometheus.Metric) error { |
414 | systemState, err := conn.GetManagerProperty("SystemState") | 414 | systemState, err := conn.GetManagerProperty("SystemState") |
415 | if err != nil { | 415 | if err != nil { |
416 | return fmt.Errorf("couldn't get system state: %s", err) | 416 | return fmt.Errorf("couldn't get system state: %w", err) |
417 | } | 417 | } |
418 | isSystemRunning := 0.0 | 418 | isSystemRunning := 0.0 |
419 | if systemState == `"running"` { | 419 | if systemState == `"running"` { |
diff --git a/collector/tcpstat_linux.go b/collector/tcpstat_linux.go index db9c655..af5ae98 100644 --- a/collector/tcpstat_linux.go +++ b/collector/tcpstat_linux.go | |||
@@ -82,7 +82,7 @@ func NewTCPStatCollector(logger log.Logger) (Collector, error) { | |||
82 | func (c *tcpStatCollector) Update(ch chan<- prometheus.Metric) error { | 82 | func (c *tcpStatCollector) Update(ch chan<- prometheus.Metric) error { |
83 | tcpStats, err := getTCPStats(procFilePath("net/tcp")) | 83 | tcpStats, err := getTCPStats(procFilePath("net/tcp")) |
84 | if err != nil { | 84 | if err != nil { |
85 | return fmt.Errorf("couldn't get tcpstats: %s", err) | 85 | return fmt.Errorf("couldn't get tcpstats: %w", err) |
86 | } | 86 | } |
87 | 87 | ||
88 | // if enabled ipv6 system | 88 | // if enabled ipv6 system |
@@ -90,7 +90,7 @@ func (c *tcpStatCollector) Update(ch chan<- prometheus.Metric) error { | |||
90 | if _, hasIPv6 := os.Stat(tcp6File); hasIPv6 == nil { | 90 | if _, hasIPv6 := os.Stat(tcp6File); hasIPv6 == nil { |
91 | tcp6Stats, err := getTCPStats(tcp6File) | 91 | tcp6Stats, err := getTCPStats(tcp6File) |
92 | if err != nil { | 92 | if err != nil { |
93 | return fmt.Errorf("couldn't get tcp6stats: %s", err) | 93 | return fmt.Errorf("couldn't get tcp6stats: %w", err) |
94 | } | 94 | } |
95 | 95 | ||
96 | for st, value := range tcp6Stats { | 96 | for st, value := range tcp6Stats { |
diff --git a/collector/textfile.go b/collector/textfile.go index 64165e6..50c1807 100644 --- a/collector/textfile.go +++ b/collector/textfile.go | |||
@@ -238,14 +238,14 @@ func (c *textFileCollector) processFile(name string, ch chan<- prometheus.Metric | |||
238 | path := filepath.Join(c.path, name) | 238 | path := filepath.Join(c.path, name) |
239 | f, err := os.Open(path) | 239 | f, err := os.Open(path) |
240 | if err != nil { | 240 | if err != nil { |
241 | return nil, fmt.Errorf("failed to open textfile data file %q: %v", path, err) | 241 | return nil, fmt.Errorf("failed to open textfile data file %q: %w", path, err) |
242 | } | 242 | } |
243 | defer f.Close() | 243 | defer f.Close() |
244 | 244 | ||
245 | var parser expfmt.TextParser | 245 | var parser expfmt.TextParser |
246 | families, err := parser.TextToMetricFamilies(f) | 246 | families, err := parser.TextToMetricFamilies(f) |
247 | if err != nil { | 247 | if err != nil { |
248 | return nil, fmt.Errorf("failed to parse textfile data from %q: %v", path, err) | 248 | return nil, fmt.Errorf("failed to parse textfile data from %q: %w", path, err) |
249 | } | 249 | } |
250 | 250 | ||
251 | if hasTimestamps(families) { | 251 | if hasTimestamps(families) { |
@@ -267,7 +267,7 @@ func (c *textFileCollector) processFile(name string, ch chan<- prometheus.Metric | |||
267 | // a failure does not appear fresh. | 267 | // a failure does not appear fresh. |
268 | stat, err := f.Stat() | 268 | stat, err := f.Stat() |
269 | if err != nil { | 269 | if err != nil { |
270 | return nil, fmt.Errorf("failed to stat %q: %v", path, err) | 270 | return nil, fmt.Errorf("failed to stat %q: %w", path, err) |
271 | } | 271 | } |
272 | 272 | ||
273 | t := stat.ModTime() | 273 | t := stat.ModTime() |
diff --git a/collector/udp_queues_linux.go b/collector/udp_queues_linux.go index 512c010..e1b347e 100644 --- a/collector/udp_queues_linux.go +++ b/collector/udp_queues_linux.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "errors" | ||
19 | "fmt" | 20 | "fmt" |
20 | "os" | 21 | "os" |
21 | 22 | ||
@@ -41,7 +42,7 @@ func init() { | |||
41 | func NewUDPqueuesCollector(logger log.Logger) (Collector, error) { | 42 | func NewUDPqueuesCollector(logger log.Logger) (Collector, error) { |
42 | fs, err := procfs.NewFS(*procPath) | 43 | fs, err := procfs.NewFS(*procPath) |
43 | if err != nil { | 44 | if err != nil { |
44 | return nil, fmt.Errorf("failed to open procfs: %v", err) | 45 | return nil, fmt.Errorf("failed to open procfs: %w", err) |
45 | } | 46 | } |
46 | return &udpQueuesCollector{ | 47 | return &udpQueuesCollector{ |
47 | fs: fs, | 48 | fs: fs, |
@@ -61,10 +62,10 @@ func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error { | |||
61 | ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.TxQueueLength), "tx", "v4") | 62 | ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.TxQueueLength), "tx", "v4") |
62 | ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.RxQueueLength), "rx", "v4") | 63 | ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.RxQueueLength), "rx", "v4") |
63 | } else { | 64 | } else { |
64 | if os.IsNotExist(errIPv4) { | 65 | if errors.Is(errIPv4, os.ErrNotExist) { |
65 | level.Debug(c.logger).Log("msg", "not collecting ipv4 based metrics") | 66 | level.Debug(c.logger).Log("msg", "not collecting ipv4 based metrics") |
66 | } else { | 67 | } else { |
67 | return fmt.Errorf("couldn't get upd queued bytes: %s", errIPv4) | 68 | return fmt.Errorf("couldn't get upd queued bytes: %w", errIPv4) |
68 | } | 69 | } |
69 | } | 70 | } |
70 | 71 | ||
@@ -73,14 +74,14 @@ func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error { | |||
73 | ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.TxQueueLength), "tx", "v6") | 74 | ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.TxQueueLength), "tx", "v6") |
74 | ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.RxQueueLength), "rx", "v6") | 75 | ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.RxQueueLength), "rx", "v6") |
75 | } else { | 76 | } else { |
76 | if os.IsNotExist(errIPv6) { | 77 | if errors.Is(errIPv6, os.ErrNotExist) { |
77 | level.Debug(c.logger).Log("msg", "not collecting ipv6 based metrics") | 78 | level.Debug(c.logger).Log("msg", "not collecting ipv6 based metrics") |
78 | } else { | 79 | } else { |
79 | return fmt.Errorf("couldn't get upd6 queued bytes: %s", errIPv6) | 80 | return fmt.Errorf("couldn't get upd6 queued bytes: %w", errIPv6) |
80 | } | 81 | } |
81 | } | 82 | } |
82 | 83 | ||
83 | if os.IsNotExist(errIPv4) && os.IsNotExist(errIPv6) { | 84 | if errors.Is(errIPv4, os.ErrNotExist) && errors.Is(errIPv6, os.ErrNotExist) { |
84 | return ErrNoData | 85 | return ErrNoData |
85 | } | 86 | } |
86 | return nil | 87 | return nil |
diff --git a/collector/wifi_linux.go b/collector/wifi_linux.go index b4b3759..076982d 100644 --- a/collector/wifi_linux.go +++ b/collector/wifi_linux.go | |||
@@ -17,6 +17,7 @@ package collector | |||
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "encoding/json" | 19 | "encoding/json" |
20 | "errors" | ||
20 | "fmt" | 21 | "fmt" |
21 | "io/ioutil" | 22 | "io/ioutil" |
22 | "os" | 23 | "os" |
@@ -167,11 +168,11 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { | |||
167 | stat, err := newWifiStater(*collectorWifi) | 168 | stat, err := newWifiStater(*collectorWifi) |
168 | if err != nil { | 169 | if err != nil { |
169 | // Cannot access wifi metrics, report no error. | 170 | // Cannot access wifi metrics, report no error. |
170 | if os.IsNotExist(err) { | 171 | if errors.Is(err, os.ErrNotExist) { |
171 | level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system") | 172 | level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system") |
172 | return ErrNoData | 173 | return ErrNoData |
173 | } | 174 | } |
174 | if os.IsPermission(err) { | 175 | if errors.Is(err, os.ErrPermission) { |
175 | level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics") | 176 | level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics") |
176 | return ErrNoData | 177 | return ErrNoData |
177 | } | 178 | } |
@@ -201,14 +202,14 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { | |||
201 | ) | 202 | ) |
202 | 203 | ||
203 | // When a statistic is not available for a given interface, package wifi | 204 | // When a statistic is not available for a given interface, package wifi |
204 | // returns an error compatible with os.IsNotExist. We leverage this to | 205 | // returns a os.ErrNotExist error. We leverage this to only export |
205 | // only export metrics which are actually valid for given interface types. | 206 | // metrics which are actually valid for given interface types. |
206 | 207 | ||
207 | bss, err := stat.BSS(ifi) | 208 | bss, err := stat.BSS(ifi) |
208 | switch { | 209 | switch { |
209 | case err == nil: | 210 | case err == nil: |
210 | c.updateBSSStats(ch, ifi.Name, bss) | 211 | c.updateBSSStats(ch, ifi.Name, bss) |
211 | case os.IsNotExist(err): | 212 | case errors.Is(err, os.ErrNotExist): |
212 | level.Debug(c.logger).Log("msg", "BSS information not found for wifi device", "name", ifi.Name) | 213 | level.Debug(c.logger).Log("msg", "BSS information not found for wifi device", "name", ifi.Name) |
213 | default: | 214 | default: |
214 | return fmt.Errorf("failed to retrieve BSS for device %s: %v", | 215 | return fmt.Errorf("failed to retrieve BSS for device %s: %v", |
@@ -221,7 +222,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { | |||
221 | for _, station := range stations { | 222 | for _, station := range stations { |
222 | c.updateStationStats(ch, ifi.Name, station) | 223 | c.updateStationStats(ch, ifi.Name, station) |
223 | } | 224 | } |
224 | case os.IsNotExist(err): | 225 | case errors.Is(err, os.ErrNotExist): |
225 | level.Debug(c.logger).Log("msg", "station information not found for wifi device", "name", ifi.Name) | 226 | level.Debug(c.logger).Log("msg", "station information not found for wifi device", "name", ifi.Name) |
226 | default: | 227 | default: |
227 | return fmt.Errorf("failed to retrieve station info for device %q: %v", | 228 | 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 92661e4..2f20096 100644 --- a/collector/zfs_freebsd.go +++ b/collector/zfs_freebsd.go | |||
@@ -250,7 +250,7 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error { | |||
250 | for _, m := range c.sysctls { | 250 | for _, m := range c.sysctls { |
251 | v, err := m.Value() | 251 | v, err := m.Value() |
252 | if err != nil { | 252 | if err != nil { |
253 | return fmt.Errorf("couldn't get sysctl: %s", err) | 253 | return fmt.Errorf("couldn't get sysctl: %w", err) |
254 | } | 254 | } |
255 | 255 | ||
256 | ch <- prometheus.MustNewConstMetric( | 256 | ch <- prometheus.MustNewConstMetric( |
diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go index 2449c26..f55d98a 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 | |||
187 | 187 | ||
188 | value, err := strconv.ParseUint(line[i], 10, 64) | 188 | value, err := strconv.ParseUint(line[i], 10, 64) |
189 | if err != nil { | 189 | if err != nil { |
190 | return fmt.Errorf("could not parse expected integer value for %q: %v", key, err) | 190 | return fmt.Errorf("could not parse expected integer value for %q: %w", key, err) |
191 | } | 191 | } |
192 | handler(zpoolName, zfsSysctl(key), value) | 192 | handler(zpoolName, zfsSysctl(key), value) |
193 | } | 193 | } |