Skip to content

Instantly share code, notes, and snippets.

@johntdyer
Created April 29, 2011 20:31
Show Gist options
  • Select an option

  • Save johntdyer/948982 to your computer and use it in GitHub Desktop.

Select an option

Save johntdyer/948982 to your computer and use it in GitHub Desktop.
<%@ page contentType="application/json; charset=UTF-8" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.management.*" %>
<%@ page import="javax.management.*" %>
<%
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
final PrintWriter os = new PrintWriter(out);
MBeanInfo mbeanServer = server.getMBeanInfo(new ObjectName("com.micromethod.sipmethod:type=server.module.container.application,name=tropo"));
MBeanAttributeInfo[] attributes = mbeanServer.getAttributes();
%>
<%
os.println("{\"tropo\":{");
os.println("\"System\":{");
os.println("\"StartedTime\":" + ((Long) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "StartedTime")).longValue()+",");
os.println("\"Revision\":\"" + ((String) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "Revision")).toString()+"\",");
os.println("\"OSName\":\"" + ((String) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "OSName")).toString()+"\",");
os.println("\"InstallId\":\"" + ((String) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "InstallId")).toString()+"\",");
os.println("\"SystemId\":\"" + ((String) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "SystemId")).toString()+"\",");
os.println("\"OSArchitecture\":\"" + ((String) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "OSArchitecture")).toString()+"\",");
os.println("\"counters\":{");
if(String.valueOf(request.getParameter("type")).equalsIgnoreCase("long")){
for(int x=0; x<attributes.length;x++){
if(attributes[x].isReadable()){
final Object value = server.getAttribute(new ObjectName("com.micromethod.sipmethod:type=server.module.container.application,name=tropo"), attributes[x].getName());
if(value instanceof Long){
os.println("\""+ attributes[x].getName() + "\":"+value);
if(x!=attributes.length-1){
os.println(",");
}
}
}
}
}else{
// Ports in use
os.println("\"licenseInUse\":{");
os.println("\"appSessions\":" + ((Long) server.getAttribute(new ObjectName("com.micromethod.sipmethod:type=server.module.container.application,name=tropo"), "ActiveAppSession")).longValue()+",");
os.println("\"AppSessionCPS\":" + ((Long) server.getAttribute(new ObjectName("com.micromethod.sipmethod:type=server.module.container.application,name=tropo"), "AppSessionCPS")).longValue()+",");
os.println("\"AppSessionCreated\":" + ((Long) server.getAttribute(new ObjectName("com.micromethod.sipmethod:type=server.module.container.application,name=tropo"), "AppSessionCreated")).longValue()+",");
os.println("\"AppSessionDestroyed\":" + ((Long) server.getAttribute(new ObjectName("com.micromethod.sipmethod:type=server.module.container.application,name=tropo"), "AppSessionDestroyed")).longValue()+",");
os.println("\"HighActiveAppSession\":" + ((Long) server.getAttribute(new ObjectName("com.micromethod.sipmethod:type=server.module.container.application,name=tropo"), "HighActiveAppSession")).longValue());
os.println("},");
os.println("\"licensedPorts\":{");
os.println("\"APPPortInLicense\":" + ((Integer) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "APPPortInLicense")).intValue()+",");
os.println("\"ASRPortInLicense\":" + ((Integer) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "ASRPortInLicense")).intValue()+",");
os.println("\"HTTPPortInLicense\":" + ((Integer) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "HTTPPortInLicense")).intValue()+",");
os.println("\"XMPPPortInLicense\":" + ((Integer) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "XMPPPortInLicense")).intValue()+",");
os.println("\"MediaPortInLicense\":" + ((Integer) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "MediaPortInLicense")).intValue()+",");
os.println("\"TTSPortInLicense\":" + ((Integer) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "TTSPortInLicense")).intValue()+",");
os.println("\"SIPPortInLicense\":" + ((Integer) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "SIPPortInLicense")).intValue());
os.println("},");
os.println("\"java\":{");
os.println("\"JDKVendor\":\"" + ((String) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "JDKVendor")).toString()+"\",");
os.println("\"JDKVersion\":\"" + ((String) server.getAttribute(new ObjectName("com.micromethod.sipmethod:name=serverinfo"), "JDKVersion")).toString()+"\"");
os.println("}");
}
os.println("}}}}");
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment