aboutsummaryrefslogtreecommitdiff
path: root/collector/netstat_linux.go
diff options
context:
space:
mode:
Diffstat (limited to 'collector/netstat_linux.go')
-rw-r--r--collector/netstat_linux.go11
1 files changed, 6 insertions, 5 deletions
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
18import ( 18import (
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) {
59func (c *netStatCollector) Update(ch chan<- prometheus.Metric) error { 60func (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