aboutsummaryrefslogtreecommitdiff
path: root/node_exporter.go
diff options
context:
space:
mode:
authorBrian Brazil <brian-brazil@users.noreply.github.com>2017-03-16 17:21:00 +0000
committerGitHub <noreply@github.com>2017-03-16 17:21:00 +0000
commita02e469b0727aed276ecd8e8d22de7f2b2447837 (patch)
treee6912ac8cdc7328e95db1a2393a4d2bccf4f52ef /node_exporter.go
parent7426dc94605e447c4da6191b847ad48077bae209 (diff)
downloadprometheus_node_collector-a02e469b0727aed276ecd8e8d22de7f2b2447837.tar.bz2
prometheus_node_collector-a02e469b0727aed276ecd8e8d22de7f2b2447837.tar.xz
prometheus_node_collector-a02e469b0727aed276ecd8e8d22de7f2b2447837.zip
Report collector success/failure and duration per scrape. (#516)
This is in line with best practices, and also saves us 63 timeseries on a default Linux setup.
Diffstat (limited to 'node_exporter.go')
-rw-r--r--node_exporter.go32
1 files changed, 18 insertions, 14 deletions
diff --git a/node_exporter.go b/node_exporter.go
index 1028ed8..4a7f88a 100644
--- a/node_exporter.go
+++ b/node_exporter.go
@@ -36,14 +36,17 @@ const (
36) 36)
37 37
38var ( 38var (
39 scrapeDurations = prometheus.NewSummaryVec( 39 scrapeDurationDesc = prometheus.NewDesc(
40 prometheus.SummaryOpts{ 40 prometheus.BuildFQName(collector.Namespace, "scrape", "collector_duration_seconds"),
41 Namespace: collector.Namespace, 41 "node_exporter: Duration of a collector scrape.",
42 Subsystem: "exporter", 42 []string{"collector"},
43 Name: "scrape_duration_seconds", 43 nil,
44 Help: "node_exporter: Duration of a scrape job.", 44 )
45 }, 45 scrapeSuccessDesc = prometheus.NewDesc(
46 []string{"collector", "result"}, 46 prometheus.BuildFQName(collector.Namespace, "scrape", "collector_success"),
47 "node_exporter: Whether a collector succeeded.",
48 []string{"collector"},
49 nil,
47 ) 50 )
48) 51)
49 52
@@ -54,7 +57,8 @@ type NodeCollector struct {
54 57
55// Describe implements the prometheus.Collector interface. 58// Describe implements the prometheus.Collector interface.
56func (n NodeCollector) Describe(ch chan<- *prometheus.Desc) { 59func (n NodeCollector) Describe(ch chan<- *prometheus.Desc) {
57 scrapeDurations.Describe(ch) 60 ch <- scrapeDurationDesc
61 ch <- scrapeSuccessDesc
58} 62}
59 63
60// Collect implements the prometheus.Collector interface. 64// Collect implements the prometheus.Collector interface.
@@ -68,7 +72,6 @@ func (n NodeCollector) Collect(ch chan<- prometheus.Metric) {
68 }(name, c) 72 }(name, c)
69 } 73 }
70 wg.Wait() 74 wg.Wait()
71 scrapeDurations.Collect(ch)
72} 75}
73 76
74func filterAvailableCollectors(collectors string) string { 77func filterAvailableCollectors(collectors string) string {
@@ -86,16 +89,17 @@ func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
86 begin := time.Now() 89 begin := time.Now()
87 err := c.Update(ch) 90 err := c.Update(ch)
88 duration := time.Since(begin) 91 duration := time.Since(begin)
89 var result string 92 var success float64
90 93
91 if err != nil { 94 if err != nil {
92 log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err) 95 log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err)
93 result = "error" 96 success = 0
94 } else { 97 } else {
95 log.Debugf("OK: %s collector succeeded after %fs.", name, duration.Seconds()) 98 log.Debugf("OK: %s collector succeeded after %fs.", name, duration.Seconds())
96 result = "success" 99 success = 1
97 } 100 }
98 scrapeDurations.WithLabelValues(name, result).Observe(duration.Seconds()) 101 ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), name)
102 ch <- prometheus.MustNewConstMetric(scrapeSuccessDesc, prometheus.GaugeValue, success, name)
99} 103}
100 104
101func loadCollectors(list string) (map[string]collector.Collector, error) { 105func loadCollectors(list string) (map[string]collector.Collector, error) {