Skip to content

Commit

Permalink
Scope MBeans queries on certain actions only
Browse files Browse the repository at this point in the history
Do not scope MBeans queries on `list_everything` or
`list_not_matching_attributes`.
Fix regression introduced with #63.
  • Loading branch information
yannmh committed Aug 25, 2015
1 parent 3044e39 commit c7c6eac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/datadog/jmxfetch/AppConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.datadog.jmxfetch;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

import org.datadog.jmxfetch.converter.ExitWatcherConverter;
Expand All @@ -23,8 +24,8 @@ class AppConfig {
public static final String ACTION_LIST_NOT_MATCHING = "list_not_matching_attributes";
public static final String ACTION_LIST_LIMITED = "list_limited_attributes";
public static final String ACTION_HELP = "help";
public static final List<String> ACTIONS = Arrays.asList(ACTION_COLLECT, ACTION_LIST_EVERYTHING,
ACTION_LIST_COLLECTED, ACTION_LIST_MATCHING, ACTION_LIST_NOT_MATCHING, ACTION_LIST_LIMITED, ACTION_HELP);
public static final HashSet<String> ACTIONS = new HashSet<String>(Arrays.asList(ACTION_COLLECT, ACTION_LIST_EVERYTHING,
ACTION_LIST_COLLECTED, ACTION_LIST_MATCHING, ACTION_LIST_NOT_MATCHING, ACTION_LIST_LIMITED, ACTION_HELP));

@Parameter(names = {"--help", "-h"},
description = "Display this help page",
Expand Down
29 changes: 20 additions & 9 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,30 @@ public LinkedList<String> getBeansScopes(){
return this.beanScopes;
}


/**
* Query and refresh the instance's list of beans.
* Limit the query scope when possible on certain actions, and fallback if necessary.
*/
private void refreshBeansList() throws IOException {
this.beans = new HashSet<ObjectInstance>();
try {
LinkedList<String> beanScopes = getBeansScopes();
for (String scope : beanScopes) {
ObjectName name = new ObjectName(scope);
this.beans.addAll(connection.queryMBeans(name));
String action = appConfig.getAction();
Boolean limitQueryScopes = !action.equals(AppConfig.ACTION_LIST_EVERYTHING) && !action.equals(AppConfig.ACTION_LIST_EVERYTHING);

if (limitQueryScopes) {
try {
LinkedList<String> beanScopes = getBeansScopes();
for (String scope : beanScopes) {
ObjectName name = new ObjectName(scope);
this.beans.addAll(connection.queryMBeans(name));
}
}
catch (Exception e) {
LOGGER.error("Unable to compute a common bean scope, querying all beans as a fallback", e);
}
}
catch (Exception e) {
LOGGER.error("Unable to compute a common bean scope, querying all beans as a fallback", e);
this.beans = connection.queryMBeans(null);
}

this.beans = (this.beans.isEmpty()) ? connection.queryMBeans(null): this.beans;
this.lastRefreshTime = System.currentTimeMillis();
}

Expand Down

0 comments on commit c7c6eac

Please sign in to comment.