cancel
Showing results for 
Search instead for 
Did you mean: 

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

josh_barrett
Confirmed Champ
Confirmed Champ

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 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

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 answer in original post

5 REPLIES 5

afaust
Legendary Innovator
Legendary Innovator

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...

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

}

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
Legendary Innovator
Legendary Innovator

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.

This worked like a charm.  Thank you Axel Faust

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