diff options
Diffstat (limited to 'collector/processes_linux.go')
-rw-r--r-- | collector/processes_linux.go | 9 |
1 files changed, 5 insertions, 4 deletions
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 | } |