Skip to content

Commit a35ed98

Browse files
committed
add a feature to generate the datasource xml for rrdtool.
1 parent eccf8c8 commit a35ed98

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

heapmemory.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"templateFile" : "heapmemory-rrd-template.xml",
1212
"outputFile" : "target/heap.rrd",
1313
"binaryPath" : "/opt/local/bin",
14-
"debug" : true
14+
"debug" : true,
15+
"generate" : true
1516
}
1617
} ]
1718
} ]

src/com/googlecode/jmxtrans/model/output/RRDToolWriter.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public class RRDToolWriter extends BaseOutputWriter {
4444
private File binaryPath = null;
4545
private static final char[] PERIOD = {'.'};
4646
private static final char[] INITIALS = {' ', '.'};
47-
47+
private static final String GENERATE = "generate";
48+
4849
/** */
4950
public RRDToolWriter() {
5051
}
@@ -106,6 +107,20 @@ public void doWrite(Query query) throws Exception {
106107
}
107108
}
108109

110+
if (isDebugEnabled() && this.getBooleanSetting(GENERATE)) {
111+
StringBuilder sb = new StringBuilder("\n");
112+
for (Result res : results) {
113+
Map<String, Object> values = res.getValues();
114+
if (values != null) {
115+
for (Entry<String, Object> entry : values.entrySet()) {
116+
String key = getDataSourceName(res.getAttributeName(), entry.getKey());
117+
sb.append("<datasource><name>" + key + "</name><type>GAUGE</type><heartbeat>400</heartbeat><min>U</min><max>U</max></datasource>\n");
118+
}
119+
}
120+
}
121+
log.debug(sb.toString());
122+
}
123+
109124
if (dataMap.keySet().size() > 0 && dataMap.values().size() > 0) {
110125
rrdToolUpdate(StringUtils.join(dataMap.keySet(), ':'), StringUtils.join(dataMap.values(), ':'));
111126
} else {

src/com/googlecode/jmxtrans/util/BaseOutputWriter.java

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public void setSettings(Map<String, Object> settings) {
4040
this.settings = settings;
4141
}
4242

43+
public boolean getBooleanSetting(String key) {
44+
return this.getSettings().containsKey(key) ? (Boolean) this.getSettings().get(key) : Boolean.FALSE;
45+
}
46+
4347
@JsonIgnore
4448
public boolean isDebugEnabled() {
4549
if (debugEnabled == null) {

0 commit comments

Comments
 (0)