aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormischief <mischief@offblast.org>2018-04-15 04:42:02 +0000
committermischief <mischief@offblast.org>2018-04-15 08:26:46 +0000
commit26a385d7abe2181530426f49e0fe918d06917ca1 (patch)
tree8a307a6317809e7f52d945344e0b3c1710d69d36
parent6025dc207d3758e5fc6af0ae358e5f1dead31360 (diff)
downloadprometheus_node_collector-26a385d7abe2181530426f49e0fe918d06917ca1.tar.bz2
prometheus_node_collector-26a385d7abe2181530426f49e0fe918d06917ca1.tar.xz
prometheus_node_collector-26a385d7abe2181530426f49e0fe918d06917ca1.zip
collector: implement node_boot_time_seconds for OpenBSD/NetBSD/Darwin
Signed-off-by: mischief <mischief@offblast.org>
-rw-r--r--collector/boot_time_bsd.go56
-rw-r--r--collector/exec_bsd.go9
-rw-r--r--collector/sysctl_bsd.go2
3 files changed, 57 insertions, 10 deletions
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
17package collector
18
19import (
20 "github.com/prometheus/client_golang/prometheus"
21)
22
23type bootTimeCollector struct{ boottime bsdSysctl }
24
25func init() {
26 registerCollector("boottime", defaultEnabled, newBootTimeCollector)
27}
28
29// newBootTimeCollector returns a new Collector exposing system boot time on BSD systems.
30func 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
42func (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
17package collector 17package collector