Skip to content

Commit c06907d

Browse files
author
Jill Grant
authored
Merge pull request #292112 from frankliu20/frank/feat-grafana
feat: add tutorial to integrate with azure managed grafana for aca
2 parents 12f513d + 997d2a5 commit c06907d

File tree

9 files changed

+171
-2
lines changed

9 files changed

+171
-2
lines changed

articles/container-apps/TOC.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@
397397
- name: Create a highly available Eureka server component cluster
398398
href: java-eureka-server-highly-available.md
399399
displayName: java
400+
- name: Build a Java metrics dashboard with Azure Managed Grafana
401+
href: java-metrics-with-grafana.md
402+
displayName: java
400403
- name: Billing & quotas
401404
items:
402405
- name: Billing
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
title: "Tutorial: Build a Java metrics dashboard with Azure Managed Grafana"
3+
description: Learn to build a Java metrics dashboard with Azure Managed Grafana.
4+
services: container-apps
5+
author: craigshoemaker
6+
ms.service: azure-container-apps
7+
ms.custom: devx-track-extended-java
8+
ms.topic: tutorial
9+
ms.date: 12/18/2024
10+
ms.author: cshoe
11+
#customer intent: As a developer, I want to build a grafa dashboard for Java metrics exposed from Azure Container Apps
12+
---
13+
14+
# Tutorial: Build a Java metrics dashboard with Azure Managed Grafana
15+
16+
In this tutorial, you will learn how to set up a metrics dashboard using Azure Managed Grafana to monitor Java applications running in Azure Container Apps.
17+
18+
Grafana is a popular tool for centralized metrics visualization and monitoring in the observability industry. Azure Managed Grafana is a fully managed Azure service that allows you to deploy and manage Grafana dashboards with seamless Azure integration. You can use Azure Managed Grafana to visualize Java metrics exposed by Azure Container Apps or integrate Java metrics into your existing Grafana dashboards.
19+
20+
In this tutorial, you:
21+
> [!div class="checklist"]
22+
> * Create an Azure Managed Grafana instance.
23+
> * Create a Java metrics dashboard in Grafana.
24+
> * Visualize Java metrics for Azure Container Apps with Grafana.
25+
26+
## Prerequisites
27+
28+
* An Azure account with an active subscription. If you don't already have one, you can [can create one for free](https://azure.microsoft.com/free/).
29+
* [Azure CLI](/cli/azure/install-azure-cli).
30+
* [A Java application deployed in Azure Container Apps](java-get-started.md).
31+
32+
## Set up the environment
33+
34+
Use the following steps to define environment variables and ensure your Azure Managed Grafana extension is up to date.
35+
36+
1. Create variables to support your Grafana configuration.
37+
```bash
38+
export LOCATION=eastus
39+
export SUBSCRIPTION_ID={subscription-id}
40+
export RESOURCE_GROUP=grafana-resource-group
41+
export GRAFANA_INSTANCE_NAME=grafana-name
42+
```
43+
44+
| Variable | Description |
45+
|-------------------------|------------------------------------------------------------------------------------|
46+
| `LOCATION` | The Azure region location where you create your Azure Managed Grafana instance. |
47+
| `SUBSCRIPTION_ID` | The subscription ID which you use to create your Azure Container Apps and Azure Managed Grafana instance. |
48+
| `RESOURCE_GROUP` | The Azure resource group name for your Azure Managed Grafana instance. |
49+
| `GRAFANA_INSTANCE_NAME` | The instance name for your Azure Managed Grafana instance. |
50+
51+
52+
1. Log in to Azure with the Azure CLI.
53+
54+
```azurecli
55+
az login
56+
```
57+
58+
1. Create a resource group.
59+
60+
```azurecli
61+
az group create --name $RESOURCE_GROUP --location $LOCATION
62+
```
63+
64+
1. Use the following command to ensure that you have the latest version of the Azure CLI extensions for Azure Managed Grafana.
65+
66+
```azurecli
67+
az extension add --name amg --upgrade
68+
```
69+
70+
71+
## Set up an Azure Managed Grafana instance
72+
73+
First, create an Azure Managed Grafana instance, and grant necessary role assignments.
74+
75+
1. Create an Azure Managed Grafana instance.
76+
77+
```azurecli
78+
az grafana create \
79+
--name $GRAFANA_INSTANCE_NAME \
80+
--resource-group $RESOURCE_GROUP \
81+
--location $LOCATION
82+
```
83+
84+
1. Grant the Azure Managed Grafana instance "Monitoring Reader" role to read metrics from Azure Monitor. Find more about the [authentication and permissions for Azure Managed Grafana](../managed-grafana/how-to-authentication-permissions.md).
85+
86+
```azurecli
87+
GRAFA_IDDENTITY=$(az grafana show --name $GRAFANA_INSTANCE_NAME --resource-group $RESOURCE_GROUP --query "identity.principalId" --output tsv)
88+
89+
az role assignment create --assignee $GRAFA_IDDENTITY --role "Monitoring Reader" --scope /subscriptions/$SUBSCRIPTION_ID
90+
```
91+
92+
## Create a Java metrics dashboard
93+
94+
> [!IMPORTANT]
95+
> To add a new dashboard in Grafana, you need to have `Grafana Admin` or `Grafana Editor`role, see [Azure Managed Grafana roles](../managed-grafana/concept-role-based-access-control.md).
96+
97+
98+
1. Assign the `Grafana Admin` role to your account on the Azure Managed Grafana resource.
99+
100+
Get the resource ID for your Azure Managed Grafana instance.
101+
```azurecli
102+
GRAFANA_RESOURCE_ID=$(az grafana show --resource-group $RESOURCE_GROUP --name $GRAFANA_INSTANCE_NAME --query id --output tsv)
103+
```
104+
105+
Before running this command, replace the `<USER_OR_SERVICE_PRINCIPAL_ID>` placeholder with your user or service principal ID.
106+
107+
```azurecli
108+
az role assignment create \
109+
--assignee <USER_OR_SERVICE_PRINCIPAL_ID> \
110+
--role "Grafana Admin" \
111+
--scope $GRAFANA_RESOURCE_ID
112+
```
113+
114+
1. Download the [sample Java metric dashboard for Azure Container Apps](https://github.com/Azure-Samples/java-microservices-aca-lab/blob/main/dashboard/aca-java-metrics-dashboard.json) json file.
115+
116+
1. Get the endpoint of the Azure Managed Grafana resource.
117+
118+
```azurecli
119+
az grafana show --resource-group $RESOURCE_GROUP \
120+
--name $GRAFANA_INSTANCE_NAME \
121+
--query "properties.endpoint" \
122+
--output tsv
123+
```
124+
This command returns the URL you can use to access the Azure Managed Grafana dashboard. Open your browser with URL and login.
125+
126+
1. Go to `Dashboard` > `New` -> `Import`. Upload the above sample dashboard JSON file, and choose the default built-in `Azure Monitor` data source, then click `Import` button.
127+
128+
:::image type="content" source="media/java-metrics-with-grafana/import-java-dashboard.png" alt-text="Screenshot of importing Java metric dashboard for Azure Container Apps." lightbox="media/java-metrics-with-grafana/import-java-dashboard.png":::
129+
130+
131+
## Visualize Java metrics for Azure Container Apps with Grafana
132+
133+
1. Input your resource information in the filters for your Azure Container Apps. Now you can view all the [supported Java metrics in Azure Container Apps](java-metrics.md) within the dashboard. The sample dashboard provides live metric data, including
134+
- Container App Overview
135+
- JVM Memory Usage
136+
- JVM Memory Buffer
137+
- JVM GC JVM GC
138+
- A detailed JVM Memory Usage Analysis
139+
140+
:::image type="content" source="media/java-metrics-with-grafana/grafana-overview.png" alt-text="Screenshot of Overview tab in Grafana." lightbox="media/java-metrics-with-grafana/grafana-overview.png":::
141+
142+
:::image type="content" source="media/java-metrics-with-grafana/Grafana-jvm-memory.png" alt-text="Screenshot of JVM memory tab in Grafana." lightbox="media/java-metrics-with-grafana/grafana-jvm-memory.png":::
143+
144+
:::image type="content" source="media/java-metrics-with-grafana/grafana-jvm-buffer.png" alt-text="Screenshot of JVM buffer memory tab in Grafana." lightbox="media/java-metrics-with-grafana/grafana-jvm-buffer.png":::
145+
146+
:::image type="content" source="media/java-metrics-with-grafana/grafana-jvm-gc.png" alt-text="Screenshot of JVM GC tab in Grafana." lightbox="media/java-metrics-with-grafana/grafana-jvm-gc.png":::
147+
148+
:::image type="content" source="media/java-metrics-with-grafana/grafana-jvm-memory-analysis.png" alt-text="Screenshot of JVM memory analysis tab in Grafana." lightbox="media/java-metrics-with-grafana/grafana-jvm-memory-analysis.png":::
149+
150+
151+
You can use this dashboard as a starting point to create your own customized metric visualizations and monitoring solution.
152+
153+
154+
## Clean up resources
155+
156+
The resources created in this tutorial have an effect on your Azure bill. If you aren't going to use these services long-term, run the following command to remove everything created in this tutorial.
157+
158+
```azurecli
159+
az group delete --resource-group $RESOURCE_GROUP
160+
```
161+
162+
## Related content
163+
164+
> [!div class="nextstepaction"]
165+
> [ Java metrics for Java apps in Azure Container Apps](./java-metrics.md)

articles/container-apps/java-metrics.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Once you select the Java development stack, the *Customize Java features for you
5454

5555
1. In the *Overview* section, under *Essentials*, find *Development stack* and select **manage**.
5656

57-
1. In the *Development stack* drop down, select **Java**.
57+
1. In the *Development stack* drop-down, select **Java**.
5858

5959
1. Select **Apply**.
6060

@@ -130,4 +130,5 @@ You can see Java metric names on Azure Monitor, but the data sets show as empty
130130
## Next steps
131131

132132
> [!div class="nextstepaction"]
133-
> [Monitor logs with Log Analytics](log-monitoring.md)
133+
- [Build a Java metrics dashboard with Azure Managed Grafana](java-metrics-with-grafana.md)
134+
- [Monitor logs with Log Analytics](log-monitoring.md)
192 KB
Loading
134 KB
Loading
248 KB
Loading
203 KB
Loading
218 KB
Loading
117 KB
Loading

0 commit comments

Comments
 (0)