jmx_vcms
TRANSCRIPT
Confidential and proprietary materials for authorized Verizon personnel and outside agencies only. Use, disclosure or distribution of this material is not permitted to any unauthorized persons or third parties except by written agreement. 1
JMX
Java Management Extensions (JMX) is a Java technology that supplies tools
for managing and monitoring java based applications, system objects,
devices and service oriented networks. Those resources are represented by
objects called MBeans (for Managed Bean).
What is JMX ?
Confidential and proprietary materials for authorized Verizon personnel and outside agencies only. Use, disclosure or distribution of this material is not permitted to any unauthorized persons or third parties except by written agreement. 2
JMX Agent & Remote Management
JMX
JMX Agent
The main component of a JMX agent is the MBean server. This is a core
managed object server in which MBeans are registered. A JMX agent also
includes a set of services for handling MBeans. JMX agents directly control
resources and make them available to remote management agents.
Remote Management
Protocol adaptors and standard connectors make a JMX agent accessible
from remote management applications outside the agent’s Java Virtual
Machine (Java VM) using the JMX URL
(Sample URL : service:jmx:rmi://192.168.7.46:12345/jndi/rmi://192.168.7.46:12345/jmxrmi)
Confidential and proprietary materials for authorized Verizon personnel and outside agencies only. Use, disclosure or distribution of this material is not permitted to any unauthorized persons or third parties except by written agreement. 3
JMX architecture
JMX
Confidential and proprietary materials for authorized Verizon personnel and outside agencies only. Use, disclosure or distribution of this material is not permitted to any unauthorized persons or third parties except by written agreement. 4
Enabling JMX on Tomcat
JMX
CATALINA_OPTS="${CATALINA_OPTS}
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=4447
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false"
1. Go to folder /usr/share/tomcat6/bin (this may differ based on the tomcat version)
2. Create a setenv.sh file with below contents (or add to it if one already exists).
#!/bin/sh
export CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=4447 -
Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false“
Note: You can alternatively put this into catalina.sh
3. Save file and restart Tomcat as root user : service tomcat6 restart (this may differ based on the tomcat version)
Ref : https://tomcat.apache.org/tomcat-6.0-doc/monitoring.html#Enabling_JMX_Remote
Confidential and proprietary materials for authorized Verizon personnel and outside agencies only. Use, disclosure or distribution of this material is not permitted to any unauthorized persons or third parties except by written agreement. 5
Campaign Portal – JMX Integration
JMX
Mbean interface: (../WebPortal/vsdp-jmx/src/main/java/com/verizon/vsdp/jmx/VsdpManagementMBean.java)
public interface VsdpManagementMBean {
public int getNewCampaignsStat();
public int getCampaignsBudgetStat();
}
Note: By convention, an MBean interface takes the name of the Java class that implements it, with the suffix MBean added.
Confidential and proprietary materials for authorized Verizon personnel and outside agencies only. Use, disclosure or distribution of this material is not permitted to any unauthorized persons or third parties except by written agreement. 6
Campaign Portal – JMX Integration (Continued..)
JMX
Mbean Implementation: (../WebPortal/vsdp-jmx/src/main/java/com/verizon/vsdp/jmx/VsdpJmxManagement.java)
public class VsdpJmxManagement extends NotificationBroadcasterSupport implements VsdpManagementMBean {
….
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName cusPortal = new ObjectName("VSDP:type=Customer Portal");
mbs.registerMBean(this, cusPortal);
int newCampaignsStatVal=0;
public void incrementNewCampaignsStat() {
newCampaignsStatVal ++;
}
….
@Override
public int getNewCampaignsStat() {
return newCampaignsStatVal;
}
….
public void sendNotification(String notificationTitle, String notificationMsg, String notificationOldMsg){
Notification n = new AttributeChangeNotification(this, sequenceNumber++, System.currentTimeMillis(),
notificationTitle, "Message", "String", notificationOldMsg, notificationMsg);
sendNotification(n);
}
}
Confidential and proprietary materials for authorized Verizon personnel and outside agencies only. Use, disclosure or distribution of this material is not permitted to any unauthorized persons or third parties except by written agreement. 7
Campaign Portal – JMX Integration (Continued..)
JMX
JMX stats call: (../WebPortal/vsdp/src/main/java/com/verizon/vsdp/controller/ServiceController.java)
public String createService (@RequestBody CreateUpdateServiceRequest req,
@RequestParam(value=TokenUtils.VSDP_TOKEN, required=true) String token,
@RequestParam(value=TokenUtils.USER, required=true) String userName,
HttpServletRequest request, HttpServletResponse response) throws TfdsCampaignException {
….
String codeSnippet = scmService.createService(req.getService(), req.getRatings(), userName);
if (codeSnippet == null)
throw new TfdsCampaignException("tfdsCampaignCreationError");
else {
….
VsdpJmxManagement.getInstance().incrementNewCampaignsStat();
return sendSuccessResponse(response, "{\"codesnippetid\":\"" + codeSnippet + "\"}");
}
….
}
Confidential and proprietary materials for authorized Verizon personnel and outside agencies only. Use, disclosure or distribution of this material is not permitted to any unauthorized persons or third parties except by written agreement. 8
Campaign Portal – JMX Integration (Continued..)
JMX
JMX notification call: (../WebPortal/vsdp/src/main/java/com/verizon/vsdp/service/SvcService.java)
private final String CD_JMX_NOTFN_TITLE = "Campaign Director connection issue";
public CampaignDirectorResponse invokeRestTemplate(Object service, String event) throws Exception {
...
try {
...
CampaignDirectorResponse cdResposne = responseEntity.getBody();
return cdResposne;
} catch (Exception exc){
logger.error("CD transaction ID {} with Exception {}", uuid,exc.getMessage());
//VPCMS call : Raise an alarm if the exception is due to CD connection loss
if (exc.getMessage().contains("java.net.ConnectException")) {
VsdpJmxManagement.getInstance().sendNotification(CD_JMX_NOTFN_TITLE, exc.getMessage(), "");
}
}
return null;
}
Confidential and proprietary materials for authorized Verizon personnel and outside agencies only. Use, disclosure or distribution of this material is not permitted to any unauthorized persons or third parties except by written agreement. 9
JConsole
Using JConsole for verification
JConsole is a graphical monitoring tool to monitor Java Virtual Machine (JVM) and Java applications both on
a local or remote machine. JConsole uses underlying features of Java Virtual Machine to provide information
on performance and resource consumption of applications running on the Java platform using Java
Management Extensions (JMX) technology. JConsole comes as part of Java Development Kit (JDK) and the
graphical console can be started using "jconsole" command.
Using Jconsole:
1. Download JDK to your laptop / desktop.
2. Start JConsole
3. Enable JMX on tomcat and start the tomcat process
4. Enter process url as “service:jmx:rmi:///jndi/rmi://192.168.7.46:4447/jmxrmi” (Replace the IP with your tomcat IP)
5. Click on “Insecure” button on the next screen if prompted.
6. Click on “MBeans” tab in the next screen after which you should see a screen as shown in fig. 1
7. The applications exposing MBeans would be shown in the console listing the attributes
Confidential and proprietary materials for authorized Verizon personnel and outside agencies only. Use, disclosure or distribution of this material is not permitted to any unauthorized persons or third parties except by written agreement. 10
Jconsole- Fig. 1
Using JConsole for verification