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 1 commit
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
28 changes: 19 additions & 9 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,31 @@ const (
)

var (
scrapeDurations = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
scrapeDurations = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: collector.Namespace,
Subsystem: "exporter",
Name: "scrape_duration_seconds",
Help: "wmi_exporter: Duration of a scrape job.",
Name: "collector_duration_seconds",
Help: "wmi_exporter: Duration of a collection.",
},
[]string{"collector", "result"},
[]string{"collector"},
)
scrapeSuccess = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: collector.Namespace,
Subsystem: "exporter",
Name: "collector_success",
Help: "wmi_exporter: Whether the collector was successful.",
},
[]string{"collector"},
)
)

// Describe sends all the descriptors of the collectors included to
// the provided channel.
func (coll WmiCollector) Describe(ch chan<- *prometheus.Desc) {
scrapeDurations.Describe(ch)
scrapeSuccess.Describe(ch)
}

// Collect sends the collected metrics from each of the collectors to
Expand All @@ -64,6 +74,7 @@ func (coll WmiCollector) Collect(ch chan<- prometheus.Metric) {
}
wg.Wait()
scrapeDurations.Collect(ch)
scrapeSuccess.Collect(ch)
}

func filterAvailableCollectors(collectors string) string {
Expand All @@ -81,16 +92,15 @@ 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

if err != nil {
log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err)
result = "error"
scrapeSuccess.WithLabelValues(name).Set(0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use ConstMetrics, so there's no interference from any scrapes happening at the same time

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Fixed!

} else {
log.Debugf("OK: %s collector succeeded after %fs.", name, duration.Seconds())
result = "success"
scrapeSuccess.WithLabelValues(name).Set(1)
}
scrapeDurations.WithLabelValues(name, result).Observe(duration.Seconds())
scrapeDurations.WithLabelValues(name).Set(duration.Seconds())
}

func expandEnabledCollectors(enabled string) []string {
Expand Down