Skip to content

Commit

Permalink
Added version argument in monitor.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen.dong committed Nov 1, 2013
1 parent b432fb0 commit e5ca1bd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
23 changes: 17 additions & 6 deletions conf/monitor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@
<type>java</type>
<execution-timeout-in-secs>60</execution-timeout-in-secs>
<task-arguments>
<!-- ENABLE/DISABLE RESOURCE MANAGER METRICS
To enable or diable Hadoop Resource Manager metrics, set
default-value="true" or "false"
<!-- HADOOP VERSION
The Hadoop version for the cluster you want to monitor using Resource Manager.
Example:
1.3, 2.2, 0.23
-->
<argument name="resource-manager-monitor" is-required="true" default-value="true" />
<argument name="host" is-required="true" default-value="localhost" />
<argument name="port" is-required="true" default-value="8088" />
<argument name="hadoop-version" is-required="true" default-value="1.3" />

<!-- ENABLE/DISABLE AMBARI METRICS
To enable or diable Ambari metrics, set default-value="true" or "false"
Ambari metrics are only available for clusters inistalled using Ambari,
manual installs are not eligible
-->
<argument name="ambari-monitor" is-required="true" default-value="false" />

<!-- RESOURCE MANAGER CONFIGS
Resource Manager is only usable for Hadoop 2.x and Hadoop 0.23.x
-->
<argument name="host" is-required="true" default-value="localhost" />
<argument name="port" is-required="true" default-value="8088" />

<!-- AMBARI CONFIGS
Only configure if 'ambari-monitor' is set to 'true'
-->
<argument name="ambari-host" is-required="true" default-value="localhost" />
<argument name="ambari-port" is-required="true" default-value="8080" />
<argument name="ambari-user" is-required="true" default-value="admin" />
Expand Down
35 changes: 26 additions & 9 deletions src/main/java/com/appdynamics/monitors/hadoop/HadoopMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,23 @@ public TaskOutput execute(Map<String, String> 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");
Expand All @@ -62,11 +71,19 @@ public TaskOutput execute(Map<String, String> args, TaskExecutionContext arg1)
Map<String, Object> hadoopMetrics = new HashMap<String, Object>();
Map<String, Object> ambariMetrics = new HashMap<String, Object>();

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,12 @@ private void getAllMetrics(Map<String, Object> 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);
}
Expand Down

0 comments on commit e5ca1bd

Please sign in to comment.