jmx_exporter icon indicating copy to clipboard operation
jmx_exporter copied to clipboard

Export attribute of TabularData not working

Open PestusAtSAG opened this issue 3 years ago • 5 comments
trafficstars

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;
}

PestusAtSAG avatar Jun 13 '22 13:06 PestusAtSAG

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?

fstab avatar Jun 14 '22 11:06 fstab

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

PestusAtSAG avatar Jun 14 '22 13:06 PestusAtSAG

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;
}

PestusAtSAG avatar Jun 14 '22 13:06 PestusAtSAG

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

PestusAtSAG avatar Jun 15 '22 07:06 PestusAtSAG

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;
}

PestusAtSAG avatar Jun 15 '22 08:06 PestusAtSAG

Closed as resolved.

dhoard avatar Jul 08 '23 04:07 dhoard