diff options
author | ioriveur <fivo.11235813@gmail.com> | 2018-11-17 19:02:54 +0900 |
---|---|---|
committer | Johannes 'fish' Ziemke <github@freigeist.org> | 2018-11-17 11:02:54 +0100 |
commit | 17fee8081f422ff9bf87cdd6bc572fe746bf2d50 (patch) | |
tree | 4aa93c26e8c411fe7121b4fa42680e0ac0d57e22 /collector | |
parent | 3cf5b006fb22068c8c72b0e7acabc1ae988560d3 (diff) | |
download | prometheus_node_collector-17fee8081f422ff9bf87cdd6bc572fe746bf2d50.tar.bz2 prometheus_node_collector-17fee8081f422ff9bf87cdd6bc572fe746bf2d50.tar.xz prometheus_node_collector-17fee8081f422ff9bf87cdd6bc572fe746bf2d50.zip |
Check BSD's mib which accounts for swap size (#1149)
* Change Dfly's CPU counting frequency, see: https://github.com/prometheus/node_exporter/issues/1129
Signed-off-by: iori-yja <fivio.11235813@gmail.com>
* Convert Dfly's CPU unit into second
Signed-off-by: iori-yja <fivio.11235813@gmail.com>
* Check BSD's mib which accounts for swap size; see #1127
Signed-off-by: iori-yja <fivo.11235813@gmail.com>
* fix swap check code
Signed-off-by: iori-yja <fivo.11235813@gmail.com>
Diffstat (limited to 'collector')
-rw-r--r-- | collector/cpu_dragonfly.go | 19 | ||||
-rw-r--r-- | collector/memory_bsd.go | 9 |
2 files changed, 12 insertions, 16 deletions
diff --git a/collector/cpu_dragonfly.go b/collector/cpu_dragonfly.go index eb7f8f8..b8c4c06 100644 --- a/collector/cpu_dragonfly.go +++ b/collector/cpu_dragonfly.go | |||
@@ -31,7 +31,7 @@ import ( | |||
31 | #include <stdio.h> | 31 | #include <stdio.h> |
32 | 32 | ||
33 | int | 33 | int |
34 | getCPUTimes(uint64_t **cputime, size_t *cpu_times_len, long *freq) { | 34 | getCPUTimes(uint64_t **cputime, size_t *cpu_times_len) { |
35 | size_t len; | 35 | size_t len; |
36 | 36 | ||
37 | // Get number of cpu cores. | 37 | // Get number of cpu cores. |
@@ -44,15 +44,6 @@ getCPUTimes(uint64_t **cputime, size_t *cpu_times_len, long *freq) { | |||
44 | return -1; | 44 | return -1; |
45 | } | 45 | } |
46 | 46 | ||
47 | // The bump on each statclock is | ||
48 | // ((cur_systimer - prev_systimer) * systimer_freq) >> 32 | ||
49 | // where | ||
50 | // systimer_freq = sysctl kern.cputimer.freq | ||
51 | len = sizeof(*freq); | ||
52 | if (sysctlbyname("kern.cputimer.freq", freq, &len, NULL, 0)) { | ||
53 | return -1; | ||
54 | } | ||
55 | |||
56 | // Get the cpu times. | 47 | // Get the cpu times. |
57 | struct kinfo_cputime cp_t[ncpu]; | 48 | struct kinfo_cputime cp_t[ncpu]; |
58 | bzero(cp_t, sizeof(struct kinfo_cputime)*ncpu); | 49 | bzero(cp_t, sizeof(struct kinfo_cputime)*ncpu); |
@@ -103,18 +94,16 @@ func getDragonFlyCPUTimes() ([]float64, error) { | |||
103 | // CPUSTATES (number of CPUSTATES) is defined as 5U. | 94 | // CPUSTATES (number of CPUSTATES) is defined as 5U. |
104 | // States: CP_USER | CP_NICE | CP_SYS | CP_IDLE | CP_INTR | 95 | // States: CP_USER | CP_NICE | CP_SYS | CP_IDLE | CP_INTR |
105 | // | 96 | // |
106 | // Each value is a counter incremented at frequency | 97 | // Each value is in microseconds |
107 | // kern.cputimer.freq | ||
108 | // | 98 | // |
109 | // Look into sys/kern/kern_clock.c for details. | 99 | // Look into sys/kern/kern_clock.c for details. |
110 | 100 | ||
111 | var ( | 101 | var ( |
112 | cpuTimesC *C.uint64_t | 102 | cpuTimesC *C.uint64_t |
113 | cpuTimerFreq C.long | ||
114 | cpuTimesLength C.size_t | 103 | cpuTimesLength C.size_t |
115 | ) | 104 | ) |
116 | 105 | ||
117 | if C.getCPUTimes(&cpuTimesC, &cpuTimesLength, &cpuTimerFreq) == -1 { | 106 | if C.getCPUTimes(&cpuTimesC, &cpuTimesLength) == -1 { |
118 | return nil, errors.New("could not retrieve CPU times") | 107 | return nil, errors.New("could not retrieve CPU times") |
119 | } | 108 | } |
120 | defer C.free(unsafe.Pointer(cpuTimesC)) | 109 | defer C.free(unsafe.Pointer(cpuTimesC)) |
@@ -123,7 +112,7 @@ func getDragonFlyCPUTimes() ([]float64, error) { | |||
123 | 112 | ||
124 | cpuTimes := make([]float64, cpuTimesLength) | 113 | cpuTimes := make([]float64, cpuTimesLength) |
125 | for i, value := range cput { | 114 | for i, value := range cput { |
126 | cpuTimes[i] = float64(value) / float64(cpuTimerFreq) | 115 | cpuTimes[i] = float64(value) / float64(1000000) |
127 | } | 116 | } |
128 | return cpuTimes, nil | 117 | return cpuTimes, nil |
129 | } | 118 | } |
diff --git a/collector/memory_bsd.go b/collector/memory_bsd.go index 8c7265e..00bf3e5 100644 --- a/collector/memory_bsd.go +++ b/collector/memory_bsd.go | |||
@@ -45,6 +45,13 @@ func NewMemoryCollector() (Collector, error) { | |||
45 | } | 45 | } |
46 | size := float64(tmp32) | 46 | size := float64(tmp32) |
47 | 47 | ||
48 | mibSwapTotal := "vm.swap_total" | ||
49 | /* swap_total is FreeBSD specific. Fall back to Dfly specific mib if not present. */ | ||
50 | _, err = unix.SysctlUint32(mibSwapTotal) | ||
51 | if err != nil { | ||
52 | mibSwapTotal = "vm.swap_size" | ||
53 | } | ||
54 | |||
48 | fromPage := func(v float64) float64 { | 55 | fromPage := func(v float64) float64 { |
49 | return v * size | 56 | return v * size |
50 | } | 57 | } |
@@ -98,7 +105,7 @@ func NewMemoryCollector() (Collector, error) { | |||
98 | { | 105 | { |
99 | name: "swap_size_bytes", | 106 | name: "swap_size_bytes", |
100 | description: "Total swap memory size", | 107 | description: "Total swap memory size", |
101 | mib: "vm.swap_total", | 108 | mib: mibSwapTotal, |
102 | dataType: bsdSysctlTypeUint64, | 109 | dataType: bsdSysctlTypeUint64, |
103 | }, | 110 | }, |
104 | // Descriptions via: top(1) | 111 | // Descriptions via: top(1) |