@@ -33,31 +33,25 @@ const (
33
33
)
34
34
35
35
var (
36
- scrapeDurations = prometheus .NewGaugeVec (
37
- prometheus.GaugeOpts {
38
- Namespace : collector .Namespace ,
39
- Subsystem : "exporter" ,
40
- Name : "collector_duration_seconds" ,
41
- Help : "wmi_exporter: Duration of a collection." ,
42
- },
36
+ scrapeDurationDesc = prometheus .NewDesc (
37
+ prometheus .BuildFQName (collector .Namespace , "exporter" , "collector_duration_seconds" ),
38
+ "wmi_exporter: Duration of a collection." ,
43
39
[]string {"collector" },
40
+ nil ,
44
41
)
45
- scrapeSuccess = prometheus .NewGaugeVec (
46
- prometheus.GaugeOpts {
47
- Namespace : collector .Namespace ,
48
- Subsystem : "exporter" ,
49
- Name : "collector_success" ,
50
- Help : "wmi_exporter: Whether the collector was successful." ,
51
- },
42
+ scrapeSuccessDesc = prometheus .NewDesc (
43
+ prometheus .BuildFQName (collector .Namespace , "exporter" , "collector_success" ),
44
+ "wmi_exporter: Whether the collector was successful." ,
52
45
[]string {"collector" },
46
+ nil ,
53
47
)
54
48
)
55
49
56
50
// Describe sends all the descriptors of the collectors included to
57
51
// the provided channel.
58
52
func (coll WmiCollector ) Describe (ch chan <- * prometheus.Desc ) {
59
- scrapeDurations . Describe ( ch )
60
- scrapeSuccess . Describe ( ch )
53
+ ch <- scrapeDurationDesc
54
+ ch <- scrapeSuccessDesc
61
55
}
62
56
63
57
// Collect sends the collected metrics from each of the collectors to
@@ -73,8 +67,6 @@ func (coll WmiCollector) Collect(ch chan<- prometheus.Metric) {
73
67
}(name , c )
74
68
}
75
69
wg .Wait ()
76
- scrapeDurations .Collect (ch )
77
- scrapeSuccess .Collect (ch )
78
70
}
79
71
80
72
func filterAvailableCollectors (collectors string ) string {
@@ -92,15 +84,27 @@ func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
92
84
begin := time .Now ()
93
85
err := c .Collect (ch )
94
86
duration := time .Since (begin )
87
+ var success float64
95
88
96
89
if err != nil {
97
90
log .Errorf ("ERROR: %s collector failed after %fs: %s" , name , duration .Seconds (), err )
98
- scrapeSuccess . WithLabelValues ( name ). Set ( 0 )
91
+ success = 0
99
92
} else {
100
93
log .Debugf ("OK: %s collector succeeded after %fs." , name , duration .Seconds ())
101
- scrapeSuccess . WithLabelValues ( name ). Set ( 1 )
94
+ success = 1
102
95
}
103
- scrapeDurations .WithLabelValues (name ).Set (duration .Seconds ())
96
+ ch <- prometheus .MustNewConstMetric (
97
+ scrapeDurationDesc ,
98
+ prometheus .GaugeValue ,
99
+ duration .Seconds (),
100
+ name ,
101
+ )
102
+ ch <- prometheus .MustNewConstMetric (
103
+ scrapeSuccessDesc ,
104
+ prometheus .GaugeValue ,
105
+ success ,
106
+ name ,
107
+ )
104
108
}
105
109
106
110
func expandEnabledCollectors (enabled string ) []string {
0 commit comments