mirror of
				https://github.com/prometheus/node_exporter.git
				synced 2025-08-20 18:33:52 -07:00 
			
		
		
		
	This should fix it.
This commit is contained in:
		
							parent
							
								
									d98335cbf0
								
							
						
					
					
						commit
						aac89c524e
					
				| 
						 | 
				
			
			@ -103,6 +103,8 @@ void freeCPUTimes(double *cpu_times) {
 | 
			
		|||
*/
 | 
			
		||||
import "C"
 | 
			
		||||
 | 
			
		||||
const MAXCPUTIMESLEN = C.MAXCPU * C.CPUSTATES;
 | 
			
		||||
 | 
			
		||||
type statCollector struct {
 | 
			
		||||
	cpu *prometheus.CounterVec
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -149,10 +151,13 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) {
 | 
			
		|||
	if C.getCPUTimes(&ncpu, &cpuTimesC, &cpuTimesLength) == -1 {
 | 
			
		||||
		return errors.New("could not retrieve CPU times")
 | 
			
		||||
	}
 | 
			
		||||
	defer C.freeCPUTimes(cpuTimesC)
 | 
			
		||||
	defer C.free(unsafe.Pointer(cpuTimesC))
 | 
			
		||||
	if cpuTimesLength > MAXCPUTIMESLEN {
 | 
			
		||||
		return errors.New("more CPU's than MAXCPU?")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Convert C.double array to Go array (https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices).
 | 
			
		||||
	cpuTimes := (*[1 << 30]C.double)(unsafe.Pointer(cpuTimesC))[:cpuTimesLength:cpuTimesLength]
 | 
			
		||||
	cpuTimes := (*[maxCpuTimes]C.double)(unsafe.Pointer(cpuTimesC))[:cpuTimesLength:cpuTimesLength]
 | 
			
		||||
 | 
			
		||||
	for cpu := 0; cpu < int(ncpu); cpu++ {
 | 
			
		||||
		base_idx := C.CPUSTATES * cpu
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue