Rest API for CPU utilization

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rest API for CPU utilization

L2 Linker

Hello, 

 

I'm trying to create a Rest API URL to check the CPU utilization on my management and data planes and create a report to monitor over time. Using commands like show running resource-monitor did not give me exactly what I was looking for. I used the <firewall ip>/debug and got the following XML:

 

<response status="success">
<status>
<stats>
<mp-cpu-utilization>8</mp-cpu-utilization>
<dp-cpu-utilization>17</dp-cpu-utilization>
</stats>
</status>
</response>

 

I'm having problems getting it into Rest API URL format and wanted to see if someone more experienced with this could help. Thank you!

2 REPLIES 2

Cyber Elite
Cyber Elite

This is actually generated through a collection of things that you can't easily mimic via the API. I guess the real question would be what you are trying to get with this information and why? It's going to be a lot of scripting to get this anywhere close to what you are looking at in the debug console. 

 

Session information:

Can be gathered a few ways; but for those running multiple vsys it's easiest to simply do the following since it breaks down the <current/> number of sessions by <vsys/>

 

/api/?type=op&cmd=<show><session><meter></meter></session></show>

If you only have a sole <vsys> then you can simply run the session info and get the value of <num-active/>

/api/?type=op&cmd=<show><session><info></info></session></show>

Management CPU Utilization:

There really isn't an easy way to parse the result due to the data structure. 

/api/?type=op&cmd=<show><system><resources></resources></system></show>

 

Dataplane CPU Utilization: 

This would depend on how opten you are running this, I provided an hour. 

/api/?type=op&cmd=<show><running><resource-monitor><hour><last>1</last></hour></resource-monitor></running></show>

You would have to average a lot of the return results to get the same result that you presented due to how the data is actually strucutred. 

L7 Applicator

@BPry wrote:

Management CPU Utilization:

There really isn't an easy way to parse the result due to the data structure. 

/api/?type=op&cmd=<show><system><resources></resources></system></show>

With some regex this shouldn't be a problem (here an example that fetches the different CPU values that this output provides in regex capture groups:

^top\s-\s\d\d:\d\d:\d\d\sup\s\d{1,3}\sdays,\s\d\d:\d\d,\s\d{1,2}\susers,\sload\saverage:\s(\d{1,3}\.\d{1,3}),\s(\d{1,3}\.\d{1,3}),\s(\d{1,3}\.\d{1,3})\sTasks:\s\d{1,3}\stotal,\s\d{1,3}\srunning,\s\d{1,3}\ssleeping,\s\d{1,3}\sstopped,\s\d{1,3}\szombie\sCpu\(s\):\s(\d{1,3}\.\d{1,3})%us,\s(\d{1,3}\.\d{1,3})%sy,\s(\d{1,3}\.\d{1,3})%ni,\s(\d{1,3}\.\d{1,3})
  • 4576 Views
  • 2 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!