diff options
author | Ben Kochie <superq@gmail.com> | 2018-09-07 22:27:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-07 22:27:52 +0200 |
commit | ebdd5241234b367ebc221a0d942b1183c8df70ab (patch) | |
tree | a5639d2238f57b9e9f4605340f06846718763a6a | |
parent | 05e55bddad50d79e6e5e28c7bfa7adc524135f41 (diff) | |
download | prometheus_node_collector-ebdd5241234b367ebc221a0d942b1183c8df70ab.tar.bz2 prometheus_node_collector-ebdd5241234b367ebc221a0d942b1183c8df70ab.tar.xz prometheus_node_collector-ebdd5241234b367ebc221a0d942b1183c8df70ab.zip |
Correctly cast Darwin memory info (#1060)
* Correctly cast Darwin memory info
* Cast stats to float64 before doing math on them to avoid integer
wrapping.
* Remove invalid `_total` suffix from gauge values.
* Handle counters in `meminfo.go`.
Signed-off-by: Ben Kochie <superq@gmail.com>
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | collector/meminfo.go | 9 | ||||
-rw-r--r-- | collector/meminfo_darwin.go | 16 |
3 files changed, 21 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 1401f84..a119177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md | |||
@@ -1,6 +1,6 @@ | |||
1 | ## master / unreleased | 1 | ## master / unreleased |
2 | 2 | ||
3 | **Breaking changes** | 3 | ### **Breaking changes** |
4 | 4 | ||
5 | supvervisord collector reports "start_time_seconds" rather than "uptime" | 5 | supvervisord collector reports "start_time_seconds" rather than "uptime" |
6 | 6 | ||
@@ -8,6 +8,9 @@ The wifi collector is disabled by default due to suspected caching issues and go | |||
8 | * https://github.com/prometheus/node_exporter/issues/870 | 8 | * https://github.com/prometheus/node_exporter/issues/870 |
9 | * https://github.com/prometheus/node_exporter/issues/1008 | 9 | * https://github.com/prometheus/node_exporter/issues/1008 |
10 | 10 | ||
11 | Darwin meminfo metrics have been renamed to match Prometheus conventions. #1060 | ||
12 | |||
13 | ### Changes | ||
11 | * [CHANGE] Filter out non-installed units when collecting all systemd units #1011 | 14 | * [CHANGE] Filter out non-installed units when collecting all systemd units #1011 |
12 | * [CHANGE] `service_restart_total` and `socket_refused_connections_total` will not be reported if you're running an older version of systemd | 15 | * [CHANGE] `service_restart_total` and `socket_refused_connections_total` will not be reported if you're running an older version of systemd |
13 | * [FEATURE] Collect NRefused property for systemd socket units (available as of systemd v239) | 16 | * [FEATURE] Collect NRefused property for systemd socket units (available as of systemd v239) |
@@ -19,6 +22,7 @@ The wifi collector is disabled by default due to suspected caching issues and go | |||
19 | * [BUGFIX] Fix goroutine leak in supervisord collector | 22 | * [BUGFIX] Fix goroutine leak in supervisord collector |
20 | * [BUGFIX] Systemd units will not be ignored if you're running older versions of systemd #1039 | 23 | * [BUGFIX] Systemd units will not be ignored if you're running older versions of systemd #1039 |
21 | * [BUGFIX] Handle vanishing PIDs #1043 | 24 | * [BUGFIX] Handle vanishing PIDs #1043 |
25 | * [BUGFIX] Correctly cast Darwin memory info #1060 | ||
22 | 26 | ||
23 | ## 0.16.0 / 2018-05-15 | 27 | ## 0.16.0 / 2018-05-15 |
24 | 28 | ||
diff --git a/collector/meminfo.go b/collector/meminfo.go index ffe343a..1652b8b 100644 --- a/collector/meminfo.go +++ b/collector/meminfo.go | |||
@@ -18,6 +18,7 @@ package collector | |||
18 | 18 | ||
19 | import ( | 19 | import ( |
20 | "fmt" | 20 | "fmt" |
21 | "strings" | ||
21 | 22 | ||
22 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
23 | "github.com/prometheus/common/log" | 24 | "github.com/prometheus/common/log" |
@@ -41,19 +42,25 @@ func NewMeminfoCollector() (Collector, error) { | |||
41 | // Update calls (*meminfoCollector).getMemInfo to get the platform specific | 42 | // Update calls (*meminfoCollector).getMemInfo to get the platform specific |
42 | // memory metrics. | 43 | // memory metrics. |
43 | func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error { | 44 | func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error { |
45 | var metricType prometheus.ValueType | ||
44 | memInfo, err := c.getMemInfo() | 46 | memInfo, err := c.getMemInfo() |
45 | if err != nil { | 47 | if err != nil { |
46 | return fmt.Errorf("couldn't get meminfo: %s", err) | 48 | return fmt.Errorf("couldn't get meminfo: %s", err) |
47 | } | 49 | } |
48 | log.Debugf("Set node_mem: %#v", memInfo) | 50 | log.Debugf("Set node_mem: %#v", memInfo) |
49 | for k, v := range memInfo { | 51 | for k, v := range memInfo { |
52 | if strings.HasSuffix(k, "_total") { | ||
53 | metricType = prometheus.CounterValue | ||
54 | } else { | ||
55 | metricType = prometheus.GaugeValue | ||
56 | } | ||
50 | ch <- prometheus.MustNewConstMetric( | 57 | ch <- prometheus.MustNewConstMetric( |
51 | prometheus.NewDesc( | 58 | prometheus.NewDesc( |
52 | prometheus.BuildFQName(namespace, memInfoSubsystem, k), | 59 | prometheus.BuildFQName(namespace, memInfoSubsystem, k), |
53 | fmt.Sprintf("Memory information field %s.", k), | 60 | fmt.Sprintf("Memory information field %s.", k), |
54 | nil, nil, | 61 | nil, nil, |
55 | ), | 62 | ), |
56 | prometheus.GaugeValue, v, | 63 | metricType, v, |
57 | ) | 64 | ) |
58 | } | 65 | } |
59 | return nil | 66 | return nil |
diff --git a/collector/meminfo_darwin.go b/collector/meminfo_darwin.go index 0aa35ce..fc6b7b3 100644 --- a/collector/meminfo_darwin.go +++ b/collector/meminfo_darwin.go | |||
@@ -46,14 +46,14 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { | |||
46 | // Syscall removes terminating NUL which we need to cast to uint64 | 46 | // Syscall removes terminating NUL which we need to cast to uint64 |
47 | total := binary.LittleEndian.Uint64([]byte(totalb + "\x00")) | 47 | total := binary.LittleEndian.Uint64([]byte(totalb + "\x00")) |
48 | 48 | ||
49 | ps := C.natural_t(syscall.Getpagesize()) | 49 | ps := float64(C.natural_t(syscall.Getpagesize())) |
50 | return map[string]float64{ | 50 | return map[string]float64{ |
51 | "active_bytes_total": float64(ps * vmstat.active_count), | 51 | "active_bytes": ps * float64(vmstat.active_count), |
52 | "inactive_bytes_total": float64(ps * vmstat.inactive_count), | 52 | "inactive_bytes": ps * float64(vmstat.inactive_count), |
53 | "wired_bytes_total": float64(ps * vmstat.wire_count), | 53 | "wired_bytes": ps * float64(vmstat.wire_count), |
54 | "free_bytes_total": float64(ps * vmstat.free_count), | 54 | "free_bytes": ps * float64(vmstat.free_count), |
55 | "swapped_in_pages_total": float64(ps * vmstat.pageins), | 55 | "swapped_in_bytes_total": ps * float64(vmstat.pageins), |
56 | "swapped_out_pages_total": float64(ps * vmstat.pageouts), | 56 | "swapped_out_bytes_total": ps * float64(vmstat.pageouts), |
57 | "bytes_total": float64(total), | 57 | "total_bytes": float64(total), |
58 | }, nil | 58 | }, nil |
59 | } | 59 | } |