mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-11-09 23:24:09 -08:00
Convert AIX cpu usage to seconds
This commit is contained in:
parent
163e9325c3
commit
05a8c77433
|
@ -16,7 +16,13 @@
|
|||
|
||||
package collector
|
||||
|
||||
/*
|
||||
#include <unistd.h> // Include the standard Unix header
|
||||
#include <errno.h> // For errno
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
|
@ -25,18 +31,32 @@ import (
|
|||
)
|
||||
|
||||
type cpuCollector struct {
|
||||
cpu typedDesc
|
||||
logger log.Logger
|
||||
cpu typedDesc
|
||||
logger log.Logger
|
||||
tickPerSecond int64
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerCollector("cpu", defaultEnabled, NewCpuCollector)
|
||||
}
|
||||
|
||||
func tickPerSecond() (int64, error) {
|
||||
ticks, err := C.sysconf(C._SC_CLK_TCK)
|
||||
if ticks == -1 || err != nil {
|
||||
return 0, fmt.Errorf("failed to get clock ticks per second: %v", err)
|
||||
}
|
||||
return int64(ticks), nil
|
||||
}
|
||||
|
||||
func NewCpuCollector(logger log.Logger) (Collector, error) {
|
||||
ticks, err := tickPerSecond()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cpuCollector{
|
||||
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
|
||||
logger: logger,
|
||||
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
|
||||
logger: logger,
|
||||
tickPerSecond: ticks,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -47,10 +67,10 @@ func (c *cpuCollector) Update(ch chan<- prometheus.Metric) error {
|
|||
}
|
||||
|
||||
for n, stat := range stats {
|
||||
ch <- c.cpu.mustNewConstMetric(float64(stat.User), strconv.Itoa(n), "user")
|
||||
ch <- c.cpu.mustNewConstMetric(float64(stat.Sys), strconv.Itoa(n), "system")
|
||||
ch <- c.cpu.mustNewConstMetric(float64(stat.Idle), strconv.Itoa(n), "idle")
|
||||
ch <- c.cpu.mustNewConstMetric(float64(stat.Wait), strconv.Itoa(n), "wait")
|
||||
ch <- c.cpu.mustNewConstMetric(float64(stat.User/c.tickPerSecond), strconv.Itoa(n), "user")
|
||||
ch <- c.cpu.mustNewConstMetric(float64(stat.Sys/c.tickPerSecond), strconv.Itoa(n), "system")
|
||||
ch <- c.cpu.mustNewConstMetric(float64(stat.Idle/c.tickPerSecond), strconv.Itoa(n), "idle")
|
||||
ch <- c.cpu.mustNewConstMetric(float64(stat.Wait/c.tickPerSecond), strconv.Itoa(n), "wait")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue