collector: Implement uname collector for FreeBSD (#1239)
* collector: Implement uname collector for FreeBSD Signed-off-by: David O'Rourke <david.orourke@gmail.com>
This commit is contained in:
parent
2b81bff518
commit
d442108d7a
5 changed files with 144 additions and 40 deletions
|
|
@ -18,49 +18,23 @@ package collector
|
|||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var unameDesc = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "uname", "info"),
|
||||
"Labeled system information as provided by the uname system call.",
|
||||
[]string{
|
||||
"sysname",
|
||||
"release",
|
||||
"version",
|
||||
"machine",
|
||||
"nodename",
|
||||
"domainname",
|
||||
},
|
||||
nil,
|
||||
)
|
||||
|
||||
type unameCollector struct{}
|
||||
|
||||
func init() {
|
||||
registerCollector("uname", defaultEnabled, newUnameCollector)
|
||||
}
|
||||
|
||||
// NewUnameCollector returns new unameCollector.
|
||||
func newUnameCollector() (Collector, error) {
|
||||
return &unameCollector{}, nil
|
||||
}
|
||||
|
||||
func (c unameCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
var uname unix.Utsname
|
||||
if err := unix.Uname(&uname); err != nil {
|
||||
return err
|
||||
func getUname() (uname, error) {
|
||||
var utsname unix.Utsname
|
||||
if err := unix.Uname(&utsname); err != nil {
|
||||
return uname{}, err
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(unameDesc, prometheus.GaugeValue, 1,
|
||||
string(uname.Sysname[:bytes.IndexByte(uname.Sysname[:], 0)]),
|
||||
string(uname.Release[:bytes.IndexByte(uname.Release[:], 0)]),
|
||||
string(uname.Version[:bytes.IndexByte(uname.Version[:], 0)]),
|
||||
string(uname.Machine[:bytes.IndexByte(uname.Machine[:], 0)]),
|
||||
string(uname.Nodename[:bytes.IndexByte(uname.Nodename[:], 0)]),
|
||||
string(uname.Domainname[:bytes.IndexByte(uname.Domainname[:], 0)]),
|
||||
)
|
||||
return nil
|
||||
output := uname{
|
||||
SysName: string(utsname.Sysname[:bytes.IndexByte(utsname.Sysname[:], 0)]),
|
||||
Release: string(utsname.Release[:bytes.IndexByte(utsname.Release[:], 0)]),
|
||||
Version: string(utsname.Version[:bytes.IndexByte(utsname.Version[:], 0)]),
|
||||
Machine: string(utsname.Machine[:bytes.IndexByte(utsname.Machine[:], 0)]),
|
||||
NodeName: string(utsname.Nodename[:bytes.IndexByte(utsname.Nodename[:], 0)]),
|
||||
DomainName: string(utsname.Domainname[:bytes.IndexByte(utsname.Domainname[:], 0)]),
|
||||
}
|
||||
|
||||
return output, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue