diff options
author | Ben Kochie <superq@gmail.com> | 2018-04-17 07:48:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-17 07:48:39 +0200 |
commit | f6008b242bead0f7b58c0aaf46d5b61e619f7fd7 (patch) | |
tree | 0a6a7d2336a25c74d13d61e83388e3614a49575b | |
parent | 768be139beb1522b092a0ec6ab7b7b3047216577 (diff) | |
parent | 693eb82139775899277919747dfcfce634ecf070 (diff) | |
download | prometheus_node_collector-f6008b242bead0f7b58c0aaf46d5b61e619f7fd7.tar.bz2 prometheus_node_collector-f6008b242bead0f7b58c0aaf46d5b61e619f7fd7.tar.xz prometheus_node_collector-f6008b242bead0f7b58c0aaf46d5b61e619f7fd7.zip |
Merge pull request #901 from mischief/bsd_boottime
collector: implement node_boot_time_seconds for OpenBSD/NetBSD/Darwin
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | collector/boot_time_bsd.go | 56 | ||||
-rw-r--r-- | collector/exec_bsd.go | 9 | ||||
-rw-r--r-- | collector/sysctl_bsd.go | 2 |
5 files changed, 59 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index aa0a88c..402b8be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md | |||
@@ -10,6 +10,7 @@ This release contains more breaking changes: | |||
10 | * [FEATURE] | 10 | * [FEATURE] |
11 | * [ENHANCEMENT] | 11 | * [ENHANCEMENT] |
12 | * [BUGFIX] Count core throttles per core and per package #871 | 12 | * [BUGFIX] Count core throttles per core and per package #871 |
13 | * [CHANGE] Move `node_boot_time_seconds` from `exec` to new `boottime` collector and enable for Darwin/Dragonfly/FreeBSD/NetBSD/OpenBSD. #901 | ||
13 | 14 | ||
14 | ## 0.16.0-rc.1 / 2018-04-04 | 15 | ## 0.16.0-rc.1 / 2018-04-04 |
15 | 16 | ||
@@ -26,6 +26,7 @@ Name | Description | OS | |||
26 | arp | Exposes ARP statistics from `/proc/net/arp`. | Linux | 26 | arp | Exposes ARP statistics from `/proc/net/arp`. | Linux |
27 | bcache | Exposes bcache statistics from `/sys/fs/bcache/`. | Linux | 27 | bcache | Exposes bcache statistics from `/sys/fs/bcache/`. | Linux |
28 | bonding | Exposes the number of configured and active slaves of Linux bonding interfaces. | Linux | 28 | bonding | Exposes the number of configured and active slaves of Linux bonding interfaces. | Linux |
29 | boottime | Exposes system boot time derived from the `kern.boottime` sysctl. | Darwin, Dragonfly, FreeBSD, NetBSD, OpenBSD | ||
29 | conntrack | Shows conntrack statistics (does nothing if no `/proc/sys/net/netfilter/` present). | Linux | 30 | conntrack | Shows conntrack statistics (does nothing if no `/proc/sys/net/netfilter/` present). | Linux |
30 | cpu | Exposes CPU statistics | Darwin, Dragonfly, FreeBSD, Linux | 31 | cpu | Exposes CPU statistics | Darwin, Dragonfly, FreeBSD, Linux |
31 | diskstats | Exposes disk I/O statistics. | Darwin, Linux | 32 | diskstats | Exposes disk I/O statistics. | Darwin, Linux |
diff --git a/collector/boot_time_bsd.go b/collector/boot_time_bsd.go new file mode 100644 index 0000000..cc2e895 --- /dev/null +++ b/collector/boot_time_bsd.go | |||
@@ -0,0 +1,56 @@ | |||
1 | // Copyright 2018 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 dragonfly openbsd netbsd darwin | ||
15 | // +build !noboottime | ||
16 | |||
17 | package collector | ||
18 | |||
19 | import ( | ||
20 | "github.com/prometheus/client_golang/prometheus" | ||
21 | ) | ||
22 | |||
23 | type bootTimeCollector struct{ boottime bsdSysctl } | ||
24 | |||
25 | func init() { | ||
26 | registerCollector("boottime", defaultEnabled, newBootTimeCollector) | ||
27 | } | ||
28 | |||
29 | // newBootTimeCollector returns a new Collector exposing system boot time on BSD systems. | ||
30 | func newBootTimeCollector() (Collector, error) { | ||
31 | return &bootTimeCollector{ | ||
32 | boottime: bsdSysctl{ | ||
33 | name: "boot_time_seconds", | ||
34 | description: "Unix time of last boot, including microseconds.", | ||
35 | mib: "kern.boottime", | ||
36 | dataType: bsdSysctlTypeStructTimeval, | ||
37 | }, | ||
38 | }, nil | ||
39 | } | ||
40 | |||
41 | // Update pushes boot time onto ch | ||
42 | func (c *bootTimeCollector) Update(ch chan<- prometheus.Metric) error { | ||
43 | v, err := c.boottime.Value() | ||
44 | if err != nil { | ||
45 | return err | ||
46 | } | ||
47 | |||
48 | ch <- prometheus.MustNewConstMetric( | ||
49 | prometheus.NewDesc( | ||
50 | prometheus.BuildFQName(namespace, "", c.boottime.name), | ||
51 | c.boottime.description, | ||
52 | nil, nil, | ||
53 | ), prometheus.GaugeValue, v) | ||
54 | |||
55 | return nil | ||
56 | } | ||
diff --git a/collector/exec_bsd.go b/collector/exec_bsd.go index 3ee8479..e4b780b 100644 --- a/collector/exec_bsd.go +++ b/collector/exec_bsd.go | |||
@@ -39,9 +39,6 @@ func NewExecCollector() (Collector, error) { | |||
39 | // vm.stats.sys.v_intr: Device interrupts | 39 | // vm.stats.sys.v_intr: Device interrupts |
40 | // vm.stats.sys.v_soft: Software interrupts | 40 | // vm.stats.sys.v_soft: Software interrupts |
41 | // vm.stats.vm.v_forks: Number of fork() calls | 41 | // vm.stats.vm.v_forks: Number of fork() calls |
42 | // | ||
43 | // From sys/kern/kern_tc.c: | ||
44 | // kern.boottime is an S,timeval | ||
45 | 42 | ||
46 | return &execCollector{ | 43 | return &execCollector{ |
47 | sysctls: []bsdSysctl{ | 44 | sysctls: []bsdSysctl{ |
@@ -75,12 +72,6 @@ func NewExecCollector() (Collector, error) { | |||
75 | description: "Number of fork() calls since system boot. Resets at architecture unsigned integer.", | 72 | description: "Number of fork() calls since system boot. Resets at architecture unsigned integer.", |
76 | mib: "vm.stats.vm.v_forks", | 73 | mib: "vm.stats.vm.v_forks", |
77 | }, | 74 | }, |
78 | { | ||
79 | name: "boot_time_seconds", | ||
80 | description: "Unix time of last boot, including microseconds.", | ||
81 | mib: "kern.boottime", | ||
82 | dataType: bsdSysctlTypeStructTimeval, | ||
83 | }, | ||
84 | }, | 75 | }, |
85 | }, nil | 76 | }, nil |
86 | } | 77 | } |
diff --git a/collector/sysctl_bsd.go b/collector/sysctl_bsd.go index 878e242..d6d4c57 100644 --- a/collector/sysctl_bsd.go +++ b/collector/sysctl_bsd.go | |||
@@ -11,7 +11,7 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build freebsd dragonfly | 14 | // +build freebsd dragonfly openbsd netbsd darwin |
15 | // +build !nomeminfo | 15 | // +build !nomeminfo |
16 | 16 | ||
17 | package collector | 17 | package collector |