diff --git a/conf/monitor.xml b/conf/monitor.xml index 2814e3a..693f9ea 100644 --- a/conf/monitor.xml +++ b/conf/monitor.xml @@ -12,18 +12,29 @@ java 60 - - - - + + + + + + + diff --git a/src/main/java/com/appdynamics/monitors/hadoop/HadoopMonitor.java b/src/main/java/com/appdynamics/monitors/hadoop/HadoopMonitor.java index e67d24e..91fcfe5 100755 --- a/src/main/java/com/appdynamics/monitors/hadoop/HadoopMonitor.java +++ b/src/main/java/com/appdynamics/monitors/hadoop/HadoopMonitor.java @@ -32,14 +32,23 @@ public TaskOutput execute(Map args, TaskExecutionContext arg1) logger.info("Executing HadoopMonitor"); try { - String host = args.get("host"); - String port = args.get("port"); - - String ambariHost = args.get("ambari-host"); - String ambariPort = args.get("ambari-port"); - String ambariUser = args.get("ambari-user"); - String ambariPassword = args.get("ambari-password"); - + boolean hasResourceManager = false; + String hadoopVersion = args.get("hadoop-version"); + String[] hadoopVersionSplit = hadoopVersion.split("\\."); + + try { + int majorVer = Integer.parseInt(hadoopVersionSplit[0]); + if (majorVer == 0) { + if (Integer.parseInt(hadoopVersionSplit[1]) >= 23) { + hasResourceManager = true; + } + } else if (majorVer > 2){ + hasResourceManager = true; + } + } catch (NumberFormatException e){ + hasResourceManager = false; + logger.error("Invalid Hadoop version '" + hadoopVersion + "'"); + } if (!args.get("metric-path").equals("")){ metricPath = args.get("metric-path"); @@ -62,11 +71,19 @@ public TaskOutput execute(Map args, TaskExecutionContext arg1) Map hadoopMetrics = new HashMap(); Map ambariMetrics = new HashMap(); - if (args.get("resource-manager-monitor").equals("true")){ + if (hasResourceManager){ + String host = args.get("host"); + String port = args.get("port"); hadoopCommunicator = new HadoopCommunicator(host,port,logger,xmlParser); hadoopCommunicator.populate(hadoopMetrics); + } else { + logger.warn("Monitor is running without Resource Manager metrics"); } if (args.get("ambari-monitor").equals("true")){ + String ambariHost = args.get("ambari-host"); + String ambariPort = args.get("ambari-port"); + String ambariUser = args.get("ambari-user"); + String ambariPassword = args.get("ambari-password"); ambariCommunicator = new AmbariCommunicator(ambariHost, ambariPort, ambariUser, ambariPassword, logger, xmlParser); ambariCommunicator.populate(ambariMetrics); } diff --git a/src/main/java/com/appdynamics/monitors/hadoop/communicator/AmbariCommunicator.java b/src/main/java/com/appdynamics/monitors/hadoop/communicator/AmbariCommunicator.java index 537cafb..62629b7 100755 --- a/src/main/java/com/appdynamics/monitors/hadoop/communicator/AmbariCommunicator.java +++ b/src/main/java/com/appdynamics/monitors/hadoop/communicator/AmbariCommunicator.java @@ -346,8 +346,12 @@ private void getAllMetrics(Map json, String hierarchy) { if (val instanceof Map){ getAllMetrics((Map) val, hierarchy + "|" + key); } else if (val instanceof Number){ - if (key.startsWith("load_")){ //convert all load factors to integers - metrics.put(hierarchy + "|" + key, (Double) val*100); + if (key.startsWith("load_")){ //convert all load factors to percentage integers + if (val instanceof Double) { + metrics.put(hierarchy + "|" + key, (Double) val*100); + } else { //if Ganglia is down, load metrics are Long + metrics.put(hierarchy + "|" + key, val); + } } else { metrics.put(hierarchy + "|" + key, val); }