mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-28 06:59:44 -08:00
Creating slice from C-array
Might not be lined up correctly? Weird output data in the second CPU.
This commit is contained in:
parent
03da1ea516
commit
1b7a18c271
|
@ -18,6 +18,7 @@ package collector
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
@ -175,9 +176,11 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
if C.getCPUTimes(&ncpu, &cpuTimesC, &cpuTimesLength) == -1 {
|
if C.getCPUTimes(&ncpu, &cpuTimesC, &cpuTimesLength) == -1 {
|
||||||
return errors.New("could not retrieve CPU times")
|
return errors.New("could not retrieve CPU times")
|
||||||
}
|
}
|
||||||
|
// TODO: Remember to free variables
|
||||||
// defer C.freeCPUTimes(cpuTimesC)
|
// defer C.freeCPUTimes(cpuTimesC)
|
||||||
fmt.Println(cpuTimesC)
|
|
||||||
fmt.Println(uint64(cpuTimesLength))
|
cpuTimes := (*[1 << 30]C.struct_kinfo_cputime)(unsafe.Pointer(&cpuTimesC))[:ncpu:ncpu]
|
||||||
|
fmt.Println(cpuTimes)
|
||||||
return errors.New("early kill")
|
return errors.New("early kill")
|
||||||
if cpuTimesLength > maxCPUTimesLen {
|
if cpuTimesLength > maxCPUTimesLen {
|
||||||
return errors.New("more CPU's than MAXCPU?")
|
return errors.New("more CPU's than MAXCPU?")
|
||||||
|
|
Loading…
Reference in a new issue