Multi-CPU Usage

In a multi-CPU BIG-IP, what’s the best way to get each CPU’s usage as a percentage?

I’ve muddled through the iControl SDK for a while. I’ve pulled some test values out through iControl but I’m not sure I’m seeing what I’m looking for. I need to get each CPU’s usage, and I need to convert the usage values to a percentage so that I can graph it. Basically, I need to create a CPU usage graph like the Windows Task Manager, updated every few seconds.

I’d appreciate a pointer or an explanation.

Thanks.

Okay, here’s some code that sorta works. But the percentages I’m getting back are around 2.5% during each 5-second polling interval. The BIG-IP GUI shows usage around 7% to 10%.

' CPU METRICS
cpu = BigIPInfo.get_cpu_usage_information()
For t = 0 To cpu.usages.Length - 1
RS.Open("SELECT * FROM CPU ORDER BY Timestamp DESC", Conn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
If RS.EOF Then
    WriteValues = False
    OldTotalCycles = 0
    OldIdleCycles = 0
Else
    WriteValues = True
    OldTotalCycles = RS("TotalCycles").Value
    OldIdleCycles = RS("IdleCycles").Value
End If
RS.AddNew()
RS("CPUNum").Value = cpu.usages(t).cpu_id
' System Cycles
High = cpu.usages(t).system.high
Low = cpu.usages(t).system.low
TotalCycles = Convert_32_to_64(Low, High)
' User Cycles
High = cpu.usages(t).user.high
Low = cpu.usages(t).user.low
TotalCycles += Convert_32_to_64(Low, High)
' Soft IRQ Cycles
High = cpu.usages(t).softirq.high
Low = cpu.usages(t).softirq.low
TotalCycles += Convert_32_to_64(Low, High)
' IRQ Cycles
High = cpu.usages(t).irq.high
Low = cpu.usages(t).irq.low
TotalCycles += Convert_32_to_64(Low, High)
' niced Cycles
High = cpu.usages(t).niced.high
Low = cpu.usages(t).niced.low
TotalCycles += Convert_32_to_64(Low, High)
' IO/WAIT Cycles
High = cpu.usages(t).iowait.high
Low = cpu.usages(t).iowait.low
Value += Convert_32_to_64(Low, High)
' Idle Cycles
High = cpu.usages(t).idle.high
Low = cpu.usages(t).idle.low
IdleCycles = Convert_32_to_64(Low, High)
' Calculate Percentage as Total Cycles (new since last update) divided by Idle Cycles (also since last update)
Percentage = (CType(OldTotalCycles, ULong) - TotalCycles) / (CType(OldIdleCyclesm, ULong) - IdleCycles)
If Not WriteValues Then Percentage = 0
RS("Usage").Value = Percentage
RS("TotalCycles").Value = TotalCycles
RS("IdleCycles").Value = IdleCycles
Dim ThisDate As New Date(cpu.time_stamp.year, cpu.time_stamp.month, cpu.time_stamp.day, cpu.time_stamp.hour, cpu.time_stamp.minute, cpu.time_stamp.second)
RS("Timestamp").Value = ThisDate
RS.Update()
RS.Close()
Next

Here are a few consecutive database records produced by this code:

CPUNumTotalCyclesIdleCyclesUsageTimestamp
070536758382930.026009988/27/2007 11:39:59 AM
070535762382930.026036098/27/2007 11:39:53 AM
0705347653829308/27/2007 11:39:48 AM
070534765382930.025905528/27/2007 11:39:43 AM
0705337733829208/27/2007 11:39:38 AM
070533773382920.025958428/27/2007 11:39:32 AM
0705327793829108/27/2007 11:39:27 AM
070532779382910.026011338/27/2007 11:39:22 AM
0705317833829008/27/2007 11:39:17 AM

Percentage = (CType(OldTotalCycles, ULong) - TotalCycles) / (CType(OldIdleCyclesm, ULong) - IdleCycles)

?

I think that should be Percentage = 1-IdleCycles/TotalCycles; ok