aboutsummaryrefslogtreecommitdiff
path: root/collector
diff options
context:
space:
mode:
authorBen Kochie <superq@gmail.com>2020-02-19 16:11:29 +0100
committerGitHub <noreply@github.com>2020-02-19 16:11:29 +0100
commit3e1b0f1bee40af140c1349ab401392882ed658de (patch)
tree7e4cd24fd74facefc651834def528a916b29a3ab /collector
parent1a75bc7b5039502641f41382a97031ae459455c5 (diff)
downloadprometheus_node_collector-3e1b0f1bee40af140c1349ab401392882ed658de.tar.bz2
prometheus_node_collector-3e1b0f1bee40af140c1349ab401392882ed658de.tar.xz
prometheus_node_collector-3e1b0f1bee40af140c1349ab401392882ed658de.zip
Don't count empty collection as success (#1613)
Many collectors depend on underlying features to be enabled. This causes confusion about what "success" means. This changes the behavior of the `node_scrape_collector_success` metric. * When a collector is unable to find data don't return success. * Catch the no data error and send to Debug log level to avoid log spam. * Update collectors to support this new functionality. * Fix copy-pasta mistake in infiband debug message. Closes: https://github.com/prometheus/node_exporter/issues/1323 Signed-off-by: Ben Kochie <superq@gmail.com>
Diffstat (limited to 'collector')
-rw-r--r--collector/bonding_linux.go2
-rw-r--r--collector/collector.go14
-rw-r--r--collector/drbd_linux.go2
-rw-r--r--collector/hwmon_linux.go2
-rw-r--r--collector/infiniband_linux.go4
-rw-r--r--collector/ipvs_linux.go2
-rw-r--r--collector/mdadm_linux.go2
-rw-r--r--collector/nfs_linux.go2
-rw-r--r--collector/nfsd_linux.go2
-rw-r--r--collector/wifi_linux.go4
10 files changed, 24 insertions, 12 deletions
diff --git a/collector/bonding_linux.go b/collector/bonding_linux.go
index 771786b..78e94b2 100644
--- a/collector/bonding_linux.go
+++ b/collector/bonding_linux.go
@@ -61,7 +61,7 @@ func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error {
61 if err != nil { 61 if err != nil {
62 if os.IsNotExist(err) { 62 if os.IsNotExist(err) {
63 level.Debug(c.logger).Log("msg", "Not collecting bonding, file does not exist", "file", statusfile) 63 level.Debug(c.logger).Log("msg", "Not collecting bonding, file does not exist", "file", statusfile)
64 return nil 64 return ErrNoData
65 } 65 }
66 return err 66 return err
67 } 67 }
diff --git a/collector/collector.go b/collector/collector.go
index af8712c..0fec09c 100644
--- a/collector/collector.go
+++ b/collector/collector.go
@@ -15,6 +15,7 @@
15package collector 15package collector
16 16
17import ( 17import (
18 "errors"
18 "fmt" 19 "fmt"
19 "sync" 20 "sync"
20 "time" 21 "time"
@@ -131,7 +132,11 @@ func execute(name string, c Collector, ch chan<- prometheus.Metric, logger log.L
131 var success float64 132 var success float64
132 133
133 if err != nil { 134 if err != nil {
134 level.Error(logger).Log("msg", "collector failed", "name", name, "duration_seconds", duration.Seconds(), "err", err) 135 if IsNoDataError(err) {
136 level.Debug(logger).Log("msg", "collector returned no data", "name", name, "duration_seconds", duration.Seconds(), "err", err)
137 } else {
138 level.Error(logger).Log("msg", "collector failed", "name", name, "duration_seconds", duration.Seconds(), "err", err)
139 }
135 success = 0 140 success = 0
136 } else { 141 } else {
137 level.Debug(logger).Log("msg", "collector succeeded", "name", name, "duration_seconds", duration.Seconds()) 142 level.Debug(logger).Log("msg", "collector succeeded", "name", name, "duration_seconds", duration.Seconds())
@@ -155,3 +160,10 @@ type typedDesc struct {
155func (d *typedDesc) mustNewConstMetric(value float64, labels ...string) prometheus.Metric { 160func (d *typedDesc) mustNewConstMetric(value float64, labels ...string) prometheus.Metric {
156 return prometheus.MustNewConstMetric(d.desc, d.valueType, value, labels...) 161 return prometheus.MustNewConstMetric(d.desc, d.valueType, value, labels...)
157} 162}
163
164// ErrNoData indicates the collector found no data to collect, but had no other error.
165var ErrNoData = errors.New("collector returned no data")
166
167func IsNoDataError(err error) bool {
168 return err == ErrNoData
169}
diff --git a/collector/drbd_linux.go b/collector/drbd_linux.go
index 5a340b9..6815c5f 100644
--- a/collector/drbd_linux.go
+++ b/collector/drbd_linux.go
@@ -188,7 +188,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error {
188 if err != nil { 188 if err != nil {
189 if os.IsNotExist(err) { 189 if os.IsNotExist(err) {
190 level.Debug(c.logger).Log("msg", "stats file does not exist, skipping", "file", statsFile, "err", err) 190 level.Debug(c.logger).Log("msg", "stats file does not exist, skipping", "file", statsFile, "err", err)
191 return nil 191 return ErrNoData
192 } 192 }
193 193
194 return err 194 return err
diff --git a/collector/hwmon_linux.go b/collector/hwmon_linux.go
index 31dbd22..5649942 100644
--- a/collector/hwmon_linux.go
+++ b/collector/hwmon_linux.go
@@ -426,7 +426,7 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error {
426 if err != nil { 426 if err != nil {
427 if os.IsNotExist(err) { 427 if os.IsNotExist(err) {
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 nil 429 return ErrNoData
430 } 430 }
431 431
432 return err 432 return err
diff --git a/collector/infiniband_linux.go b/collector/infiniband_linux.go
index 4fa68ba..1f453b8 100644
--- a/collector/infiniband_linux.go
+++ b/collector/infiniband_linux.go
@@ -109,8 +109,8 @@ func (c *infinibandCollector) Update(ch chan<- prometheus.Metric) error {
109 devices, err := c.fs.InfiniBandClass() 109 devices, err := c.fs.InfiniBandClass()
110 if err != nil { 110 if err != nil {
111 if os.IsNotExist(err) { 111 if os.IsNotExist(err) {
112 level.Debug(c.logger).Log("msg", "IPv4 sockstat statistics not found, skipping") 112 level.Debug(c.logger).Log("msg", "infiniband statistics not found, skipping")
113 return nil 113 return ErrNoData
114 } 114 }
115 return fmt.Errorf("error obtaining InfiniBand class info: %s", err) 115 return fmt.Errorf("error obtaining InfiniBand class info: %s", err)
116 } 116 }
diff --git a/collector/ipvs_linux.go b/collector/ipvs_linux.go
index 89469e5..11adf0f 100644
--- a/collector/ipvs_linux.go
+++ b/collector/ipvs_linux.go
@@ -115,7 +115,7 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error {
115 // Cannot access ipvs metrics, report no error. 115 // Cannot access ipvs metrics, report no error.
116 if os.IsNotExist(err) { 116 if os.IsNotExist(err) {
117 level.Debug(c.logger).Log("msg", "ipvs collector metrics are not available for this system") 117 level.Debug(c.logger).Log("msg", "ipvs collector metrics are not available for this system")
118 return nil 118 return ErrNoData
119 } 119 }
120 return fmt.Errorf("could not get IPVS stats: %s", err) 120 return fmt.Errorf("could not get IPVS stats: %s", err)
121 } 121 }
diff --git a/collector/mdadm_linux.go b/collector/mdadm_linux.go
index faf1cee..05f83ee 100644
--- a/collector/mdadm_linux.go
+++ b/collector/mdadm_linux.go
@@ -105,7 +105,7 @@ func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error {
105 if err != nil { 105 if err != nil {
106 if os.IsNotExist(err) { 106 if os.IsNotExist(err) {
107 level.Debug(c.logger).Log("msg", "Not collecting mdstat, file does not exist", "file", *procPath) 107 level.Debug(c.logger).Log("msg", "Not collecting mdstat, file does not exist", "file", *procPath)
108 return nil 108 return ErrNoData
109 } 109 }
110 110
111 return fmt.Errorf("error parsing mdstatus: %s", err) 111 return fmt.Errorf("error parsing mdstatus: %s", err)
diff --git a/collector/nfs_linux.go b/collector/nfs_linux.go
index 7ed4930..55f9e19 100644
--- a/collector/nfs_linux.go
+++ b/collector/nfs_linux.go
@@ -97,7 +97,7 @@ func (c *nfsCollector) Update(ch chan<- prometheus.Metric) error {
97 if err != nil { 97 if err != nil {
98 if os.IsNotExist(err) { 98 if os.IsNotExist(err) {
99 level.Debug(c.logger).Log("msg", "Not collecting NFS metrics", "err", err) 99 level.Debug(c.logger).Log("msg", "Not collecting NFS metrics", "err", err)
100 return nil 100 return ErrNoData
101 } 101 }
102 return fmt.Errorf("failed to retrieve nfs stats: %w", err) 102 return fmt.Errorf("failed to retrieve nfs stats: %w", err)
103 } 103 }
diff --git a/collector/nfsd_linux.go b/collector/nfsd_linux.go
index 234e1da..b6f2f8e 100644
--- a/collector/nfsd_linux.go
+++ b/collector/nfsd_linux.go
@@ -63,7 +63,7 @@ func (c *nfsdCollector) Update(ch chan<- prometheus.Metric) error {
63 if err != nil { 63 if err != nil {
64 if os.IsNotExist(err) { 64 if os.IsNotExist(err) {
65 level.Debug(c.logger).Log("msg", "Not collecting NFSd metrics", "err", err) 65 level.Debug(c.logger).Log("msg", "Not collecting NFSd metrics", "err", err)
66 return nil 66 return ErrNoData
67 } 67 }
68 return fmt.Errorf("failed to retrieve nfsd stats: %w", err) 68 return fmt.Errorf("failed to retrieve nfsd stats: %w", err)
69 } 69 }
diff --git a/collector/wifi_linux.go b/collector/wifi_linux.go
index 5a5a86c..118e714 100644
--- a/collector/wifi_linux.go
+++ b/collector/wifi_linux.go
@@ -167,11 +167,11 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
167 // Cannot access wifi metrics, report no error. 167 // Cannot access wifi metrics, report no error.
168 if os.IsNotExist(err) { 168 if os.IsNotExist(err) {
169 level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system") 169 level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system")
170 return nil 170 return ErrNoData
171 } 171 }
172 if os.IsPermission(err) { 172 if os.IsPermission(err) {
173 level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics") 173 level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics")
174 return nil 174 return ErrNoData
175 } 175 }
176 176
177 return fmt.Errorf("failed to access wifi data: %w", err) 177 return fmt.Errorf("failed to access wifi data: %w", err)