Search code examples
javaazureazure-monitor

How to monitor Java Heap usage in Azure Monitor


How do I monitor the heap memory usage of my Java application with Azure Monitor and generate an alert when it's 90% used?

It seems that you can monitor the Heap of the JVM with Zabbix etc., but is it possible to do the same monitoring with Azure Monitor?


Solution

  • Azure recommended way is to use Azure Monitor Application Insights Java 3.0 which does not require any code change to your application. You can take a look at detailed configuration ( especially the JMX counter) here which contains the heap memory.

    <PerformanceCounters>
          <Jmx>
            <Add objectName="java.lang:type=ClassLoading" attribute="TotalLoadedClassCount" displayName="Loaded Class Count"/>
            <Add objectName="java.lang:type=Memory" attribute="HeapMemoryUsage.used" displayName="Heap Memory Usage-used" type="composite"/>
          </Jmx>
        </PerformanceCounters>
    

    For adding alerts on these metrics you can consult the documentation here.