| title | Tutorial: Build a Java metrics dashboard with Azure Managed Grafana |
|---|---|
| description | Learn to build a Java metrics dashboard with Azure Managed Grafana. |
| services | container-apps |
| author | craigshoemaker |
| ms.service | azure-container-apps |
| ms.custom | devx-track-extended-java |
| ms.topic | tutorial |
| ms.date | 03/25/2026 |
| ms.author | cshoe |
In this tutorial, you learn how to set up a metrics dashboard using Azure Managed Grafana to monitor Java applications running in Azure Container Apps.
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.
In this tutorial, you:
[!div class="checklist"]
- Create an Azure Managed Grafana instance.
- Create a Java metrics dashboard in Grafana.
- Visualize Java metrics for Azure Container Apps with Grafana.
- An Azure account with an active subscription. If you don't already have one, you can can create one for free.
- Azure CLI.
- A Java application deployed in Azure Container Apps.
Use the following steps to define environment variables and ensure your Azure Managed Grafana extension is up to date.
-
Create variables to support your Grafana configuration.
export LOCATION=eastus export SUBSCRIPTION_ID={subscription-id} export RESOURCE_GROUP=grafana-resource-group export GRAFANA_INSTANCE_NAME=grafana-name
Variable Description LOCATIONThe Azure region location where you create your Azure Managed Grafana instance. SUBSCRIPTION_IDThe subscription ID, which you use to create your Azure Container Apps and Azure Managed Grafana instance. RESOURCE_GROUPThe Azure resource group name for your Azure Managed Grafana instance. GRAFANA_INSTANCE_NAMEThe instance name for your Azure Managed Grafana instance. -
Sign in to Azure with the Azure CLI.
az login -
Create a resource group.
az group create --name $RESOURCE_GROUP --location $LOCATION -
Use the following command to ensure that you have the latest version of the Azure CLI extensions for Azure Managed Grafana.
az extension add --name amg --upgrade
First, create an Azure Managed Grafana instance, and grant necessary role assignments.
-
Create an Azure Managed Grafana instance.
az grafana create \ --name $GRAFANA_INSTANCE_NAME \ --resource-group $RESOURCE_GROUP \ --location $LOCATION -
To read metrics from Azure Monitor, you need to grant the Azure Managed Grafana instance a Monitoring Reader role. To find out more, see authentication and permissions for Azure Managed Grafana.
GRAFA_IDDENTITY=$(az grafana show --name $GRAFANA_INSTANCE_NAME --resource-group $RESOURCE_GROUP --query "identity.principalId" --output tsv) az role assignment create --assignee $GRAFA_IDDENTITY --role "Monitoring Reader" --scope /subscriptions/$SUBSCRIPTION_ID
Important
To add a new dashboard in Grafana, you need to have Grafana Admin or Grafana Editorrole, see Azure Managed Grafana roles.
-
Assign the
Grafana Adminrole to your account on the Azure Managed Grafana resource.Get the resource ID for your Azure Managed Grafana instance.
GRAFANA_RESOURCE_ID=$(az grafana show --resource-group $RESOURCE_GROUP --name $GRAFANA_INSTANCE_NAME --query id --output tsv)Before running this command, replace the
<USER_OR_SERVICE_PRINCIPAL_ID>placeholder with your user or service principal ID.az role assignment create \ --assignee <USER_OR_SERVICE_PRINCIPAL_ID> \ --role "Grafana Admin" \ --scope $GRAFANA_RESOURCE_ID -
Download the sample Java metric dashboard for Azure Container Apps json file.
-
Get the endpoint of the Azure Managed Grafana resource.
az grafana show --resource-group $RESOURCE_GROUP \ --name $GRAFANA_INSTANCE_NAME \ --query "properties.endpoint" \ --output tsvThis command returns the URL you can use to access the Azure Managed Grafana dashboard. Open your browser with the URL and sign in.
-
Go to
Dashboard>New->Importand upload the sample dashboard JSON file that you downloaded in the previous step. Choose the default built-inAzure Monitordata source, then select theImportbutton.:::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":::
-
Input your resource information in the filters for your Azure Container Apps. Now you can view all the supported Java Virtual Machine (JVM) metrics in Azure Container Apps within the dashboard. The sample dashboard provides live metric data, including
- Container App Overview
- JVM Memory Usage
- JVM Memory Buffer
- JVM garbage collection (GC)
- A detailed JVM Memory Usage Analysis
:::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":::
:::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":::
:::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":::
:::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":::
:::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":::
You can use this dashboard as a starting point to create your own customized metric visualizations and monitoring solution.
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.
az group delete --resource-group $RESOURCE_GROUP
[!div class="nextstepaction"] Java metrics for Java apps in Azure Container Apps