diff options
author | Julius Volz <julius@soundcloud.com> | 2015-09-10 00:33:12 +0200 |
---|---|---|
committer | Julius Volz <julius@soundcloud.com> | 2015-09-11 14:32:18 +0200 |
commit | 7b39ccc1446e52a552e09fa9a52c43143221c72c (patch) | |
tree | 8327fb5f00414976a81e08c52b3d5cbf52a594a6 /collector/uname_linux.go | |
parent | 02956d2bcc9d107dd480bb16bcadd75d0c81f81b (diff) | |
download | prometheus_node_collector-7b39ccc1446e52a552e09fa9a52c43143221c72c.tar.bz2 prometheus_node_collector-7b39ccc1446e52a552e09fa9a52c43143221c72c.tar.xz prometheus_node_collector-7b39ccc1446e52a552e09fa9a52c43143221c72c.zip |
Add Linux uname collector.
This creates a single metric like:
node_uname_info{domainname="(none)",machine="x86_64",nodename="desktop",release="3.16.0-48-generic",sysname="Linux",version="#64~14.04.1-Ubuntu SMP Thu Aug 20 23:03:57 UTC 2015"} 1
Diffstat (limited to 'collector/uname_linux.go')
-rw-r--r-- | collector/uname_linux.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/collector/uname_linux.go b/collector/uname_linux.go new file mode 100644 index 0000000..768ac7a --- /dev/null +++ b/collector/uname_linux.go | |||
@@ -0,0 +1,63 @@ | |||
1 | // +build !nouname | ||
2 | |||
3 | package collector | ||
4 | |||
5 | import ( | ||
6 | "syscall" | ||
7 | |||
8 | "github.com/prometheus/client_golang/prometheus" | ||
9 | ) | ||
10 | |||
11 | var unameDesc = prometheus.NewDesc( | ||
12 | prometheus.BuildFQName(Namespace, "uname", "info"), | ||
13 | "Labeled system information as provided by the uname system call.", | ||
14 | []string{ | ||
15 | "sysname", | ||
16 | "release", | ||
17 | "version", | ||
18 | "machine", | ||
19 | "nodename", | ||
20 | "domainname", | ||
21 | }, | ||
22 | nil, | ||
23 | ) | ||
24 | |||
25 | type unameCollector struct{} | ||
26 | |||
27 | func init() { | ||
28 | Factories["uname"] = newUnameCollector | ||
29 | } | ||
30 | |||
31 | // NewUnameCollector returns new unameCollector. | ||
32 | func newUnameCollector() (Collector, error) { | ||
33 | return &unameCollector{}, nil | ||
34 | } | ||
35 | |||
36 | func intArrayToString(array [65]int8) string { | ||
37 | var str string | ||
38 | for _, a := range array { | ||
39 | if a == 0 { | ||
40 | break | ||
41 | } | ||
42 | str += string(a) | ||
43 | } | ||
44 | return str | ||
45 | } | ||
46 | |||
47 | func (c unameCollector) Update(ch chan<- prometheus.Metric) error { | ||
48 | var uname syscall.Utsname | ||
49 | if err := syscall.Uname(&uname); err != nil { | ||
50 | return err | ||
51 | } | ||
52 | |||
53 | labelValues := []string{ | ||
54 | intArrayToString(uname.Sysname), | ||
55 | intArrayToString(uname.Release), | ||
56 | intArrayToString(uname.Version), | ||
57 | intArrayToString(uname.Machine), | ||
58 | intArrayToString(uname.Nodename), | ||
59 | intArrayToString(uname.Domainname), | ||
60 | } | ||
61 | ch <- prometheus.MustNewConstMetric(unameDesc, prometheus.GaugeValue, 1, labelValues...) | ||
62 | return nil | ||
63 | } | ||