aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid O'Rourke <phyber@users.noreply.github.com>2019-02-05 16:39:24 +0000
committerBen Kochie <superq@gmail.com>2019-02-05 17:39:24 +0100
commitd442108d7ae3c3445b501fd253816b40c322a4f9 (patch)
tree3e6d581ad314fc7d4b870ea39122a3a2c89388df
parent2b81bff51843525dc210749c33d96ac382921b1f (diff)
downloadprometheus_node_collector-d442108d7ae3c3445b501fd253816b40c322a4f9.tar.bz2
prometheus_node_collector-d442108d7ae3c3445b501fd253816b40c322a4f9.tar.xz
prometheus_node_collector-d442108d7ae3c3445b501fd253816b40c322a4f9.zip
collector: Implement uname collector for FreeBSD (#1239)
* collector: Implement uname collector for FreeBSD Signed-off-by: David O'Rourke <david.orourke@gmail.com>
-rw-r--r--CHANGELOG.md1
-rw-r--r--README.md2
-rw-r--r--collector/uname.go72
-rw-r--r--collector/uname_freebsd.go57
-rw-r--r--collector/uname_linux.go52
5 files changed, 144 insertions, 40 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 28cefae..c445503 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ The cpufreq metrics now separate the `cpufreq` and `scaling` data based on what
14* [ENHANCEMENT] Add Infiniband counters #1120 14* [ENHANCEMENT] Add Infiniband counters #1120
15* [FEATURE] Add a flag to disable exporter metrics #1148 15* [FEATURE] Add a flag to disable exporter metrics #1148
16* [FEATURE] Add kstat-based Solaris metrics for boottime, cpu and zfs collectors #1197 16* [FEATURE] Add kstat-based Solaris metrics for boottime, cpu and zfs collectors #1197
17* [FEATURE] Add uname collector for FreeBSD #1239
17 18
18## 0.17.0 / 2018-11-30 19## 0.17.0 / 2018-11-30
19 20
diff --git a/README.md b/README.md
index 9066d85..187e275 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ stat | Exposes various statistics from `/proc/stat`. This includes boot time, fo
54textfile | Exposes statistics read from local disk. The `--collector.textfile.directory` flag must be set. | _any_ 54textfile | Exposes statistics read from local disk. The `--collector.textfile.directory` flag must be set. | _any_
55time | Exposes the current system time. | _any_ 55time | Exposes the current system time. | _any_
56timex | Exposes selected adjtimex(2) system call stats. | Linux 56timex | Exposes selected adjtimex(2) system call stats. | Linux
57uname | Exposes system information as provided by the uname system call. | Linux 57uname | Exposes system information as provided by the uname system call. | FreeBSD, Linux
58vmstat | Exposes statistics from `/proc/vmstat`. | Linux 58vmstat | Exposes statistics from `/proc/vmstat`. | Linux
59xfs | Exposes XFS runtime statistics. | Linux (kernel 4.4+) 59xfs | Exposes XFS runtime statistics. | Linux (kernel 4.4+)
60zfs | Exposes [ZFS](http://open-zfs.org/) performance statistics. | [Linux](http://zfsonlinux.org/), Solaris 60zfs | Exposes [ZFS](http://open-zfs.org/) performance statistics. | [Linux](http://zfsonlinux.org/), Solaris
diff --git a/collector/uname.go b/collector/uname.go
new file mode 100644
index 0000000..e9a633f
--- /dev/null
+++ b/collector/uname.go
@@ -0,0 +1,72 @@
1// Copyright 2019 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14// +build freebsd linux
15// +build !nouname
16
17package collector
18
19import (
20 "github.com/prometheus/client_golang/prometheus"
21)
22
23var unameDesc = prometheus.NewDesc(
24 prometheus.BuildFQName(namespace, "uname", "info"),
25 "Labeled system information as provided by the uname system call.",
26 []string{
27 "sysname",
28 "release",
29 "version",
30 "machine",
31 "nodename",
32 "domainname",
33 },
34 nil,
35)
36
37type unameCollector struct{}
38type uname struct {
39 SysName string
40 Release string
41 Version string
42 Machine string
43 NodeName string
44 DomainName string
45}
46
47func init() {
48 registerCollector("uname", defaultEnabled, newUnameCollector)
49}
50
51// NewUnameCollector returns new unameCollector.
52func newUnameCollector() (Collector, error) {
53 return &unameCollector{}, nil
54}
55
56func (c unameCollector) Update(ch chan<- prometheus.Metric) error {
57 uname, err := getUname()
58 if err != nil {
59 return err
60 }
61
62 ch <- prometheus.MustNewConstMetric(unameDesc, prometheus.GaugeValue, 1,
63 uname.SysName,
64 uname.Release,
65 uname.Version,
66 uname.Machine,
67 uname.NodeName,
68 uname.DomainName,
69 )
70
71 return nil
72}
diff --git a/collector/uname_freebsd.go b/collector/uname_freebsd.go
new file mode 100644
index 0000000..9e4a8ba
--- /dev/null
+++ b/collector/uname_freebsd.go
@@ -0,0 +1,57 @@
1// Copyright 2019 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14// +build !nouname
15
16package collector
17
18import (
19 "bytes"
20 "strings"
21
22 "golang.org/x/sys/unix"
23)
24
25func getUname() (uname, error) {
26 var utsname unix.Utsname
27 if err := unix.Uname(&utsname); err != nil {
28 return uname{}, err
29 }
30
31 // We do a little bit of work here to emulate what happens in the Linux
32 // uname calls since FreeBSD uname doesn't have a Domainname.
33 nodename := string(utsname.Nodename[:bytes.IndexByte(utsname.Nodename[:], 0)])
34 split := strings.SplitN(nodename, ".", 2)
35
36 // We'll always have at least a single element in the array. We assume this
37 // is the hostname.
38 hostname := split[0]
39
40 // If we have more than one element, we assume this is the domainname.
41 // Otherwise leave it to "(none)" like Linux.
42 domainname := "(none)"
43 if len(split) > 1 {
44 domainname = split[1]
45 }
46
47 output := uname{
48 SysName: string(utsname.Sysname[:bytes.IndexByte(utsname.Sysname[:], 0)]),
49 Release: string(utsname.Release[:bytes.IndexByte(utsname.Release[:], 0)]),
50 Version: string(utsname.Version[:bytes.IndexByte(utsname.Version[:], 0)]),
51 Machine: string(utsname.Machine[:bytes.IndexByte(utsname.Machine[:], 0)]),
52 NodeName: hostname,
53 DomainName: domainname,
54 }
55
56 return output, nil
57}
diff --git a/collector/uname_linux.go b/collector/uname_linux.go
index 090180d..65de629 100644
--- a/collector/uname_linux.go
+++ b/collector/uname_linux.go
@@ -18,49 +18,23 @@ package collector
18import ( 18import (
19 "bytes" 19 "bytes"
20 20
21 "github.com/prometheus/client_golang/prometheus"
22
23 "golang.org/x/sys/unix" 21 "golang.org/x/sys/unix"
24) 22)
25 23
26var unameDesc = prometheus.NewDesc( 24func getUname() (uname, error) {
27 prometheus.BuildFQName(namespace, "uname", "info"), 25 var utsname unix.Utsname
28 "Labeled system information as provided by the uname system call.", 26 if err := unix.Uname(&utsname); err != nil {
29 []string{ 27 return uname{}, err
30 "sysname", 28 }
31 "release",
32 "version",
33 "machine",
34 "nodename",
35 "domainname",
36 },
37 nil,
38)
39
40type unameCollector struct{}
41
42func init() {
43 registerCollector("uname", defaultEnabled, newUnameCollector)
44}
45
46// NewUnameCollector returns new unameCollector.
47func newUnameCollector() (Collector, error) {
48 return &unameCollector{}, nil
49}
50 29
51func (c unameCollector) Update(ch chan<- prometheus.Metric) error { 30 output := uname{
52 var uname unix.Utsname 31 SysName: string(utsname.Sysname[:bytes.IndexByte(utsname.Sysname[:], 0)]),
53 if err := unix.Uname(&uname); err != nil { 32 Release: string(utsname.Release[:bytes.IndexByte(utsname.Release[:], 0)]),
54 return err 33 Version: string(utsname.Version[:bytes.IndexByte(utsname.Version[:], 0)]),
34 Machine: string(utsname.Machine[:bytes.IndexByte(utsname.Machine[:], 0)]),
35 NodeName: string(utsname.Nodename[:bytes.IndexByte(utsname.Nodename[:], 0)]),
36 DomainName: string(utsname.Domainname[:bytes.IndexByte(utsname.Domainname[:], 0)]),
55 } 37 }
56 38
57 ch <- prometheus.MustNewConstMetric(unameDesc, prometheus.GaugeValue, 1, 39 return output, nil
58 string(uname.Sysname[:bytes.IndexByte(uname.Sysname[:], 0)]),
59 string(uname.Release[:bytes.IndexByte(uname.Release[:], 0)]),
60 string(uname.Version[:bytes.IndexByte(uname.Version[:], 0)]),
61 string(uname.Machine[:bytes.IndexByte(uname.Machine[:], 0)]),
62 string(uname.Nodename[:bytes.IndexByte(uname.Nodename[:], 0)]),
63 string(uname.Domainname[:bytes.IndexByte(uname.Domainname[:], 0)]),
64 )
65 return nil
66} 40}