| 81 | } |
| 82 | |
| 83 | func execute(name string, c Collector, ch chan<- prometheus.Metric) { |
| 84 | begin := time.Now() |
| 85 | err := c.Update(ch) |
| 86 | duration := time.Since(begin) |
| 87 | var success float64 |
| 88 | |
| 89 | if err != nil { |
| 90 | log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err) |
| 91 | success = 0 |
| 92 | } else { |
| 93 | log.Debugf("OK: %s collector succeeded after %fs.", name, duration.Seconds()) |
| 94 | success = 1 |
| 95 | } |
| 96 | ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), name) |
| 97 | ch <- prometheus.MustNewConstMetric(scrapeSuccessDesc, prometheus.GaugeValue, success, name) |
| 98 | } |
| 99 | |
| 100 | // Collector is the interface a collector has to implement. |
| 101 | type Collector interface { |