Change scrape_duration_seconds to gauge (#90)

* Change and rename scrape_duration metric to gauge collector_duration, split out collector_success

* Change to const metrics
This commit is contained in:
Calle Pettersson
2017-07-05 13:12:42 +02:00
committed by Martin Lindhe
parent 1db60e22b9
commit 1ebee26c30

View File

@@ -33,21 +33,25 @@ const (
) )
var ( var (
scrapeDurations = prometheus.NewSummaryVec( scrapeDurationDesc = prometheus.NewDesc(
prometheus.SummaryOpts{ prometheus.BuildFQName(collector.Namespace, "exporter", "collector_duration_seconds"),
Namespace: collector.Namespace, "wmi_exporter: Duration of a collection.",
Subsystem: "exporter", []string{"collector"},
Name: "scrape_duration_seconds", nil,
Help: "wmi_exporter: Duration of a scrape job.", )
}, scrapeSuccessDesc = prometheus.NewDesc(
[]string{"collector", "result"}, prometheus.BuildFQName(collector.Namespace, "exporter", "collector_success"),
"wmi_exporter: Whether the collector was successful.",
[]string{"collector"},
nil,
) )
) )
// Describe sends all the descriptors of the collectors included to // Describe sends all the descriptors of the collectors included to
// the provided channel. // the provided channel.
func (coll WmiCollector) Describe(ch chan<- *prometheus.Desc) { func (coll WmiCollector) Describe(ch chan<- *prometheus.Desc) {
scrapeDurations.Describe(ch) ch <- scrapeDurationDesc
ch <- scrapeSuccessDesc
} }
// Collect sends the collected metrics from each of the collectors to // Collect sends the collected metrics from each of the collectors to
@@ -63,7 +67,6 @@ func (coll WmiCollector) Collect(ch chan<- prometheus.Metric) {
}(name, c) }(name, c)
} }
wg.Wait() wg.Wait()
scrapeDurations.Collect(ch)
} }
func filterAvailableCollectors(collectors string) string { func filterAvailableCollectors(collectors string) string {
@@ -81,16 +84,27 @@ func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
begin := time.Now() begin := time.Now()
err := c.Collect(ch) err := c.Collect(ch)
duration := time.Since(begin) duration := time.Since(begin)
var result string var success float64
if err != nil { if err != nil {
log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err) log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err)
result = "error" success = 0
} else { } else {
log.Debugf("OK: %s collector succeeded after %fs.", name, duration.Seconds()) log.Debugf("OK: %s collector succeeded after %fs.", name, duration.Seconds())
result = "success" success = 1
} }
scrapeDurations.WithLabelValues(name, result).Observe(duration.Seconds()) ch <- prometheus.MustNewConstMetric(
scrapeDurationDesc,
prometheus.GaugeValue,
duration.Seconds(),
name,
)
ch <- prometheus.MustNewConstMetric(
scrapeSuccessDesc,
prometheus.GaugeValue,
success,
name,
)
} }
func expandEnabledCollectors(enabled string) []string { func expandEnabledCollectors(enabled string) []string {