jmx_exporter
jmx_exporter copied to clipboard
Export attribute of TabularData not working
Hello jmx_expoerter team,
i have a spring boot application and MBean which exposes following attribute. I can see the tabular data at jconsole but not at http://localhost:12345/metrics. Is TabularData supported?
The customActionCounterMap is a Map<String, Integer>.
@ManagedAttribute
public TabularData getCounter() throws Exception {
CompositeType compositeType = new CompositeType("CustomAction", "CustomAction", itemNames, itemDescription, itemTypes );
TabularType tabularType = new TabularType(
"CustomAction table",
"CustomAction table",
compositeType,
itemNames);
TabularDataSupport rows = new TabularDataSupport(tabularType);
CompositeData[] compositeData = new CompositeData[customActionCounterMap.size()];
int i = 0;
for (CustomActionRequestKey customActionRequestKey : customActionCounterMap.keySet()) {
CompositeDataSupport compositeDataSupport = new CompositeDataSupport(compositeType, itemNames, new Object[] {customActionRequestKey.toString(), customActionCounterMap.get(customActionRequestKey) });
compositeData[i] = compositeDataSupport;
i++;
}
rows.putAll(compositeData);
return rows;
}
There's a TabularMBean in the integration tests.
The smoke test verifies that the tabular data is successfully exposed:
https://github.com/prometheus/jmx_exporter/blob/21fd1bbcd5ae95f9dc331a7a4b02fc5b45248a85/integration_tests/smoke_tests/src/test/java/io/prometheus/jmx/AgentJavaVersionsIT.java#L97-L102
Do you see any difference between your example and the working example from the integration test?
Yes, sorry, you are right, TabularData is supported, i also can see this at my example application for standard MBeans.
TYPE java_lang_G1_Young_Generation_LastGcInfo_memoryUsageBeforeGc_used untyped java_lang_G1_Young_Generation_LastGcInfo_memoryUsageBeforeGc_used{type="GarbageCollector",key="CodeHeap 'profiled nmethods'",} 2.8525312E7 java_lang_G1_Young_Generation_LastGcInfo_memoryUsageBeforeGc_used{type="GarbageCollector",key="G1 Old Gen",} 8753536.0 java_lang_G1_Young_Generation_LastGcInfo_memoryUsageBeforeGc_used{type="GarbageCollector",key="CodeHeap 'non- ...
However, my TablularData is not exported and i don't know why, even though it is working in jconsole correct. There are some logic on exporter which filters my TabularData. I suppose it doesn't parses the TabularData correct and findes the number value. Could you point me to the code where TabularData is computed? Probably: https://github.com/prometheus/jmx_exporter/blob/master/collector/src/main/java/io/prometheus/jmx/JmxScraper.java#L252
I made my implementation a bit more transparent: This is my Attribute which is working perfectly fine at jconsole:
@ManagedAttribute
public TabularData getSimpleTable() throws Exception {
CompositeType compositeType = new CompositeType(
"Test",
"Test",
new String[]{ "key", "count"},
new String[]{ "key", "count"},
new OpenType[]{SimpleType.STRING, SimpleType.INTEGER});
CompositeData[] data = new CompositeData[3];
data[0] = new CompositeDataSupport(compositeType, new String[] {"key", "count"}, new Object[] {
"Test1", 1,
});
data[1] = new CompositeDataSupport(compositeType, new String[] {"key", "count"}, new Object[] {
"Test2", 2,
});
data[2] = new CompositeDataSupport(compositeType, new String[] {"key", "count"}, new Object[] {
"Test3", 3,
});
TabularType tabularType = new TabularType(
"Table",
"Table",
compositeType,
new String[] { "key", "count" });
TabularDataSupport rows = new TabularDataSupport(tabularType);
rows.putAll(data);
return rows;
}
I debuged the code and i know why my tabular data is not exported. The reason is following line: https://github.com/prometheus/jmx_exporter/blob/21fd1bbcd5ae95f9dc331a7a4b02fc5b45248a85/collector/src/main/java/io/prometheus/jmx/JmxScraper.java#L266
Why are all index names of tabular data gets removed from the valueKeys Set? In my case the tabular type index equal the keys of my composite data object. If they get removed it will never enter loop: https://github.com/prometheus/jmx_exporter/blob/21fd1bbcd5ae95f9dc331a7a4b02fc5b45248a85/collector/src/main/java/io/prometheus/jmx/JmxScraper.java#L285
I have changed my code based on my debugging and now the values get exported. My new code looks like that:
@ManagedAttribute
public TabularData getSimpleTable() throws Exception {
CompositeType compositeType = new CompositeType(
"Test",
"Test",
new String[]{ "key", "value"},
new String[]{ "key", "value"},
new OpenType[]{SimpleType.STRING, SimpleType.INTEGER});
CompositeData[] data = new CompositeData[3];
data[0] = new CompositeDataSupport(compositeType, new String[] {"key", "value"}, new Object[] {
"Test1", 1,
});
data[1] = new CompositeDataSupport(compositeType, new String[] {"key", "value"}, new Object[] {
"Test2", 2,
});
data[2] = new CompositeDataSupport(compositeType, new String[] {"key", "value"}, new Object[] {
"Test3", 3,
});
TabularType tabularType = new TabularType(
"Table",
"Table",
compositeType,
new String[] { "key" });
TabularDataSupport rows = new TabularDataSupport(tabularType);
rows.putAll(data);
return rows;
}
Closed as resolved.