Nov 19, 2020 · by Bogdan Veres

How to integrate Azure Monitor with Grafana

Performance monitoring in Azure  

A monitoring system can help find solutions to a wide range of problems, including slow response times, data loss, questionable user activity and file delivery caused by overloaded, crashed servers, and issues with network connections. This article covers how to set up a monitoring for Azure using Azure Monitoring API’s and Grafana.

Grafana is open source visualization and analytics software. It allows you to query, visualize, alert on, and explore your metrics no matter where they are stored. The tool displays temporary series data. It can obtain a graphic overview of the situation of a system or organization from a bunch of collected data.

If there is an usual spike in activity on the graph we can start to investigate it. Grafana has a built-in alerting engine that can be integrated with Slack or we can set up to send email notifications when an event is triggered. From Grafana we can detect time intervals when load is increasing, and with this information we can scale up the environment and we can reduce costs when traffic is lower. Using all this data we can understand the system behavior. Also, past data is used to identify patterns and we can avoid problems like an overloaded server that can quickly lead to cascading failures elsewhere in the system. 

Sign up for a new Azure account on: http://portal.azure.com/ 

Considering that we already have a web application deployed in Azure we will configure a permanent resource monitor.  

We will use Grafana to visualize data retrieved from Azure APIs. To enable access for Grafana to App Insights we will have to: 

  • Register Grafana with Azure AD and create a service principal 
  • Assign permissions to Grafana (read access is required for data source configuration in Grafana) 
  • Get tenant and app ID values for signing in (these are required for Grafana configuration) 
  • Create a new application secret 
  • Configure access policies on resources 

Register Grafana with Azure AD and create a service principal  

In Azure portal go to: 

  • Azure Active Directory -> App Registrations 
  • From App Registrations -> Select New Registration

  • Click on Register button 

 

Assign role to application 

To have access from Grafana to Azure App Insights we will have to grant permissions to the app that was previously created.   

From Azure portal, go to Subscriptions

Select the subscription that will be used for monitoring and from the left side menu select Access Control (IAM)

Then click on Add Role Assignment  

From the role assignment tab select the role and member (for this demo we will set the role to OWNER – you can find more details about user roles here: https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles

In the Select field, search for the previously created application. 

Click on the Save button. A message should be displayed on screen to inform that the role assignment was completed successfully. 

 

Generate client secret key 

  1. Go to Azure Active Directory 
  2. Select Certificates & secrets 
  3. Click on New client secret
  4. Save the key (this will be used in Grafana to setup data source)

How to get tenant and app ID values for signing in  

  1. Go to Azure Active Directory 
  2. Select App Registrations 
  3. From the list of owned applications select the app that was created previously

Getting data from web application  

First, configure an application insights resource. To do this follow the steps from this resource: https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-new-resource 

The next step will be to create a Log Analytics workspace per your resource group. To create the workspace follow the steps from: https://docs.microsoft.com/en-us/azure/azure-monitor/learn/quick-create-workspace 

Your resource group should now have the following services: 

Grafana data source configuration 

Application Insights must be configured in your web app to retrieve logs and metrics.  

For Azure Monitor we have the following keys: 

Provide the keys then click on Load subscriptions and Load workspaces and subscription field/default workspace should be populated with data. 

Click on Save and Test and you should see the following message displayed: 

From Grafana click on the “+” sign, then click on Import and use the following ID: 10175. Click on the Load button. On the next screen click on the Import button. The dashboard is loaded now in your Grafana instance. Select the correct data for Subscription, Resource Group. This dashboard is for SQL databases – in this case select for namespaces: Microsoft.Sql/servers/databases.

You can update the dashboard to monitor metrics like CPU, Memory, and the like.

Closing thoughts and tips

The setup can be used to monitor the resources and performance of applications under test. There are many ways to avoid performance-related issues, scaling up the compute resources is one of them but should be made carefully. Although it is often necessary to scale compute resources, doing so prematurely can generate unnecessary architectural complexity and financial costs. This is why a good monitoring system is required, finding issues earlier in the development process is better and cheaper. Improving performance throughout the software development lifecycle helps the team to create more reliable software. 

 

 

Sources:

https://pandorafms.com/blog/what-is-grafana/

https://grafana.com/docs/grafana/latest/getting-started/what-is-grafana/

https://www.mutiny.com/news/blogs/2016/6-reasons-why-IT-monitoring-and-reporting-is-important-to-your-business/

https://www.synopsys.com/blogs/software-security/cost-to-fix-bugs-during-each-sdlc-phase/

 

Bogdan Veres

Bogdan Veres

QA Community Lead
Sorin joined Softvision in 2010 and since then he gained expertise in UI & backend automation, performance testing and build automation. He is also interested in developing his leadership skills and sharing his knowledge, leading to his new role of QA Community Lead in 2017. In his spare time, Sorin is passionate about mountain biking, hardware and traveling.
Bogdan Veres

Latest posts by Bogdan Veres

Share This Article

Post A Comment