2015-09-26 08:36:40 -07: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 09:14:17 -08:00
|
|
|
// +build freebsd dragonfly
|
2015-05-12 07:25:28 -07:00
|
|
|
// +build !nomeminfo
|
2015-05-12 01:35:28 -07:00
|
|
|
|
|
|
|
package collector
|
|
|
|
|
|
|
|
import (
|
2016-12-28 17:15:35 -08:00
|
|
|
"fmt"
|
2015-05-12 01:35:28 -07:00
|
|
|
|
2016-12-28 17:15:35 -08:00
|
|
|
"golang.org/x/sys/unix"
|
2015-05-12 01:35:28 -07:00
|
|
|
)
|
|
|
|
|
2016-12-27 03:46:25 -08:00
|
|
|
func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
|
|
|
|
info := make(map[string]float64)
|
2015-05-12 01:35:28 -07:00
|
|
|
|
2017-02-28 21:36:02 -08:00
|
|
|
tmp32, err := unix.SysctlUint32("vm.stats.vm.v_page_size")
|
2016-12-28 17:15:35 -08:00
|
|
|
if err != nil {
|
2016-12-27 03:46:25 -08:00
|
|
|
return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %s", err)
|
2015-05-12 01:35:28 -07:00
|
|
|
}
|
2017-04-11 03:04:14 -07:00
|
|
|
size := float64(tmp32)
|
|
|
|
fromPage := func(v float64) float64 {
|
2017-02-28 21:36:02 -08:00
|
|
|
return v * size
|
|
|
|
}
|
2015-05-12 01:35:28 -07:00
|
|
|
|
2017-03-07 17:54:28 -08:00
|
|
|
for _, ctl := range []bsdSysctl{
|
|
|
|
{name: "active_bytes", mib: "vm.stats.vm.v_active_count", conversion: fromPage},
|
|
|
|
{name: "inactive_bytes", mib: "vm.stats.vm.v_inactive_count", conversion: fromPage},
|
|
|
|
{name: "wired_bytes", mib: "vm.stats.vm.v_wire_count", conversion: fromPage},
|
|
|
|
{name: "cache_bytes", mib: "vm.stats.vm.v_cache_count", conversion: fromPage},
|
2017-10-25 11:55:22 -07:00
|
|
|
{name: "buffer_bytes", mib: "vfs.bufspace", dataType: bsdSysctlTypeCLong},
|
2017-03-07 17:54:28 -08:00
|
|
|
{name: "free_bytes", mib: "vm.stats.vm.v_free_count", conversion: fromPage},
|
|
|
|
{name: "size_bytes", mib: "vm.stats.vm.v_page_count", conversion: fromPage},
|
|
|
|
{name: "swap_in_bytes_total", mib: "vm.stats.vm.v_swappgsin", conversion: fromPage},
|
|
|
|
{name: "swap_out_bytes_total", mib: "vm.stats.vm.v_swappgsout", conversion: fromPage},
|
|
|
|
{name: "swap_size_bytes", mib: "vm.swap_total", dataType: bsdSysctlTypeUint64},
|
2016-12-27 03:46:25 -08:00
|
|
|
} {
|
2017-03-07 17:54:28 -08:00
|
|
|
v, err := ctl.Value()
|
2016-12-27 03:46:25 -08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-02-28 21:36:02 -08:00
|
|
|
|
2017-03-07 17:54:28 -08:00
|
|
|
info[ctl.name] = v
|
2015-05-12 01:35:28 -07:00
|
|
|
}
|
2017-02-28 21:36:02 -08:00
|
|
|
|
2016-12-27 03:46:25 -08:00
|
|
|
return info, nil
|
2015-05-12 01:35:28 -07:00
|
|
|
}
|