Add BSD exec statistics collector (#457)
* First pass of a sysctl_bsd source, exec_bsd + exec metrics * Incorportate PR feedback, including removing pre-build descriptions, unit conversion callback. * Remove redundant cached_description field, per PR feedback * Incorporate PR feedback
This commit is contained in:
parent
c6e66756b3
commit
5c28ab044d
4 changed files with 170 additions and 1 deletions
70
collector/sysctl_bsd.go
Normal file
70
collector/sysctl_bsd.go
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// +build freebsd dragonfly
|
||||
// +build !nomeminfo
|
||||
|
||||
package collector
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
type bsdSysctlType uint8
|
||||
|
||||
// BSD-specific sysctl value types. There is an impedience mismatch between
|
||||
// native C types, e.g. int vs long, and the golang unix.Sysctl variables
|
||||
|
||||
const (
|
||||
// Default to uint32.
|
||||
bsdSysctlTypeUint32 bsdSysctlType = iota
|
||||
bsdSysctlTypeUint64
|
||||
)
|
||||
|
||||
// Contains all the info needed to map a single bsd-sysctl to a prometheus value.
|
||||
type bsdSysctl struct {
|
||||
// Prometheus name
|
||||
name string
|
||||
|
||||
// Simple prometheus description
|
||||
description string
|
||||
|
||||
// Prometheus type
|
||||
valueType prometheus.ValueType
|
||||
|
||||
// Sysctl name
|
||||
mib string
|
||||
|
||||
// Sysctl data-type
|
||||
dataType bsdSysctlType
|
||||
}
|
||||
|
||||
func (b bsdSysctl) Value() (float64, error) {
|
||||
var tmp32 uint32
|
||||
var tmp64 uint64
|
||||
var err error
|
||||
|
||||
switch b.dataType {
|
||||
case bsdSysctlTypeUint32:
|
||||
tmp32, err = unix.SysctlUint32(b.mib)
|
||||
tmp64 = uint64(tmp32)
|
||||
case bsdSysctlTypeUint64:
|
||||
tmp64, err = unix.SysctlUint64(b.mib)
|
||||
}
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return float64(tmp64), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue