-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathinflux.go
58 lines (50 loc) · 1.57 KB
/
influx.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
package prometheus
import (
"runtime"
"strconv"
"time"
platform "github.com/influxdata/influxdb/v2"
"github.com/prometheus/client_golang/prometheus"
)
type influxCollector struct {
influxInfoDesc *prometheus.Desc
influxUptimeDesc *prometheus.Desc
start time.Time
}
// NewInfluxCollector returns a collector which exports influxdb process metrics.
func NewInfluxCollector(procID platform.IDGenerator, build platform.BuildInfo) prometheus.Collector {
id := procID.ID().String()
return &influxCollector{
influxInfoDesc: prometheus.NewDesc(
"influxdb_info",
"Information about the influxdb environment.",
nil, prometheus.Labels{
"version": build.Version,
"commit": build.Commit,
"build_date": build.Date,
"os": runtime.GOOS,
"arch": runtime.GOARCH,
"cpus": strconv.Itoa(runtime.NumCPU()),
},
),
influxUptimeDesc: prometheus.NewDesc(
"influxdb_uptime_seconds",
"influxdb process uptime in seconds",
nil, prometheus.Labels{
"id": id,
},
),
start: time.Now(),
}
}
// Describe returns all descriptions of the collector.
func (c *influxCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.influxInfoDesc
ch <- c.influxUptimeDesc
}
// Collect returns the current state of all metrics of the collector.
func (c *influxCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(c.influxInfoDesc, prometheus.GaugeValue, 1)
uptime := time.Since(c.start).Seconds()
ch <- prometheus.MustNewConstMetric(c.influxUptimeDesc, prometheus.GaugeValue, float64(uptime))
}