Collect JVM performance counters with Application Insights

I would like to check the frequency of GC occurrence and the memory usage rate on the JVM. You can get it with jstat etc., but you can also get it with Application Insights with a little modification.

Incorporate Application Insights to send metrics

--Include com.microsoft.azure: applicationinsights-web as a dependency in pom.xml --Call TelemetryConfiguration.getActive (). SetInstrumentationKey (telemetryKey); at initialization etc. to set --ʻAdd ApplicationInsights.xml` as a resource

For example, for Spring Boot, add Change like this.

I wrote a lot in ʻApplicationInsights.xml`, but there is Articles I wrote in the past about this. If you look at the places where you don't like it at all, Java apps aren't popular. lonely. We take as much as possible, including unnecessary ones, so please comment out if necessary.

So, after giving the instrumentation key and executing it, after a while, it will look like this. The default is to collect counters every 60 seconds.

image.png

A stack of Metaspace used, Non Heap used, and Heap used (Metaspace used and Non Heap used have duplicates, so you should remove either one ...)

When aggregating multiple metrics into one Application Insight

There should be cases where two or more units are operated or autoscaled, and what happens in that case?

There is a column called cloud_RoleInstance, which has the host name of the execution environment. By dividing it with this, you can see it for each environment. The following is a case where the number was increased to 2 or 3 on the way.

image.png

Do the same with Log Analytics

Log Analytics is behind Application Insights, so you can get it in the same way.

//Line graph display of MEM Heap Used at 1-minute intervals
performanceCounters 
| where name == 'MEM Heap Used'
| summarize avg(value) by cloud_RoleInstance, bin(timestamp, 1m)
| render timechart 

The execution result looks like this.

image.png

Alert settings

I won't write it because it's annoying, but it looks like a metric for Application Insights, so I can do it properly.

Recommended Posts

Collect JVM performance counters with Application Insights
Trace the SQL executed with the application Insights java agent