aboutsummaryrefslogtreecommitdiff
path: root/collector/uname_linux.go
diff options
context:
space:
mode:
authorJulius Volz <julius@soundcloud.com>2015-09-10 00:33:12 +0200
committerJulius Volz <julius@soundcloud.com>2015-09-11 14:32:18 +0200
commit7b39ccc1446e52a552e09fa9a52c43143221c72c (patch)
tree8327fb5f00414976a81e08c52b3d5cbf52a594a6 /collector/uname_linux.go
parent02956d2bcc9d107dd480bb16bcadd75d0c81f81b (diff)
downloadprometheus_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.go63
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
3package collector
4
5import (
6 "syscall"
7
8 "github.com/prometheus/client_golang/prometheus"
9)
10
11var 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
25type unameCollector struct{}
26
27func init() {
28 Factories["uname"] = newUnameCollector
29}
30
31// NewUnameCollector returns new unameCollector.
32func newUnameCollector() (Collector, error) {
33 return &unameCollector{}, nil
34}
35
36func 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
47func (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}