Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly cast Darwin memory info #1060

Merged
merged 2 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion collector/meminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package collector

import (
"fmt"
"strings"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
Expand All @@ -41,19 +42,25 @@ func NewMeminfoCollector() (Collector, error) {
// Update calls (*meminfoCollector).getMemInfo to get the platform specific
// memory metrics.
func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error {
var metricType prometheus.ValueType
memInfo, err := c.getMemInfo()
if err != nil {
return fmt.Errorf("couldn't get meminfo: %s", err)
}
log.Debugf("Set node_mem: %#v", memInfo)
for k, v := range memInfo {
if strings.HasSuffix(k, "_total") {
metricType = prometheus.CounterValue
} else {
metricType = prometheus.GaugeValue
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, memInfoSubsystem, k),
fmt.Sprintf("Memory information field %s.", k),
nil, nil,
),
prometheus.GaugeValue, v,
metricType, v,
)
}
return nil
Expand Down
16 changes: 8 additions & 8 deletions collector/meminfo_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
// Syscall removes terminating NUL which we need to cast to uint64
total := binary.LittleEndian.Uint64([]byte(totalb + "\x00"))

ps := C.natural_t(syscall.Getpagesize())
ps := float64(C.natural_t(syscall.Getpagesize()))
return map[string]float64{
"active_bytes_total": float64(ps * vmstat.active_count),
"inactive_bytes_total": float64(ps * vmstat.inactive_count),
"wired_bytes_total": float64(ps * vmstat.wire_count),
"free_bytes_total": float64(ps * vmstat.free_count),
"swapped_in_pages_total": float64(ps * vmstat.pageins),
"swapped_out_pages_total": float64(ps * vmstat.pageouts),
"bytes_total": float64(total),
"active_bytes": ps * float64(vmstat.active_count),
"inactive_bytes": ps * float64(vmstat.inactive_count),
"wired_bytes": ps * float64(vmstat.wire_count),
"free_bytes": ps * float64(vmstat.free_count),
"swapped_in_bytes_total": ps * float64(vmstat.pageins),
"swapped_out_bytes_total": ps * float64(vmstat.pageouts),
"total_bytes": float64(total),
}, nil
}