-
Notifications
You must be signed in to change notification settings - Fork 0
/
exporter.go
60 lines (53 loc) · 1.62 KB
/
exporter.go
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
52
53
54
55
56
57
58
59
60
package collector
import (
"github.com/prometheus/client_golang/prometheus"
)
// ExporterCollector collects metrics, mostly runtime, about this exporter in general.
type ExporterCollector struct {
gitCommit string
goVersion string
osVersion string
startTime int64
StartTime *prometheus.Desc
BuildInfo *prometheus.Desc
}
// NewExporterCollector returns a new ExporterCollector.
func NewExporterCollector(osVersion, goVersion, gitCommit string, startTime int64) *ExporterCollector {
subsystem := "exporter"
return &ExporterCollector{
osVersion: osVersion,
goVersion: goVersion,
gitCommit: gitCommit,
startTime: startTime,
StartTime: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "start_time"),
"Exporter start time in Unix epoch seconds",
nil,
nil,
),
BuildInfo: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "build_info"),
"A metric with a constant '1' value labeled by OS version, Go version, and the Git commit of the exporter",
[]string{"os_version", "go_version", "git_commit"},
nil,
),
}
}
// Collect implements Prometheus' Collector interface and is used to collect metrics
func (c *ExporterCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(
c.StartTime,
prometheus.GaugeValue,
float64(c.startTime),
)
ch <- prometheus.MustNewConstMetric(
c.BuildInfo,
prometheus.CounterValue,
1.0,
c.osVersion, c.goVersion, c.gitCommit,
)
}
// Describe implements Prometheus' Collector interface and is used to describe metrics
func (c *ExporterCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.StartTime
}