@@ -59,35 +59,44 @@ type cpuCollector struct {
59
59
cpuFlags typedDesc
60
60
cpuContextSwitch typedDesc
61
61
62
- logger * slog.Logger
63
- tickPerSecond int64
62
+ logger * slog.Logger
63
+ tickPerSecond float64
64
+ purrTicksPerSecond float64
64
65
}
65
66
66
67
func init () {
67
68
registerCollector ("cpu" , defaultEnabled , NewCpuCollector )
68
69
}
69
70
70
- func tickPerSecond () (int64 , error ) {
71
+ func tickPerSecond () (float64 , error ) {
71
72
ticks , err := C .sysconf (C ._SC_CLK_TCK )
72
73
if ticks == - 1 || err != nil {
73
74
return 0 , fmt .Errorf ("failed to get clock ticks per second: %v" , err )
74
75
}
75
- return int64 (ticks ), nil
76
+ return float64 (ticks ), nil
76
77
}
77
78
78
79
func NewCpuCollector (logger * slog.Logger ) (Collector , error ) {
79
80
ticks , err := tickPerSecond ()
80
81
if err != nil {
81
82
return nil , err
82
83
}
84
+
85
+ pconfig , err := perfstat .PartitionStat ()
86
+
87
+ if err != nil {
88
+ return nil , err
89
+ }
90
+
83
91
return & cpuCollector {
84
- cpu : typedDesc {nodeCPUSecondsDesc , prometheus .CounterValue },
85
- cpuPhysical : typedDesc {nodeCPUPhysicalSecondsDesc , prometheus .CounterValue },
86
- cpuRunQueue : typedDesc {nodeCPUSRunQueueDesc , prometheus .GaugeValue },
87
- cpuFlags : typedDesc {nodeCPUFlagsDesc , prometheus .GaugeValue },
88
- cpuContextSwitch : typedDesc {nodeCPUContextSwitchDesc , prometheus .CounterValue },
89
- logger : logger ,
90
- tickPerSecond : ticks ,
92
+ cpu : typedDesc {nodeCPUSecondsDesc , prometheus .CounterValue },
93
+ cpuPhysical : typedDesc {nodeCPUPhysicalSecondsDesc , prometheus .CounterValue },
94
+ cpuRunQueue : typedDesc {nodeCPUSRunQueueDesc , prometheus .GaugeValue },
95
+ cpuFlags : typedDesc {nodeCPUFlagsDesc , prometheus .GaugeValue },
96
+ cpuContextSwitch : typedDesc {nodeCPUContextSwitchDesc , prometheus .CounterValue },
97
+ logger : logger ,
98
+ tickPerSecond : ticks ,
99
+ purrTicksPerSecond : float64 (pconfig .ProcessorMhz * 1e6 ),
91
100
}, nil
92
101
}
93
102
@@ -99,16 +108,16 @@ func (c *cpuCollector) Update(ch chan<- prometheus.Metric) error {
99
108
100
109
for n , stat := range stats {
101
110
// LPAR metrics
102
- ch <- c .cpu .mustNewConstMetric (float64 (stat .User / c .tickPerSecond ) , strconv .Itoa (n ), "user" )
103
- ch <- c .cpu .mustNewConstMetric (float64 (stat .Sys / c .tickPerSecond ) , strconv .Itoa (n ), "system" )
104
- ch <- c .cpu .mustNewConstMetric (float64 (stat .Idle / c .tickPerSecond ) , strconv .Itoa (n ), "idle" )
105
- ch <- c .cpu .mustNewConstMetric (float64 (stat .Wait / c .tickPerSecond ) , strconv .Itoa (n ), "wait" )
111
+ ch <- c .cpu .mustNewConstMetric (float64 (stat .User ) / c .tickPerSecond , strconv .Itoa (n ), "user" )
112
+ ch <- c .cpu .mustNewConstMetric (float64 (stat .Sys ) / c .tickPerSecond , strconv .Itoa (n ), "system" )
113
+ ch <- c .cpu .mustNewConstMetric (float64 (stat .Idle ) / c .tickPerSecond , strconv .Itoa (n ), "idle" )
114
+ ch <- c .cpu .mustNewConstMetric (float64 (stat .Wait ) / c .tickPerSecond , strconv .Itoa (n ), "wait" )
106
115
107
116
// Physical CPU metrics
108
- ch <- c .cpuPhysical .mustNewConstMetric (float64 (stat .PIdle / c .tickPerSecond ) , strconv .Itoa (n ), "pidle" )
109
- ch <- c .cpuPhysical .mustNewConstMetric (float64 (stat .PUser / c .tickPerSecond ) , strconv .Itoa (n ), "puser" )
110
- ch <- c .cpuPhysical .mustNewConstMetric (float64 (stat .PSys / c .tickPerSecond ) , strconv .Itoa (n ), "psys" )
111
- ch <- c .cpuPhysical .mustNewConstMetric (float64 (stat .PWait / c .tickPerSecond ) , strconv .Itoa (n ), "pwait" )
117
+ ch <- c .cpuPhysical .mustNewConstMetric (float64 (stat .PIdle ) / c .purrTicksPerSecond , strconv .Itoa (n ), "pidle" )
118
+ ch <- c .cpuPhysical .mustNewConstMetric (float64 (stat .PUser ) / c .purrTicksPerSecond , strconv .Itoa (n ), "puser" )
119
+ ch <- c .cpuPhysical .mustNewConstMetric (float64 (stat .PSys ) / c .purrTicksPerSecond , strconv .Itoa (n ), "psys" )
120
+ ch <- c .cpuPhysical .mustNewConstMetric (float64 (stat .PWait ) / c .purrTicksPerSecond , strconv .Itoa (n ), "pwait" )
112
121
113
122
// Run queue length
114
123
ch <- c .cpuRunQueue .mustNewConstMetric (float64 (stat .RunQueue ), strconv .Itoa (n ))
0 commit comments