-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollector.go
More file actions
51 lines (41 loc) · 1.38 KB
/
Copy pathcollector.go
File metadata and controls
51 lines (41 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"context"
"github.com/go-kit/kit/log"
"time"
"github.com/prometheus/client_golang/prometheus"
)
type collector struct {
ctx context.Context
target string
//module *config.Module
logger log.Logger
}
// Describe implements Prometheus.Collector.
func (c collector) Describe(ch chan<- *prometheus.Desc) {
ch <- prometheus.NewDesc("dummy", "dummy", nil, nil)
}
// Collect implements Prometheus.Collector.
func (c collector) Collect(ch chan<- prometheus.Metric) {
start := time.Now()
// pdus, err := ScrapeTarget(c.ctx, c.target, c.module, c.logger)
/*if err != nil {
level.Info(c.logger).Log("msg", "Error scraping target", "err", err)
ch <- prometheus.NewInvalidMetric(prometheus.NewDesc("snmp_error", "Error scraping target", nil, nil), err)
return
}*/
var pjSlice []prometheus.Metric // place to push collected metrics
walkLegaEtx(c.target, &pjSlice, c.logger)
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc("pjlink_walk_duration_seconds", "Time PJLink walk took.", nil, nil),
prometheus.GaugeValue,
time.Since(start).Seconds())
// iterate over results and push results to chan
for i := range pjSlice {
ch <- pjSlice[i]
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc("pjlink_scrape_duration_seconds", "Total PJLink time scrape took (walk and processing).", nil, nil),
prometheus.GaugeValue,
time.Since(start).Seconds())
}