forked from BonnierNews/logstash_exporter
/
nodeinfo_collector.go
90 lines (76 loc) · 2.11 KB
/
nodeinfo_collector.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package collector
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"strconv"
)
// NodeInfoCollector type
type NodeInfoCollector struct {
endpoint string
NodeInfos *prometheus.Desc
OsInfos *prometheus.Desc
JvmInfos *prometheus.Desc
}
// NewNodeInfoCollector function
func NewNodeInfoCollector(logstashEndpoint string) (Collector, error) {
const subsystem = "info"
return &NodeInfoCollector{
endpoint: logstashEndpoint,
NodeInfos: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "node"),
"A metric with a constant '1' value labeled by Logstash version.",
[]string{"version"},
nil,
),
OsInfos: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "os"),
"A metric with a constant '1' value labeled by name, arch, version and available_processors to the OS running Logstash.",
[]string{"name", "arch", "version", "available_processors"},
nil,
),
JvmInfos: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "jvm"),
"A metric with a constant '1' value labeled by name, version and vendor of the JVM running Logstash.",
[]string{"name", "version", "vendor"},
nil,
),
}, nil
}
// Collect function implements nodestats_collector collector
func (c *NodeInfoCollector) Collect(ch chan<- prometheus.Metric) error {
if desc, err := c.collect(ch); err != nil {
log.Error("Failed collecting info metrics", desc, err)
return err
}
return nil
}
func (c *NodeInfoCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
stats, err := NodeInfo(c.endpoint)
if err != nil {
return nil, err
}
ch <- prometheus.MustNewConstMetric(
c.NodeInfos,
prometheus.CounterValue,
float64(1),
stats.Version,
)
ch <- prometheus.MustNewConstMetric(
c.OsInfos,
prometheus.CounterValue,
float64(1),
stats.Os.Name,
stats.Os.Arch,
stats.Os.Version,
strconv.Itoa(stats.Os.AvailableProcessors),
)
ch <- prometheus.MustNewConstMetric(
c.JvmInfos,
prometheus.CounterValue,
float64(1),
stats.Jvm.VMName,
stats.Jvm.VMVersion,
stats.Jvm.VMVendor,
)
return nil, nil
}