Linux Java App Service performance monitoring with Java New Relic agent

Published Aug 09 2021 02:10 AM 2,383 Views
Microsoft

When running your Java application in Azure Linux App Service, you may encounter performance related issues like high memory consumption, slow dependency calls, etc.
Java New Relic agent is one of the APM tools that can help to provide a better understanding of what may be causing the performance issues.

This article shows a demonstration of how to use New Relic agent to monitor your Java application running in Linux App Service.

 

Prerequisites

  • A New Relic account.
  • Azure App Service for Linux with built-in Java docker image.

 

Setup and Enable Java New Relic agent

Download Java Newrelic agent:

https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip 

Upload the downloaded newrelic-java.zip file to your Azure App Servic:

  1. Inside the App Service /home/site/wwwroot folder, create a new "apm" folder
    - Go to https://<webapp-name>.scm.azurewebsites.net/newui/webssh
    - Use the following command to create a new /home/site/wwwroot/apm folder

 

 

 

 

mkdir -p /home/site/wwwroot/apm

 

 

 

 

 

Hanli_Ren_0-1628063742990.png

2.  Upload the newrelic-java.zip file to /home/site/wwwroot/apm

Hanli_Ren_1-1628063791034.png

 

3. Decompress the /home/site/wwwroot/apm/newrelic-java.zip

 

 

 

 

 

cd /home/site/wwwroot/apm/
unzip newrelic-java.zip

 

 

 

 

 

 

Hanli_Ren_2-1628063886479.png

 

Create Newrelic API keys 

Now we need to get the Newrelic API keys by navigating directly to
1. Create "Ingest-License" key in https://one.newrelic.com/launcher/api-keys-ui.api-keys-launcher

Hanli_Ren_0-1628064022292.png


2. Copy the new create API key, save it in your local notepad.

Hanli_Ren_1-1628064072815.png

 

Configure your Newrelic setting in Azure App Service

1. Go to App Service WEBSSH https://<webapp-name>.scm.azurewebsites.net/newui/webssh

 

 

 

vi /home/site/wwwroot/apm/newrelic/newrelic.yml

 

 

 

 

 

Hanli_Ren_2-1628064158499.png

 

2. Input your Newrelic API Key and

Hanli_Ren_3-1628064190038.png

Hanli_Ren_4-1628064204915.png

Use ":wq" save the change.

 

3. In the App Settings, add "JAVA_OPTS" with Newrelic java agent path.
    JAVA_OPTS = -javaagent:/home/site/wwwroot/apm/newrelic/newrelic.jar

   Hanli_Ren_5-1628064268116.png

   Save the Application Settings change and web app should be automatically restarted.

 

Monitor your Java Application Performance in Newrelic

Go to https://one.newrelic.com/ 
Click "Explorer" tab, in the "Service - APM", we should see your java app showed up in the list. The Name should match your app_name configured in newrelic.yml.

Hanli_Ren_6-1628064333532.png

 

1. Monitor the Application performance Summary.

Hanli_Ren_7-1628064370054.png

 

2. Monitor JVM Memory usage

Hanli_Ren_0-1628064434488.png

 

3. Monitor "Service Map" and "Dependencies"

Hanli_Ren_1-1628064472819.png

List all the dependencies

Hanli_Ren_3-1628064545075.png

 

Check most time consuming external services

Hanli_Ren_4-1628064583093.png

 

4. Run Thread profiler
Set profiling Duration, and click "Start profiler"

Hanli_Ren_0-1628064629434.png

When the profiling starts, run test over your Java App Service.

For example: send requests to https://<webapp-name>.azurewebsites.net/slowurl 

Hanli_Ren_1-1628064629436.png

After the profiling completes, you will be able to click "View the results"

Hanli_Ren_2-1628064629439.png

Hanli_Ren_3-1628064629440.png

 

%3CLINGO-SUB%20id%3D%22lingo-sub-2608926%22%20slang%3D%22en-US%22%3ELinux%20Java%20App%20Service%20performance%20monitoring%20with%20Java%20New%20Relic%20agent%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2608926%22%20slang%3D%22en-US%22%3E%3CP%3EWhen%20running%20your%20Java%20application%20in%20Azure%20Linux%20App%20Service%2C%20you%20may%20encounter%20performance%20related%20issues%20like%20high%20memory%20consumption%2C%20slow%20dependency%20calls%2C%20etc.%3CBR%20%2F%3EJava%20New%20Relic%20agent%20is%20one%20of%20the%20APM%20tools%20that%20can%20help%20to%20provide%20a%20better%20understanding%20of%20what%20may%20be%20causing%20the%20performance%20issues.%3C%2FP%3E%3CP%3EThis%20article%20shows%20a%20demonstration%20of%20how%20to%20use%20New%20Relic%20agent%20to%20monitor%20your%20Java%20application%20running%20in%20Linux%20App%20Service.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EPrerequisites%20A%20%3CA%20href%3D%22https%3A%2F%2Fmicrosoftapc-my.sharepoint.com%2Fpersonal%2Fhanren_microsoft_com%2F_layouts%2FOneNote.aspx%3Fid%3D%252Fpersonal%252Fhanren_microsoft_com%252FDocuments%252FHanli%2520%2540%2520Microsoft%26amp%3Bwd%3Dtarget%2528Blog.one%257CCF92B782-A906-4CA4-BA04-5B073D18B634%252FLinux%2520Java%2520App%2520Service%2520performance%2520monitoring%2520with%2520Java%2520New%2520Relic%257C26EF0317-0669-40C9-8D1A-7DECD79673F7%252F%2529%2520onenote%3Ahttps%3A%2F%2Fmicrosoftapc-my.sharepoint.com%2Fpersonal%2Fhanren_microsoft_com%2FDocuments%2FHanli%2520%40%2520Microsoft%2FBlog.one%23Linux%2520Java%2520App%2520Service%2520performance%2520monitoring%2520with%2520Java%2520New%2520Relic%26amp%3Bsection-id%3D%7BCF92B782-A906-4CA4-BA04-5B073D18B634%7D%26amp%3Bpage-id%3D%7B26EF0317-0669-40C9-8D1A-7DECD79673F7%7D%26amp%3Bobject-id%3D%7BA0610F10-9AF0-00FB-1657-7D00325BF0F9%7D%26amp%3B3B%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ENew%20Relic%3C%2FA%3E%20account.%20Azure%20App%20Service%20for%20Linux%20with%20built-in%20Java%20docker%20image.%20%26nbsp%3B%20Setup%20and%20Enable%20Java%20New%20Relic%20agent%20Download%20Java%20Newrelic%20agent%3A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdownload.newrelic.com%2Fnewrelic%2Fjava-agent%2Fnewrelic-agent%2Fcurrent%2Fnewrelic-java.zip%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fdownload.newrelic.com%2Fnewrelic%2Fjava-agent%2Fnewrelic-agent%2Fcurrent%2Fnewrelic-java.zip%3C%2FA%3E%26nbsp%3B%3C%2FP%3EUpload%20the%20downloaded%20newrelic-java.zip%20file%20to%20your%20Azure%20App%20Servic%3A%20Inside%20the%20App%20Service%20%2Fhome%2Fsite%2Fwwwroot%20folder%2C%20create%20a%20new%20%22apm%22%20folder%3CBR%20%2F%3E-%20Go%20to%20https%3A%2F%2F%3CWEBAPP-NAME%3E.scm.azurewebsites.net%2Fnewui%2Fwebssh%3CBR%20%2F%3E-%20Use%20the%20following%20command%20to%20create%20a%20new%20%2Fhome%2Fsite%2Fwwwroot%2Fapm%20folder%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3Emkdir%20-p%20%2Fhome%2Fsite%2Fwwwroot%2Fapm%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E2.%26nbsp%3B%26nbsp%3BUpload%20the%20newrelic-java.zip%20file%20to%20%2Fhome%2Fsite%2Fwwwroot%2Fapm%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E3.%26nbsp%3BDecompress%20the%20%2Fhome%2Fsite%2Fwwwroot%2Fapm%2Fnewrelic-java.zip%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3Ecd%20%2Fhome%2Fsite%2Fwwwroot%2Fapm%2F%20unzip%20newrelic-java.zip%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3ECreate%20Newrelic%20API%20keys%26nbsp%3B%3CP%3ENow%20we%20need%20to%20get%20the%20Newrelic%20API%20keys%20by%20navigating%20directly%20to%3CBR%20%2F%3E1.%20Create%20%22Ingest-License%22%20key%20in%20%3CA%20href%3D%22https%3A%2F%2Fone.newrelic.com%2Flauncher%2Fapi-keys-ui.api-keys-launcher%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fone.newrelic.com%2Flauncher%2Fapi-keys-ui.api-keys-launcher%3C%2FA%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E2.%20Copy%20the%20new%20create%20API%20key%2C%20save%20it%20in%20your%20local%20notepad.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EConfigure%20your%20Newrelic%20setting%20in%20Azure%20App%20Service%3CP%3E1.%20Go%20to%20App%20Service%20WEBSSH%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2F%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2F%3CWEBAPP-NAME%3E.scm.azurewebsites.net%2Fnewui%2Fwebssh%3C%2FWEBAPP-NAME%3E%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3Evi%20%2Fhome%2Fsite%2Fwwwroot%2Fapm%2Fnewrelic%2Fnewrelic.yml%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2.%20Input%20your%20Newrelic%20API%20Key%20and%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EUse%20%22%3Awq%22%20save%20the%20change.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E3.%20In%20the%20App%20Settings%2C%20add%20%22JAVA_OPTS%22%20with%20Newrelic%20java%20agent%20path.%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20JAVA_OPTS%20%3D%20-javaagent%3A%2Fhome%2Fsite%2Fwwwroot%2Fapm%2Fnewrelic%2Fnewrelic.jar%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3BSave%20the%20Application%20Settings%20change%20and%20web%20app%20should%20be%20automatically%20restarted.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EMonitor%20your%20Java%20Application%20Performance%20in%20Newrelic%3CP%3EGo%20to%20%3CA%20href%3D%22https%3A%2F%2Fone.newrelic.com%2F%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fone.newrelic.com%2F%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3EClick%20%22Explorer%22%20tab%2C%20in%20the%20%22Service%20-%20APM%22%2C%20we%20should%20see%20your%20java%20app%20showed%20up%20in%20the%20list.%20The%20Name%20should%20match%20your%20app_name%20configured%20in%20newrelic.yml.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20Monitor%20the%20Application%20performance%20Summary.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2.%20Monitor%20JVM%20Memory%20usage%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E3.%20Monitor%20%22Service%20Map%22%20and%20%22Dependencies%22%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EList%20all%20the%20dependencies%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheck%20most%20time%20consuming%20external%20services%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E4.%20Run%20Thread%20profiler%3CBR%20%2F%3ESet%20profiling%20Duration%2C%20and%20click%20%22Start%20profiler%22%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EWhen%20the%20profiling%20starts%2C%20run%20test%20over%20your%20Java%20App%20Service.%3C%2FP%3E%3CP%3EFor%20example%3A%20send%20requests%20to%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2F%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2F%3CWEBAPP-NAME%3E.azurewebsites.net%2Fslowurl%3C%2FWEBAPP-NAME%3E%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EAfter%20the%20profiling%20completes%2C%20you%20will%20be%20able%20to%20click%20%22View%20the%20results%22%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FWEBAPP-NAME%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2608926%22%20slang%3D%22en-US%22%3E%3CP%3ELinux%20Java%20App%20Service%20performance%20monitoring%20with%20Java%20New%20Relic%20agent%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Aug 08 2021 02:13 AM
Updated by: