-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildinfo.go
57 lines (49 loc) · 1.57 KB
/
buildinfo.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
package collector
import (
"github.com/DazWilkin/Aetos/opts"
"github.com/prometheus/client_golang/prometheus"
)
var _ prometheus.Collector = (*BuildInfoCollector)(nil)
// BuildInfoCollector collects metrics, mostly runtime, about this exporter in general.
type BuildInfoCollector struct {
opts *opts.Build
// Metrics
startTime *prometheus.Desc
buildInfo *prometheus.Desc
}
// NewBuildInfoCollector returns a new ExporterCollector.
func NewBuildInfoCollector(opts *opts.Build) *BuildInfoCollector {
return &BuildInfoCollector{
opts: opts,
startTime: prometheus.NewDesc(
prometheus.BuildFQName(opts.Namespace, opts.Subsystem, "start_time"),
"Exporter start time in Unix epoch seconds",
nil,
nil,
),
buildInfo: prometheus.NewDesc(
prometheus.BuildFQName(opts.Namespace, opts.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 *BuildInfoCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(
c.startTime,
prometheus.GaugeValue,
float64(c.opts.StartTime),
)
ch <- prometheus.MustNewConstMetric(
c.buildInfo,
prometheus.CounterValue,
1.0,
c.opts.OSVersion, c.opts.GoVersion, c.opts.GitCommit,
)
}
// Describe implements Prometheus' Collector interface and is used to describe metrics
func (c *BuildInfoCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.startTime
}