What is the best way to get the CPU utilization information with a webscript

cancel
Showing results for 
Search instead for 
Did you mean: 
josh_barrett
Active Member II

What is the best way to get the CPU utilization information with a webscript

Jump to solution

On the Admin tools there is a system performance page that we use to check the CPU utilization.

I am trying to create a monitor page and want to use that information to mark my server up or down from routing if the server's CPU is pegged.

Can I access that same info displayed on the admin tool with a java backed webscript?

1 Solution

Accepted Solutions
afaust
Master

Re: What is the best way to get the CPU utilization information with a webscript

Jump to solution

The admin tool loads its data via a JSON-based web script that you can use for monitoring as well. See this blog post by Cesar Capillas‌ for examples...

View solution in original post

5 Replies
afaust
Master

Re: What is the best way to get the CPU utilization information with a webscript

Jump to solution

The admin tool loads its data via a JSON-based web script that you can use for monitoring as well. See this blog post by Cesar Capillas‌ for examples...

josh_barrett
Active Member II

Re: What is the best way to get the CPU utilization information with a webscript

Jump to solution

Thanks Axel!   I am using the following to get the info I need.  

http://server:8080/alfresco/s/enterprise/admin/admin-performance?format=json 

which returns JSON that I can use:

{

   FreeMemory: 8478,

   MaxMemory: 18432,

   TotalMemory: 12288,

   CPULoad: 25,

   ThreadCount: 218,

   PeakThreadCount: 225

}

josh_barrett
Active Member II

Re: What is the best way to get the CPU utilization information with a webscript

Jump to solution

Axel Faust‌, Cesar Capillas‌,  Follow up question...  

Is there a way to wire the Admin javascript object into a java backed webscript?   I already have a java backed webscript I am using for my monitor.   

Admin.getMBeanAttributes(
            "java.lang:type=OperatingSystem",
            ["ProcessCpuLoad"]
         );

afaust
Master

Re: What is the best way to get the CPU utilization information with a webscript

Jump to solution

Well, you wouldn't need to. All the data is freely accessible from a Java context without using the Admin JavaScript object. That is the reason why it was so simple for us to re-create the Enterprise Edition-only Support Tools for Community Edition (via the OOTBee Support Tools project). The JavaScript object is only wrapping that access code and exposes it to JavaScript...

Though the OOTBee Support Tools also uses JavaScript code, this basically just access the Java class java.lang.management.ManagementFactory to acecss the memory mbean to view memory metrics.

josh_barrett
Active Member II

Re: What is the best way to get the CPU utilization information with a webscript

Jump to solution

This worked like a charm.  Thank you Axel Faust

OperatingSystemMXBean osBean = (com.sun.management.OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean()
monitorInfo.setCpuUtilization(osBean.processCpuLoad*100)