Skip to content

Commit

Permalink
Added MBean object exclude capability
Browse files Browse the repository at this point in the history
  • Loading branch information
Satish Reddy M committed Mar 10, 2015
1 parent f6aad72 commit d1393a8
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 46 deletions.
37 changes: 23 additions & 14 deletions src/main/java/com/appdynamics/monitors/kafka/KafkaMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.appdynamics.extensions.util.metrics.MetricFactory;
import com.appdynamics.extensions.yml.YmlReader;
import com.appdynamics.monitors.kafka.config.Configuration;
import com.appdynamics.monitors.kafka.config.Domain;
import com.appdynamics.monitors.kafka.config.KafkaMonitorConstants;
import com.appdynamics.monitors.kafka.config.Server;
import com.google.common.base.Strings;
Expand All @@ -29,7 +30,7 @@
public class KafkaMonitor extends AManagedMonitor {
private static final Logger logger = Logger.getLogger(KafkaMonitor.class);

public static final String METRICS_SEPARATOR = "|";
public static final String METRIC_SEPARATOR = "|";
private static final String CONFIG_ARG = "config-file";
private static final String FILE_NAME = "monitors/KafkaMonitor/config.yml";

Expand Down Expand Up @@ -69,11 +70,11 @@ private Map<String, Number> populateStats(Configuration config) throws Exception
JMXConnector connector = null;
try {
connector = KafkaJMXConnector.connect(server);
List<String> domains = server.getDomains();
for (String domain : domains) {
Set<ObjectInstance> mBeans = KafkaJMXConnector.queryMBeans(connector, domain);
List<Domain> domains = server.getDomains();
for (Domain domain : domains) {
Set<ObjectInstance> mBeans = KafkaJMXConnector.queryMBeans(connector, domain.getName());
if (mBeans != null) {
Map<String, Number> curMetrics = extractMetrics(connector, mBeans);
Map<String, Number> curMetrics = extractMetrics(connector, domain, mBeans);
metrics.putAll(curMetrics);
} else {
logger.debug("Error while getting data from MBean domain" + domain);
Expand All @@ -89,10 +90,18 @@ private Map<String, Number> populateStats(Configuration config) throws Exception
return metrics;
}

private Map<String, Number> extractMetrics(JMXConnector connector, Set<ObjectInstance> allMbeans) {
private Map<String, Number> extractMetrics(JMXConnector connector, Domain domain, Set<ObjectInstance> allMbeans) {
Map<String, Number> metrics = new HashMap<String, Number>();
List<String> excludeObjects = domain.getExcludeObjects();
for (ObjectInstance mbean : allMbeans) {
ObjectName objectName = mbean.getObjectName();

String name = objectName.getKeyProperty("name");
if (excludeObjects.contains(name)) {
String type = objectName.getKeyProperty("type");
logger.debug("Excluding [" + name + "] of type [" + type + "] in domain [" + domain.getName() + "] as configured");
continue; // Skip if the attribute is excluded
}
MBeanAttributeInfo[] attributes = KafkaJMXConnector.fetchAllAttributesForMbean(connector, objectName);
if (attributes != null) {
for (MBeanAttributeInfo attr : attributes) {
Expand Down Expand Up @@ -129,8 +138,8 @@ private String getMetricsKey(ObjectName objectName, MBeanAttributeInfo attr) {
String type = objectName.getKeyProperty("type");
String name = objectName.getKeyProperty("name");

metricsKey.append(objectName.getDomain()).append(METRICS_SEPARATOR).append(type).append(METRICS_SEPARATOR).append(name);
metricsKey.append(METRICS_SEPARATOR).append(attr.getName());
metricsKey.append(objectName.getDomain()).append(METRIC_SEPARATOR).append(type).append(METRIC_SEPARATOR).append(name);
metricsKey.append(METRIC_SEPARATOR).append(attr.getName());
return metricsKey.toString();
}

Expand All @@ -157,22 +166,22 @@ private String getConfigFilename(String filename) {

private void printStats(Configuration config, List<Metric> metrics) {
String metricPathPrefix = config.getMetricPathPrefix();
for(Metric aMetric : metrics){
printMetric(metricPathPrefix + aMetric.getMetricPath(),aMetric.getMetricValue().toString(),aMetric.getAggregator(),aMetric.getTimeRollup(),aMetric.getClusterRollup());
for (Metric aMetric : metrics) {
printMetric(metricPathPrefix + aMetric.getMetricPath(), aMetric.getMetricValue().toString(), aMetric.getAggregator(), aMetric.getTimeRollup(), aMetric.getClusterRollup());
}
}


private void printMetric(String metricName,String metricValue,String aggType,String timeRollupType,String clusterRollupType){
private void printMetric(String metricName, String metricValue, String aggType, String timeRollupType, String clusterRollupType) {
MetricWriter metricWriter = getMetricWriter(metricName,
aggType,
timeRollupType,
clusterRollupType
);
// System.out.println("Sending [" + aggType + METRIC_SEPARATOR + timeRollupType + METRIC_SEPARATOR + clusterRollupType
// + "] metric = " + metricName + " = " + metricValue);
//System.out.println("Sending [" + aggType + METRIC_SEPARATOR + timeRollupType + METRIC_SEPARATOR + clusterRollupType
// + "] metric = " + metricName + " = " + metricValue);
if (logger.isDebugEnabled()) {
logger.debug("Sending [" + aggType + METRICS_SEPARATOR + timeRollupType + METRICS_SEPARATOR + clusterRollupType
logger.debug("Sending [" + aggType + METRIC_SEPARATOR + timeRollupType + METRIC_SEPARATOR + clusterRollupType
+ "] metric = " + metricName + " = " + metricValue);
}
metricWriter.printMetric(metricValue);
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/appdynamics/monitors/kafka/config/Domain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.appdynamics.monitors.kafka.config;


import java.util.List;

public class Domain {
private String name;
private List<String> excludeObjects;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<String> getExcludeObjects() {
return excludeObjects;
}

public void setExcludeObjects(List<String> excludeObjects) {
this.excludeObjects = excludeObjects;
}
}
62 changes: 31 additions & 31 deletions src/main/java/com/appdynamics/monitors/kafka/config/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,49 @@

public class Server {

private String host;
private int port;
private String username;
private String password;
private List<String> domains;
private String host;
private int port;
private String username;
private String password;
private List<Domain> domains;

public String getHost() {
return host;
}
public String getHost() {
return host;
}

public void setHost(String host) {
this.host = host;
}
public void setHost(String host) {
this.host = host;
}

public int getPort() {
return port;
}
public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}
public void setPort(int port) {
this.port = port;
}

public String getUsername() {
return username;
}
public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}
public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}
public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
public void setPassword(String password) {
this.password = password;
}

public List<String> getDomains() {
public List<Domain> getDomains() {
return domains;
}

public void setDomains(List<String> domains) {
public void setDomains(List<Domain> domains) {
this.domains = domains;
}
}
14 changes: 13 additions & 1 deletion src/main/resources/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ server:
port: 9999
username: ""
password: ""
domains: ["\"kafka.server\"", "\"kafka.cluster\"", "\"kafka.controller\"", "\"kafka.network\"", "\"kafka.log\"", "\"kafka.consumer\""]
domains:
- name: "\"kafka.server\""
excludeObjects: ["\"Replica-MaxLag\""]
- name: "\"kafka.cluster\""
excludeObjects: []
- name: "\"kafka.controller\""
excludeObjects: []
- name: "\"kafka.network\""
excludeObjects: []
- name: "\"kafka.log\""
excludeObjects: []
- name: "\"kafka.consumer\""
excludeObjects: []

#prefix used to show up metrics in AppDynamics
metricPathPrefix: "Custom Metrics|Kafka|"
Expand Down

0 comments on commit d1393a8

Please sign in to comment.