You can translate the question and the replies:

How to connect to the Denodo JMX service from java

This isn't so much a question as a "Here is what I did" post. Goal: Monitor the "ActiveRequests" information for my Denodo 5.5 server Problem: The monitoring tool I'm using can't read JMX, but it execute other scripts and parse the output Solution: Write a simple java program to read the ActiveRequests attribute via JMX and output it in JSON format. Code (I know it is quite rudimentary, but it works for me on Denodo 5.5) ``` import java.util.HashMap; import java.util.Map; import; import; import; import; import; public class ReadJmx { public static void main(String[] args) { try{ if (args.length == 0){ System.out.println("Usage:\t\t\t\t\t\tjava -jar ReadJmx.jar servername"); System.out.println("Where servername is a denodo server, e.g.:\tjava -jar ReadJmx.jar dvdrdenodo1"); System.exit(1); } String host = args[0]; ////Eclipse --> Go to Run -> Run Configurations... and Select tab "Arguments". String denodo_unencrypted_password = System.getenv().get("DENODO_UNENCRYPTED_PASSWORD"); //Eclipse --> Go to Run -> Run Configurations... and Select tab "Environment". if (denodo_unencrypted_password == null || denodo_unencrypted_password == ""){ System.out.println("ERROR: Environment Variable 'DENODO_UNENCRYPTED_PASSWORD' not set"); System.exit(1); } JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+host+":9999/jmxrmi"); //for passing credentials for password Map<String, String[]> env = new HashMap<>(); String[] credentials = {"admin", denodo_unencrypted_password}; env.put(JMXConnector.CREDENTIALS, credentials); JMXConnector jmxConnector = JMXConnectorFactory.connect(url, env); MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); System.out.println("{"); System.out.println("\"server\" : \""+host+"\""); ObjectName info = new ObjectName(""); System.out.print(",\"ActiveRequests\" : "); System.out.println(mbeanServerConnection.getAttribute(info, "ActiveRequests")); System.out.println("}"); //FOR FINDING DOMAINS: //System.out.println("\nDomains:"); //String domains[] = mbeanServerConnection.getDomains(); //Arrays.sort(domains); //for (String domain : domains) { // System.out.println("\tDomain = " + domain); //} //System.out.println(mbeanServerConnection.getMBeanCount()); //FOR FINDING ALL THE MBEANS //System.out.println("\nQuery MBeanServer MBeans:"); //Set<ObjectName> names = new TreeSet<ObjectName>(mbeanServerConnection.queryNames(null, null)); //for (ObjectName name : names) { //System.out.println("\tObjectName = " + name); //} jmxConnector.close(); }catch (Exception e){ e.printStackTrace(); } }//method }//class ```
15-06-2016 15:26:09 -0400

2 Answers

Hi! Very interesting post. Can you share the name of the monitoring tool for which you developed this code?
Denodo Team
20-06-2016 21:39:33 -0400
Yep, we are using a custom python script for monitoring. Python doesn't natively speak JMX (from what I can tell), so I needed/wanted a way to get access to the information that is available via JMX.
21-06-2016 11:49:57 -0400
You must sign in to add an answer. If you do not have an account, you can register here