Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change scrape_duration_seconds to gauge #90

Merged
merged 2 commits into from
Jul 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,25 @@ const (
)

var (
scrapeDurations = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: collector.Namespace,
Subsystem: "exporter",
Name: "scrape_duration_seconds",
Help: "wmi_exporter: Duration of a scrape job.",
},
[]string{"collector", "result"},
scrapeDurationDesc = prometheus.NewDesc(
prometheus.BuildFQName(collector.Namespace, "exporter", "collector_duration_seconds"),
"wmi_exporter: Duration of a collection.",
[]string{"collector"},
nil,
)
scrapeSuccessDesc = prometheus.NewDesc(
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
// the provided channel.
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
Expand All @@ -63,7 +67,6 @@ func (coll WmiCollector) Collect(ch chan<- prometheus.Metric) {
}(name, c)
}
wg.Wait()
scrapeDurations.Collect(ch)
}

func filterAvailableCollectors(collectors string) string {
Expand All @@ -81,16 +84,27 @@ func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
begin := time.Now()
err := c.Collect(ch)
duration := time.Since(begin)
var result string
var success float64

if err != nil {
log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err)
result = "error"
success = 0
} else {
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 {
Expand Down