Added node_memory_buffer, node_memory_swaptotal to meminfo_bsd (#451)
This commit is contained in:
parent
84eaa8fecd
commit
bdc2131332
|
@ -22,30 +22,63 @@ import (
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type sysctlType uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
sysctlTypeUint32 sysctlType = iota
|
||||||
|
sysctlTypeUint64
|
||||||
|
)
|
||||||
|
|
||||||
|
type meminfoSysctl struct {
|
||||||
|
name string
|
||||||
|
dataType sysctlType
|
||||||
|
conversion func(uint64) uint64
|
||||||
|
}
|
||||||
|
|
||||||
func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
|
func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
|
||||||
info := make(map[string]float64)
|
info := make(map[string]float64)
|
||||||
|
|
||||||
size, err := unix.SysctlUint32("vm.stats.vm.v_page_size")
|
tmp32, err := unix.SysctlUint32("vm.stats.vm.v_page_size")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %s", err)
|
return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %s", err)
|
||||||
}
|
}
|
||||||
|
size := uint64(tmp32)
|
||||||
|
fromPage := func(v uint64) uint64 {
|
||||||
|
return v * size
|
||||||
|
}
|
||||||
|
|
||||||
for key, v := range map[string]string{
|
for key, v := range map[string]meminfoSysctl{
|
||||||
"active": "vm.stats.vm.v_active_count",
|
"active_bytes": {"vm.stats.vm.v_active_count", sysctlTypeUint32, fromPage},
|
||||||
"inactive": "vm.stats.vm.v_inactive_count",
|
"inactive_bytes": {"vm.stats.vm.v_inactive_count", sysctlTypeUint32, fromPage},
|
||||||
"wire": "vm.stats.vm.v_wire_count",
|
"wired_bytes": {"vm.stats.vm.v_wire_count", sysctlTypeUint32, fromPage},
|
||||||
"cache": "vm.stats.vm.v_cache_count",
|
"cache_bytes": {"vm.stats.vm.v_cache_count", sysctlTypeUint32, fromPage},
|
||||||
"free": "vm.stats.vm.v_free_count",
|
"buffer_bytes": {"vfs.bufspace", sysctlTypeUint32, nil},
|
||||||
"swappgsin": "vm.stats.vm.v_swappgsin",
|
"free_bytes": {"vm.stats.vm.v_free_count", sysctlTypeUint32, fromPage},
|
||||||
"swappgsout": "vm.stats.vm.v_swappgsout",
|
"size_bytes": {"vm.stats.vm.v_page_count", sysctlTypeUint32, fromPage},
|
||||||
"total": "vm.stats.vm.v_page_count",
|
"swap_in_bytes_total": {"vm.stats.vm.v_swappgsin", sysctlTypeUint32, fromPage},
|
||||||
|
"swap_out_bytes_total": {"vm.stats.vm.v_swappgsout", sysctlTypeUint32, fromPage},
|
||||||
|
"swap_size_bytes": {"vm.swap_total", sysctlTypeUint64, nil},
|
||||||
} {
|
} {
|
||||||
value, err := unix.SysctlUint32(v)
|
var tmp64 uint64
|
||||||
|
switch v.dataType {
|
||||||
|
case sysctlTypeUint32:
|
||||||
|
tmp32, err = unix.SysctlUint32(v.name)
|
||||||
|
tmp64 = uint64(tmp32)
|
||||||
|
case sysctlTypeUint64:
|
||||||
|
tmp64, err = unix.SysctlUint64(v.name)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Convert metrics to kB (same as Linux meminfo).
|
|
||||||
info[key] = float64(value) * float64(size)
|
if v.conversion != nil {
|
||||||
|
// Convert to bytes.
|
||||||
|
info[key] = float64(v.conversion(tmp64))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
info[key] = float64(tmp64)
|
||||||
}
|
}
|
||||||
|
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue