Node_Exporter/collector/meminfo_bsd.go

52 lines
1.5 KiB
Go
Raw Normal View History

2015-09-26 17:36:40 +02:00
// Copyright 2015 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2016-12-27 18:14:17 +01:00
// +build freebsd dragonfly
// +build !nomeminfo
2015-05-12 10:35:28 +02:00
package collector
import (
"fmt"
2015-05-12 10:35:28 +02:00
"golang.org/x/sys/unix"
2015-05-12 10:35:28 +02:00
)
func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
info := make(map[string]float64)
2015-05-12 10:35:28 +02:00
size, err := unix.SysctlUint32("vm.stats.vm.v_page_size")
if err != nil {
return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %s", err)
2015-05-12 10:35:28 +02:00
}
for key, v := range map[string]string{
"active": "vm.stats.vm.v_active_count",
"inactive": "vm.stats.vm.v_inactive_count",
"wire": "vm.stats.vm.v_wire_count",
"cache": "vm.stats.vm.v_cache_count",
"free": "vm.stats.vm.v_free_count",
"swappgsin": "vm.stats.vm.v_swappgsin",
"swappgsout": "vm.stats.vm.v_swappgsout",
"total": "vm.stats.vm.v_page_count",
} {
value, err := unix.SysctlUint32(v)
if err != nil {
return nil, err
}
// Convert metrics to kB (same as Linux meminfo).
info[key] = float64(value) * float64(size)
2015-05-12 10:35:28 +02:00
}
return info, nil
2015-05-12 10:35:28 +02:00
}