aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--collector/exec_bsd.go98
-rw-r--r--collector/sysctl_bsd.go70
-rw-r--r--node_exporter.go2
4 files changed, 170 insertions, 1 deletions
diff --git a/README.md b/README.md
index 0c4822f..9d742d8 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,7 @@ cpu | Exposes CPU statistics | Darwin, Dragonfly, FreeBSD
26diskstats | Exposes disk I/O statistics from `/proc/diskstats`. | Linux 26diskstats | Exposes disk I/O statistics from `/proc/diskstats`. | Linux
27edac | Exposes error detection and correction statistics. | Linux 27edac | Exposes error detection and correction statistics. | Linux
28entropy | Exposes available entropy. | Linux 28entropy | Exposes available entropy. | Linux
29exec | Exposes execution statistics. | Dragonfly, FreeBSD
29filefd | Exposes file descriptor statistics from `/proc/sys/fs/file-nr`. | Linux 30filefd | Exposes file descriptor statistics from `/proc/sys/fs/file-nr`. | Linux
30filesystem | Exposes filesystem statistics, such as disk space used. | Darwin, Dragonfly, FreeBSD, Linux, OpenBSD 31filesystem | Exposes filesystem statistics, such as disk space used. | Darwin, Dragonfly, FreeBSD, Linux, OpenBSD
31hwmon | Expose hardware monitoring and sensor data from `/sys/class/hwmon/`. | Linux 32hwmon | Expose hardware monitoring and sensor data from `/sys/class/hwmon/`. | Linux
diff --git a/collector/exec_bsd.go b/collector/exec_bsd.go
new file mode 100644
index 0000000..0c79458
--- /dev/null
+++ b/collector/exec_bsd.go
@@ -0,0 +1,98 @@
1// Copyright 2017 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
15// +build !noexec
16
17package collector
18
19import (
20 "github.com/prometheus/client_golang/prometheus"
21)
22
23type execCollector struct {
24 sysctls []bsdSysctl
25}
26
27func init() {
28 Factories["exec"] = NewExecCollector
29}
30
31// NewExecCollector returns a new Collector exposing system execution statistics
32func NewExecCollector() (Collector, error) {
33 // From sys/vm/vm_meter.c:
34 // All are of type CTLTYPE_UINT.
35 //
36 // vm.stats.sys.v_swtch: Context switches
37 // vm.stats.sys.v_trap: Traps
38 // vm.stats.sys.v_syscall: System calls
39 // vm.stats.sys.v_intr: Device interrupts
40 // vm.stats.sys.v_soft: Software interrupts
41 // vm.stats.vm.v_forks: Number of fork() calls
42
43 return &execCollector{
44 sysctls: []bsdSysctl{
45 {
46 name: "context_switches_total",
47 description: "Context switches since system boot. Resets at architeture unsigned integer.",
48 mib: "vm.stats.sys.v_swtch",
49 },
50 {
51 name: "traps_total",
52 description: "Traps since system boot. Resets at architeture unsigned integer.",
53 mib: "vm.stats.sys.v_trap",
54 },
55 {
56 name: "system_calls_total",
57 description: "System calls since system boot. Resets at architeture unsigned integer.",
58 mib: "vm.stats.sys.v_syscall",
59 },
60 {
61 name: "device_interrupts_total",
62 description: "Device interrupts since system boot. Resets at architeture unsigned integer.",
63 mib: "vm.stats.sys.v_intr",
64 },
65 {
66 name: "software_interrupts_total",
67 description: "Software interrupts since system boot. Resets at architeture unsigned integer.",
68 mib: "vm.stats.sys.v_soft",
69 },
70 {
71 name: "forks_total",
72 description: "Number of fork() calls since system boot. Resets at architeture unsigned integer.",
73 mib: "vm.stats.vm.v_forks",
74 },
75 },
76 }, nil
77}
78
79// Update pushes exec statistics onto ch
80func (c *execCollector) Update(ch chan<- prometheus.Metric) (err error) {
81 for _, m := range c.sysctls {
82 v, err := m.Value()
83 if err != nil {
84 return err
85 }
86
87 // We "know" all of our sysctls are CounterValues, let's skip
88 // parsing them
89 ch <- prometheus.MustNewConstMetric(
90 prometheus.NewDesc(
91 prometheus.BuildFQName(Namespace, "exec", m.name),
92 m.description,
93 nil, nil,
94 ), prometheus.CounterValue, v)
95 }
96
97 return nil
98}
diff --git a/collector/sysctl_bsd.go b/collector/sysctl_bsd.go
new file mode 100644
index 0000000..fcb8af5
--- /dev/null
+++ b/collector/sysctl_bsd.go
@@ -0,0 +1,70 @@
1// Copyright 2017 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
15// +build !nomeminfo
16
17package collector
18
19import (
20 "github.com/prometheus/client_golang/prometheus"
21 "golang.org/x/sys/unix"
22)
23
24type bsdSysctlType uint8
25
26// BSD-specific sysctl value types. There is an impedience mismatch between
27// native C types, e.g. int vs long, and the golang unix.Sysctl variables
28
29const (
30 // Default to uint32.
31 bsdSysctlTypeUint32 bsdSysctlType = iota
32 bsdSysctlTypeUint64
33)
34
35// Contains all the info needed to map a single bsd-sysctl to a prometheus value.
36type bsdSysctl struct {
37 // Prometheus name
38 name string
39
40 // Simple prometheus description
41 description string
42
43 // Prometheus type
44 valueType prometheus.ValueType
45
46 // Sysctl name
47 mib string
48
49 // Sysctl data-type
50 dataType bsdSysctlType
51}
52
53func (b bsdSysctl) Value() (float64, error) {
54 var tmp32 uint32
55 var tmp64 uint64
56 var err error
57
58 switch b.dataType {
59 case bsdSysctlTypeUint32:
60 tmp32, err = unix.SysctlUint32(b.mib)
61 tmp64 = uint64(tmp32)
62 case bsdSysctlTypeUint64:
63 tmp64, err = unix.SysctlUint64(b.mib)
64 }
65 if err != nil {
66 return 0, err
67 }
68
69 return float64(tmp64), nil
70}
diff --git a/node_exporter.go b/node_exporter.go
index ec69c05..1a505cf 100644
--- a/node_exporter.go
+++ b/node_exporter.go
@@ -32,7 +32,7 @@ import (
32) 32)
33 33
34const ( 34const (
35 defaultCollectors = "conntrack,cpu,diskstats,entropy,edac,filefd,filesystem,hwmon,infiniband,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,vmstat,wifi,zfs" 35 defaultCollectors = "conntrack,cpu,diskstats,entropy,edac,exec,filefd,filesystem,hwmon,infiniband,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,vmstat,wifi,zfs"
36) 36)
37 37
38var ( 38var (