Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags per query #128

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ private void buildQueries(Element rootElement, JmxTransExporterConfiguration con

}
Integer collectInterval = intAttributeOrNull(queryElement, COLLECT_INTERVAL_NAME);
String tags = queryElement.hasAttribute("tags") ? queryElement.getAttribute("tags") : null;

configuration.withQuery(objectName, attributes, key, position, type, resultAlias, collectInterval);
configuration.withQuery(objectName, attributes, key, position, type, resultAlias, collectInterval, tags);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ public JmxTransExporterConfiguration withQuery(@Nonnull String objectName, @Nonn

public JmxTransExporterConfiguration withQuery(@Nonnull String objectName, @Nonnull List<String> attributes, @Nullable String key,
@Nullable Integer position, @Nullable String type, @Nullable String resultAlias, @Nullable Integer collectInterval) {
Query query = new Query(objectName, attributes, key, position, type, resultAlias, this.resultNameStrategy, collectInterval);
return withQuery(objectName, attributes, null, null, null, resultAlias, collectInterval, null);
}

public JmxTransExporterConfiguration withQuery(@Nonnull String objectName, @Nonnull List<String> attributes, @Nullable String key,
@Nullable Integer position, @Nullable String type, @Nullable String resultAlias, @Nullable Integer collectInterval, @Nullable String tags) {
Query query = new Query(objectName, attributes, key, position, type, resultAlias, this.resultNameStrategy, collectInterval, tags);
queries.add(query);
return this;
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/jmxtrans/agent/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public class Query implements Collector {
@Nullable
private Integer collectInterval;

@Nullable
private List<Tag> tags;

/**
* @see #Query(String, String, String, Integer, String, String, ResultNameStrategy)
*/
Expand Down Expand Up @@ -133,15 +136,20 @@ public Query(@Nonnull String objectName, @Nullable String attribute, @Nullable S
private static boolean nullOrEmtpy(String attribute) {
return attribute == null || attribute.isEmpty();
}


public Query(@Nonnull String objectName, @Nonnull List<String> attributes, @Nullable String key, @Nullable Integer position,
@Nullable String type, @Nullable String resultAlias, @Nonnull ResultNameStrategy resultNameStrategy, @Nullable Integer collectInterval) {
this(objectName, attributes, key, position, type, resultAlias, resultNameStrategy, null, null);
}

/**
* Creates a query that accepts a list of attributes to collect. If the list is empty, all attributes will be collected.
* @param collectInterval
*
* @see #Query(String, String, String, Integer, String, String, ResultNameStrategy)
*/
public Query(@Nonnull String objectName, @Nonnull List<String> attributes, @Nullable String key, @Nullable Integer position,
@Nullable String type, @Nullable String resultAlias, @Nonnull ResultNameStrategy resultNameStrategy, @Nullable Integer collectInterval) {
@Nullable String type, @Nullable String resultAlias, @Nonnull ResultNameStrategy resultNameStrategy, @Nullable Integer collectInterval, @Nullable String tags) {
try {
this.objectName = new ObjectName(Preconditions2.checkNotNull(objectName));
} catch (MalformedObjectNameException e) {
Expand All @@ -154,6 +162,7 @@ public Query(@Nonnull String objectName, @Nonnull List<String> attributes, @Null
this.type = type;
this.resultNameStrategy = Preconditions2.checkNotNull(resultNameStrategy, "resultNameStrategy");
this.collectInterval = collectInterval;
this.tags = Tag.tagsFromCommaSeparatedString(tags);
}


Expand Down