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.
This commit is contained in:
parent
7426dc9460
commit
a02e469b07
3 changed files with 48 additions and 17 deletions
|
|
@ -36,14 +36,17 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
scrapeDurations = prometheus.NewSummaryVec(
|
||||
prometheus.SummaryOpts{
|
||||
Namespace: collector.Namespace,
|
||||
Subsystem: "exporter",
|
||||
Name: "scrape_duration_seconds",
|
||||
Help: "node_exporter: Duration of a scrape job.",
|
||||
},
|
||||
[]string{"collector", "result"},
|
||||
scrapeDurationDesc = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(collector.Namespace, "scrape", "collector_duration_seconds"),
|
||||
"node_exporter: Duration of a collector scrape.",
|
||||
[]string{"collector"},
|
||||
nil,
|
||||
)
|
||||
scrapeSuccessDesc = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(collector.Namespace, "scrape", "collector_success"),
|
||||
"node_exporter: Whether a collector succeeded.",
|
||||
[]string{"collector"},
|
||||
nil,
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -54,7 +57,8 @@ type NodeCollector struct {
|
|||
|
||||
// Describe implements the prometheus.Collector interface.
|
||||
func (n NodeCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
scrapeDurations.Describe(ch)
|
||||
ch <- scrapeDurationDesc
|
||||
ch <- scrapeSuccessDesc
|
||||
}
|
||||
|
||||
// Collect implements the prometheus.Collector interface.
|
||||
|
|
@ -68,7 +72,6 @@ func (n NodeCollector) Collect(ch chan<- prometheus.Metric) {
|
|||
}(name, c)
|
||||
}
|
||||
wg.Wait()
|
||||
scrapeDurations.Collect(ch)
|
||||
}
|
||||
|
||||
func filterAvailableCollectors(collectors string) string {
|
||||
|
|
@ -86,16 +89,17 @@ func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
|
|||
begin := time.Now()
|
||||
err := c.Update(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 loadCollectors(list string) (map[string]collector.Collector, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue