Skip to content

Commit 12ae086

Browse files
Merge pull request #211254 from AaronMaxwell/patch-2
Updating JFR documentation with a FAQ
2 parents 2b7bb55 + 555ea4f commit 12ae086

File tree

6 files changed

+222
-0
lines changed

6 files changed

+222
-0
lines changed
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
---
2+
title: Java Profiler for Azure Monitor Application Insights
3+
description: How to configure the Azure Monitor Application Insights for Java Profiler
4+
ms.topic: conceptual
5+
ms.date: 07/19/2022
6+
ms.devlang: java
7+
ms.custom: devx-track-java
8+
---
9+
10+
# Java Profiler for Azure Monitor Application Insights
11+
12+
> [!NOTE]
13+
> The Java Profiler feature is in preview, starting from 3.4.0.
14+
15+
The Application Insights Java Profiler provides a system for:
16+
17+
> [!div class="checklist"]
18+
> - Generating JDK Flight Recorder (JFR) profiles on demand from the Java Virtual Machine (JVM).
19+
> - Generating JFR profiles automatically when certain trigger conditions are met from JVM, such as CPU or memory breaching a configured threshold.
20+
21+
## Overview
22+
23+
The Application Insights Java profiler uses the JFR profiler provided by the JVM to record profiling data, allowing users to download the JFR recordings at a later time and analyze them to identify the cause of performance issues.
24+
25+
This data is gathered on demand when trigger conditions are met. The available triggers are thresholds over CPU usage and Memory consumption.
26+
27+
When a threshold is reached, a profile of the configured type and duration is gathered and uploaded. This profile is then visible within the performance blade of the associated Application Insights Portal UI.
28+
29+
> [!WARNING]
30+
> The JFR profiler by default executes the "profile-without-env-data" profile. A JFR file is a series of events emitted by the JVM. The "profile-without-env-data" configuration, is similar to the "profile" configuration that ships with the JVM, however has had some events disabled that have the potential to contain sensitive deployment information such as environment variables, arguments provided to the JVM and processes running on the system.
31+
32+
The flags that have been disabled are:
33+
34+
- jdk.JVMInformation
35+
- jdk.InitialSystemProperty
36+
- jdk.OSInformation
37+
- jdk.InitialEnvironmentVariable
38+
- jdk.SystemProcess
39+
40+
However, you should review all enabled flags to ensure that profiles don't contain sensitive data.
41+
42+
See [Configuring Profile Contents](#configuring-profile-contents) on setting a custom profiler configuration.
43+
44+
## Prerequisites
45+
46+
- JVM with Java Flight Recorder (JFR) capability
47+
- Java 8 update 262+
48+
- Java 11+
49+
50+
> [!WARNING]
51+
> OpenJ9 JVM is not supported
52+
53+
## Usage
54+
55+
### Triggers
56+
57+
For more detailed description of the various triggers available, see [profiler overview](../profiler/profiler-overview.md).
58+
59+
The ApplicationInsights Java Agent monitors CPU and memory consumption and if it breaches a configured threshold a profile is triggered. Both thresholds are a percentage.
60+
61+
#### Profile now
62+
63+
Within the profiler user interface (see [profiler settings](../profiler/profiler-settings.md)) there's a **Profile now** button. Selecting this button will immediately request a profile in all agents that are attached to the Application Insights instance.
64+
65+
#### CPU
66+
67+
CPU threshold is a percentage of the usage of all available cores on the system.
68+
69+
As an example, if one core of an eight core machine were saturated the CPU percentage would be considered 12.5%.
70+
71+
#### Memory
72+
73+
Memory percentage is the current Tenured memory region (OldGen) occupancy against the maximum possible size of the region.
74+
75+
Occupancy is evaluated after a tenured collection has been performed. The maximum size of the tenured region is the size it would be if the JVMs' heap grew to its maximum size.
76+
77+
For instance, take the following scenario:
78+
79+
- The Java heap could grow to a maximum of 1024 mb.
80+
- The Tenured Generation could grow to 90% of the heap.
81+
- Therefore the maximum possible size of tenured would be 922 mb.
82+
- Your threshold was set via the user interface to 75%, therefore your threshold would be 75% of 922 mb, 691 mb.
83+
84+
In this scenario, a profile will occur in the following circumstances:
85+
86+
- Full garbage collection is executed
87+
- The Tenured regions occupancy is above 691 mb after collection
88+
89+
### Installation
90+
91+
The following steps will guide you through enabling the profiling component on the agent and configuring resource limits that will trigger a profile if breached.
92+
93+
1. Configure the resource thresholds that will cause a profile to be collected:
94+
95+
1. Browse to the Performance -> Profiler section of the Application Insights instance.
96+
:::image type="content" source="./media/java-standalone-profiler/performance-blade.png" alt-text="Screenshot of the link to open performance blade." lightbox="media/java-standalone-profiler/performance-blade.png":::
97+
:::image type="content" source="./media/java-standalone-profiler/profiler-button.png" alt-text="Screenshot of the Profiler button from the Performance blade." lightbox="media/java-standalone-profiler/profiler-button.png":::
98+
99+
2. Select "Triggers"
100+
101+
3. Configure the required CPU and Memory thresholds and select Apply.
102+
:::image type="content" source="./media/java-standalone-profiler/cpu-memory-trigger-settings.png" alt-text="Screenshot of trigger settings pane for CPU and Memory triggers.":::
103+
104+
1. Inside the `applicationinsights.json` configuration of your process, enable profiler with the `preview.profiler.enabled` setting:
105+
```json
106+
{
107+
"connectionString" : "...",
108+
"preview" : {
109+
"profiler" : {
110+
"enabled" : true
111+
}
112+
}
113+
}
114+
```
115+
Alternatively, set the `APPLICATIONINSIGHTS_PROFILER_ENABLED` environment variable to true.
116+
117+
1. Restart your process with the updated configuration.
118+
119+
> [!WARNING]
120+
> The Java profiler does not support the "Sampling" trigger. Configuring this will have no effect.
121+
122+
After these steps have been completed, the agent will monitor the resource usage of your process and trigger a profile when the threshold is exceeded. When a profile has been triggered and completed, it will be viewable from the
123+
Application Insights instance within the Performance -> Profiler section. From that screen the profile can be downloaded, once download the JFR recording file can be opened and analyzed within a tool of your choosing, for example JDK Mission Control (JMC).
124+
125+
:::image type="content" source="./media/java-standalone-profiler/configure-blade-inline.png" alt-text="Screenshot of profiler page features and settings." lightbox="media/java-standalone-profiler/configure-blade-inline.png":::
126+
127+
### Configuration
128+
129+
Configuration of the profiler triggering settings, such as thresholds and profiling periods, are set within the ApplicationInsights UI under the Performance, Profiler, Triggers UI as described in [Installation](#installation).
130+
131+
Additionally, many parameters can be configured using environment variables and the `applicationinsights.json` configuration file.
132+
133+
#### Configuring Profile Contents
134+
135+
If you wish to provide a custom profile configuration, alter the `memoryTriggeredSettings`, and `cpuTriggeredSettings` to provide the path to a `.jfc` file with your required configuration.
136+
137+
Profiles can be generated/edited in the JDK Mission Control (JMC) user interface under the `Window->Flight Recording Template Manager` menu and control over individual flags is found inside `Edit->Advanced` of this user interface.
138+
139+
### Environment variables
140+
141+
- `APPLICATIONINSIGHTS_PROFILER_ENABLED`: boolean (default: `false`)
142+
Enables/disables the profiling feature.
143+
144+
### Configuration file
145+
146+
Example configuration:
147+
148+
```json
149+
{
150+
"preview": {
151+
"profiler": {
152+
"enabled": true,
153+
"cpuTriggeredSettings": "profile-without-env-data",
154+
"memoryTriggeredSettings": "profile-without-env-data",
155+
"manualTriggeredSettings": "profile-without-env-data"
156+
}
157+
}
158+
}
159+
160+
```
161+
162+
`memoryTriggeredSettings` This configuration will be used if a memory profile is requested. This value can be one of:
163+
164+
- `profile-without-env-data` (default value). A profile with certain sensitive events disabled, see Warning section above for details.
165+
- `profile`. Uses the `profile.jfc` configuration that ships with JFR.
166+
- A path to a custom jfc configuration file on the file system, i.e `/tmp/myconfig.jfc`.
167+
168+
`cpuTriggeredSettings` This configuration will be used if a cpu profile is requested.
169+
This value can be one of:
170+
171+
- `profile-without-env-data` (default value). A profile with certain sensitive events disabled, see Warning section above for details.
172+
- `profile`. Uses the `profile.jfc` jfc configuration that ships with JFR.
173+
- A path to a custom jfc configuration file on the file system, i.e `/tmp/myconfig.jfc`.
174+
175+
`manualTriggeredSettings` This configuration will be used if a manual profile is requested.
176+
This value can be one of:
177+
178+
- `profile-without-env-data` (default value). A profile with certain sensitive events disabled, see
179+
Warning section above for details.
180+
- `profile`. Uses the `profile.jfc` jfc configuration that ships with JFR.
181+
- A path to a custom jfc configuration file on the file system, i.e `/tmp/myconfig.jfc`.
182+
183+
## Frequently asked questions
184+
185+
### What is Azure Monitor Application Insights Java Profiling?
186+
Azure Monitor Application Insights Java profiler uses Java Flight Recorder (JFR) to profile your application using a customized configuration.
187+
188+
### What is Java Flight Recorder (JFR)?
189+
Java Flight Recorder is a tool for collecting profiling data of a running Java application. It's integrated into the Java Virtual Machine (JVM) and is used for troubleshooting performance issues. Learn more about [Java SE JFR Runtime](https://docs.oracle.com/javacomponents/jmc-5-4/jfr-runtime-guide/about.htm#JFRUH170).
190+
191+
### What is the price and/or licensing fee implications for enabling App Insights Java Profiling?
192+
Java Profiling enablement is a free feature with Application Insights. [Azure Monitor Application Insights pricing](https://azure.microsoft.com/pricing/details/monitor/) is based on ingestion cost.
193+
194+
### Which Java profiling information is collected?
195+
Profiling data collected by the JFR includes: method and execution profiling data, garbage collection data, and lock profiles.
196+
197+
### How can I use App Insights Java Profiling and visualize the data?
198+
JFR recording can be viewed and analyzed with your preferred tool, for example [Java Mission Control (JMC)](https://jdk.java.net/jmc/8/).
199+
200+
### Are performance diagnosis and fix recommendations provided with App Insights Java Profiling?
201+
'Performance diagnostics and recommendations' is a new feature that will be available as Application Insights Java Diagnostics. You may [sign up](https://aka.ms/JavaO11y) to preview this feature. JFR recording can be viewed with Java Mission Control (JMC).
202+
203+
### What's the difference between on-demand and automatic Java Profiling in App Insights?
204+
205+
On-demand is user triggered profiling in real-time whereas automatic profiling is with preconfigured triggers.
206+
207+
Use [Profile Now](https://github.com/johnoliver/azure-docs-pr/blob/add-java-profiler-doc/articles/azure-monitor/profiler/profiler-settings.md) for the on-demand profiling option. [Profile Now](https://github.com/johnoliver/azure-docs-pr/blob/add-java-profiler-doc/articles/azure-monitor/profiler/profiler-settings.md) will immediately profile all agents attached to the Application Insights instance.
208+
209+
Automated profiling is triggered a breach in a resource threshold.
210+
211+
### Which Java profiling triggers can I configure?
212+
Application Insights Java Agent currently supports monitoring of CPU and memory consumption. CPU threshold is configured as a percentage of all available cores on the machine. Memory is the current Tenured memory region (OldGen) occupancy against the maximum possible size of the region.
213+
214+
### What are the required prerequisites to enable Java Profiling?
215+
216+
Review the [Pre-requisites](#prerequisites) at the top of this article.
217+
218+
### Can I use Java Profiling for microservices application?
219+
220+
Yes, you can profile a JVM running microservices using the JFR.
34.8 KB
Loading
15.1 KB
Loading
88.6 KB
Loading
96.3 KB
Loading

articles/azure-monitor/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,8 @@ items:
890890
href: app/java-in-process-agent.md
891891
- name: Spring Boot
892892
href: app/java-spring-boot.md
893+
- name: Java Profiler
894+
href: app/java-standalone-profiler.md
893895
- name: Configuration options
894896
href: app/java-standalone-config.md
895897
- name: Advanced configurations

0 commit comments

Comments
 (0)