aboutsummaryrefslogtreecommitdiff
path: root/collector/meminfo.go
diff options
context:
space:
mode:
authorBen Kochie <superq@gmail.com>2018-09-07 22:27:52 +0200
committerGitHub <noreply@github.com>2018-09-07 22:27:52 +0200
commitebdd5241234b367ebc221a0d942b1183c8df70ab (patch)
treea5639d2238f57b9e9f4605340f06846718763a6a /collector/meminfo.go
parent05e55bddad50d79e6e5e28c7bfa7adc524135f41 (diff)
downloadprometheus_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>
Diffstat (limited to 'collector/meminfo.go')
-rw-r--r--collector/meminfo.go9
1 files changed, 8 insertions, 1 deletions
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
19import ( 19import (
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.
43func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error { 44func (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