@@ -59,35 +59,44 @@ type cpuCollector struct {
5959 cpuFlags typedDesc
6060 cpuContextSwitch typedDesc
6161
62- logger * slog.Logger
63- tickPerSecond int64
62+ logger * slog.Logger
63+ tickPerSecond float64
64+ purrTicksPerSecond float64
6465}
6566
6667func init () {
6768 registerCollector ("cpu" , defaultEnabled , NewCpuCollector )
6869}
6970
70- func tickPerSecond () (int64 , error ) {
71+ func tickPerSecond () (float64 , error ) {
7172 ticks , err := C .sysconf (C ._SC_CLK_TCK )
7273 if ticks == - 1 || err != nil {
7374 return 0 , fmt .Errorf ("failed to get clock ticks per second: %v" , err )
7475 }
75- return int64 (ticks ), nil
76+ return float64 (ticks ), nil
7677}
7778
7879func NewCpuCollector (logger * slog.Logger ) (Collector , error ) {
7980 ticks , err := tickPerSecond ()
8081 if err != nil {
8182 return nil , err
8283 }
84+
85+ pconfig , err := perfstat .PartitionStat ()
86+
87+ if err != nil {
88+ return nil , err
89+ }
90+
8391 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 ),
91100 }, nil
92101}
93102
@@ -99,16 +108,16 @@ func (c *cpuCollector) Update(ch chan<- prometheus.Metric) error {
99108
100109 for n , stat := range stats {
101110 // 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" )
106115
107116 // 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" )
112121
113122 // Run queue length
114123 ch <- c .cpuRunQueue .mustNewConstMetric (float64 (stat .RunQueue ), strconv .Itoa (n ))
0 commit comments