{"id":62089,"date":"2021-07-30T08:00:55","date_gmt":"2021-07-30T16:00:55","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/devops\/?p=62089"},"modified":"2021-07-30T10:15:20","modified_gmt":"2021-07-30T18:15:20","slug":"monitoring-azure-by-using-grafana-dashboards","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/monitoring-azure-by-using-grafana-dashboards\/","title":{"rendered":"Monitoring Azure by using Grafana dashboards"},"content":{"rendered":"<p>By using <a href=\"https:\/\/docs.microsoft.com\/azure\/azure-monitor\/overview?WT.mc_id=devops-23282-petender\">Azure Monitor<\/a>, <a href=\"https:\/\/docs.microsoft.com\/azure\/azure-monitor\/logs\/log-analytics-overview?WT.mc_id=devops-23282-petender\">Azure Log Analytics<\/a> and <a href=\"https:\/\/docs.microsoft.com\/azure\/azure-monitor\/app\/app-insights-overview?WT.mc_id=devops-23282-petender\">Application Insights<\/a>, Azure cloud teams have access to a collection of end-to-end monitoring solutions, directly from the Azure Portal, allowing for Azure Services monitoring, as well as hybrid.<\/p>\n<p>Monitoring involves reading out a combination of: &#8211; <strong>metrics<\/strong>, for example CPU and Memory load on a Virtual Machine, number of HTTPS connections to an Azure App Service,&#8230;) &#8211; <strong>logs<\/strong>, for example log files from an Apache VM, Linux Syslogs, Cosmos DB logs on a Storage Account,&#8230;) &#8211; <strong>traces<\/strong>, which typically provides insights using a correlation as well as time series on both metrics and logs; for example, show the disk storage increase over the last 6 months; or identify the top 10 visitor countries to your e-commerce web application<\/p>\n<p>While the Azure Portal allows for creating custom dashboards based on a multitude of different graphs, pie charts, line charts and more &#8211; even custom Markdown formatted text can be added &#8211; customers are often relying on third party solutions for even more compelling diagrams and customized dashboards. One such tool is <strong>Grafana<\/strong>.<\/p>\n<p>This article takes you from the initial Grafana installation to how to integrate the aforementioned Azure monitoring services and build out powerful dashboards.<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li>An Azure Subscription (go <a href=\"https:\/\/azure.microsoft.com\/en-us\/free\/?WT.mc_id=devops-23282-petender\">here<\/a> to create a Free Azure Subscription)<\/li>\n<li>Some sample deployed resources to monitor (for example Virtual Machine, Storage, App Service, Database Service, Azure Kubernetes Service,&#8230;)<\/li>\n<\/ul>\n<h2>Installing Grafana<\/h2>\n<p>Grafana can be installed in several flavors, as a <strong>full application<\/strong> on a Windows Server or Linux Server, an application on MacOS or as a <strong>Docker Container<\/strong>. The benefit is you manage all configuration yourself. Click <a href=\"https:\/\/grafana.com\/grafana\/download?pg=graf-deployment-options&amp;plcmt=deploy-box-1?WT.mc_id=devops-23282-petender\">this URL<\/a> to find out more.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_1.png\" alt=\"Grafana Download \" \/><\/p>\n<p>One could also go for an <strong>Azure Marketplace VM image<\/strong>, which builds a fully-workable Grafana VM setup in just a few minutes.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_2.png\" alt=\"Grafana Azure MarketPlace Image \" \/><\/p>\n<p>A last option is <a href=\"https:\/\/grafana.com\/get\/?WT.mc_id=devops-23282-petender\"><strong>Grafana Cloud<\/strong><\/a> ,a cloud-SaaS platform, offering you immediate access to a complete Grafana setup, hosted in the cloud. You just need to provide a Google, GitHub or Microsoft Account (or create a specific Grafana local account) and done. This offers a 14-day free trial.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_3.png\" alt=\"Grafana Cloud\" \/><\/p>\n<p>For this article, I used the Grafana Cloud flavor, using a GitHub account.<\/p>\n<ol>\n<li>\n<p>Once authenticated, you need to <strong>Name your Stack<\/strong>, which refers to a unique URL for your Grafana environment.<\/p>\n<\/li>\n<li>\n<p>Next, your cloud service is getting deployed; which takes about a minute.<\/p>\n<\/li>\n<li>\n<p>Last, you are presented with the starting dashboard, from where you can select the different services Grafana integrates with.<\/p>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_6.png\" alt=\"Grafana Services\" \/><\/p>\n<ol>\n<li>From this screen, scroll down to the *Visualize existing data&#8221; section, and notice <strong>Azure Monitor<\/strong> <\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_7.png\" alt=\"Grafana Services\" \/><\/p>\n<h2>Connecting Grafana with Azure Monitor<\/h2>\n<ol>\n<li>Select <strong>Azure Monitor<\/strong> from the list of available integration services, and click the <strong>Next:Configure Service<\/strong> button<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_8.png\" alt=\"Grafana Azure Service\" \/><\/p>\n<ol>\n<li>\n<p>Next, go to <strong>Configuration \/ Data Sources and Select Azure Monitor<\/strong><\/p>\n<\/li>\n<li>\n<p>You are prompted for <strong>Authentication<\/strong> settings, which requires a <strong>Service Principal<\/strong>; <strong>READ<\/strong> permissions on Tenant or Subscription level should be enough (For more information on Service Principals, I can recommend these docs:<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/azure\/active-directory\/develop\/app-objects-and-service-principals?WT.mc_id=devops-23282-petender\">Service Principal<\/a> <\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/devops\/demystifying-service-principals-managed-identities\/?WT.mc_id=devops-23282-petender\">SP or Managed Identity<\/a><\/li>\n<\/ul>\n<ol>\n<li>I&#8217;m a big fan of <strong><a href=\"https:\/\/docs.microsoft.com\/en-us\/cli\/azure\/install-azure-cli-windows?tabs=azure-cli?WT.mc_id=devops-23282-petender\">Azure CLI<\/a><\/strong> to execute Azure admin tasks, so using this as an example on how to create the Service Principal in my subscription:<\/li>\n<\/ol>\n<p>From Azure CLI (Cloud Shell or local runtime), execute the following command:<\/p>\n<pre><code>az ad sp create-for-rbac --name GrafanaDemo --role \"Reader\"\n<\/code><\/pre>\n<p>This produces the necessary output on screen that you need to copy\/paste into the settings form on the Grafana side:<\/p>\n<pre><code>Creating 'Reader' role assignment under scope '\/subscriptions\/46801f45-d426-43b3-a094-0781444710a8'\nThe output includes credentials that you must protect. Be sure that you do not include these credentials in your code or check the credentials into your source control. For more information, see [Az AD SP CLI](https:\/\/aka.ms\/azadsp-cli?WT.mc_id=devops-23282-petender)\n'name' property in the output is deprecated and will be removed in the future. Use 'appId' instead.\n{\n  \"appId\": \"976fd8ae-XXXX-XXXX-XXXX-XXXXXXXXXXXX\",\n  \"displayName\": \"PDTGrafanademo\",\n  \"name\": \"976fd8ae-XXXX-XXXX-XXXX-XXXXXXXXXXXX\"\",\n  \"password\": \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\n  \"tenant\": \"72f988bf-XXXX-XXXX-XXXX-XXXXXXXXXXXX\"\n}\npeter@Azure:~$\npeter@Azure:~$\n<\/code><\/pre>\n<ol>\n<li>use the <strong>Load Subscriptions<\/strong> button to pull up your default subscription, as well as Azure Log Analytics Default Workspace. <\/li>\n<\/ol>\n<p>(if you don&#8217;t have a Log Analytics workspace yet, follow the guidelines in <a href=\"https:\/\/docs.microsoft.com\/azure\/azure-monitor\/logs\/quick-create-workspace?WT.mc_id=devops-23282-petender\">this document<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_9.png\" alt=\"Grafana Services\" \/><\/p>\n<h2>Customizing Dashboard views<\/h2>\n<p>From here, there is obviously a welth of options available, depending on the Azure Service and Resource Type, the corresponding metrics and the information you want to read out.<\/p>\n<p>I promised you the basic log parameters using metrics, logs and traces, so will guide you through each on how to use them. But feel free to select your own sample resources and go over the different dashboarding options.<\/p>\n<h2>Using Metrics<\/h2>\n<ol>\n<li>\n<p>From the Granafa Portal, select <strong>Dashboards \/ New Dashboards<\/strong><\/p>\n<\/li>\n<li>\n<p>Select <strong>Add an empty panel<\/strong><\/p>\n<\/li>\n<li>\n<p>A Sample Dashboard appears. <img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_10.png\" alt=\"Sample Dashboard\" \/><\/p>\n<\/li>\n<li>\n<p>From <strong>Data Source<\/strong> below the graph panel, select the <strong>Azure Monitor<\/strong> data source you defined earlier.<\/p>\n<\/li>\n<li>\n<p>From the <strong>Service<\/strong> listbox below, select <strong>Metrics<\/strong><\/p>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_11.png\" alt=\"Sample Dashboard\" \/><\/p>\n<ol>\n<li>This allows you to complete the different fields and select the Resource and Metric you want to read out. Below example reads the <strong>Percentage CPU<\/strong> for a sample <strong>WebVM<\/strong> Virtual Machine in my sample Resource Group <strong>SimplCWebApp<\/strong><\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_12.png\" alt=\"Percentage CPU for a VM\" \/><\/p>\n<ol>\n<li>Depending on the time frame you want to read out, you might want to alter the default <strong>last 6 hours<\/strong> parameter. I wanted to read out the information from the last 15 days, but only the first 8 days. This can be done by updating the <strong>From<\/strong> to <strong>now-15d<\/strong> and <strong>To<\/strong> to <strong>now-7d<\/strong> and click <strong>Apply Time Range<\/strong> <\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_13.png\" alt=\"Percentage CPU for a VM\" \/><\/p>\n<ol>\n<li>Resulting in the following chart view: <\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_14.png\" alt=\"Percentage CPU for a VM\" \/><\/p>\n<ol>\n<li>\n<p>From the <strong>right hand side panel<\/strong> you can customize more settings on what the chart should look like. I won&#8217;t describe many of the options, as they should be rather clear. But don&#8217;t hold back playing with the different options. For example <strong>Title<\/strong> and <strong>Legend Values<\/strong> are quite useful to add.<\/p>\n<\/li>\n<li>\n<p>To add more information on the same chart, <strong>click<\/strong> the <strong>Add query<\/strong> button, and make some new selections. In my example, I added the <strong>SQLVM<\/strong> as 2nd resource<\/p>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_15.png\" alt=\"Percentage CPU for a VM\" \/><\/p>\n<p>Resulting in the following updated chart:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_16.png\" alt=\"Percentage CPU for multiple VMs\" \/><\/p>\n<ol>\n<li><strong>Click<\/strong> the <strong>Save<\/strong> button in the upper right corner to save your changes, and store them as a full dashboard. <\/li>\n<\/ol>\n<h2>Importing pre-configured dashboards<\/h2>\n<p>The above example should get you going to <strong>build out custom dashboard views<\/strong> for about any Azure Resource type and metrics. However, for more complex workloads (like containers, Azure Kubernetes Service,&#8230;) why doing all the work from scratch yourself, when you can <strong>import<\/strong> preconfigured dashboards from <a href=\"https:\/\/grafana.com\/grafana\/dashboards?WT.mc_id=devops-23282-petender\"><strong>here<\/strong><\/a>?<\/p>\n<p>Since I have some container workloads and an AKS cluster up-and-running, let&#8217;s check out how this works:<\/p>\n<ol>\n<li>From the Grafana Portal, select <strong>Create \/ Import<\/strong><\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_18.png\" alt=\"Import\" \/><\/p>\n<ol>\n<li>\n<p>Enter the following URL in the &#8220;import from Grafana.com&#8221; link:<\/p>\n<p>https:\/\/grafana.com\/grafana\/dashboards\/12817<\/p>\n<\/li>\n<\/ol>\n<p>which refers at <em>AKS Monitor Containers<\/em><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_19.png\" alt=\"Import Link\" \/><\/p>\n<ol>\n<li>And confirming with <strong>Load<\/strong><\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_20.png\" alt=\"Import Link\" \/><\/p>\n<ol>\n<li>Confirming with <strong>Import<\/strong>; after a few seconds, your full sample dashboard is loaded:<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_21.png\" alt=\"Import Link\" \/><\/p>\n<ol>\n<li>Where for each section, several pre-configured dashboard panels are showing you multiple statistics of your AKS Cluster<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/07\/grafana_2021-07-11_22.png\" alt=\"Import Link\" \/><\/p>\n<h2>Summary<\/h2>\n<p>In this article, I wanted to introduce you to <strong>Grafana<\/strong>, an Open Source dashboarding tool, allowing for aggregating different sources like Azure Monitor, Kubernetes, AWS, Docker and several other, and building up powerful dashboards. If you are only using Azure resources, I would personally recommend drilling down on all the capabilities of Azure Monitor and Log Analytics for sure. However, if you have a <strong>more hybrid or multi-cloud scenario<\/strong>, Grafana will definitely augment the power of Azure Monitor out of its integration with a huge amount of other data connectors.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By using Azure Monitor, Azure Log Analytics and Application Insights, Azure cloud teams have access to a collection of end-to-end monitoring solutions, directly from the Azure Portal, allowing for Azure Services monitoring, as well as hybrid. Monitoring involves reading out a combination of: &#8211; metrics, for example CPU and Memory load on a Virtual Machine, [&hellip;]<\/p>\n","protected":false},"author":45107,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[224],"tags":[],"class_list":["post-62089","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure"],"acf":[],"blog_post_summary":"<p>By using Azure Monitor, Azure Log Analytics and Application Insights, Azure cloud teams have access to a collection of end-to-end monitoring solutions, directly from the Azure Portal, allowing for Azure Services monitoring, as well as hybrid. Monitoring involves reading out a combination of: &#8211; metrics, for example CPU and Memory load on a Virtual Machine, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/62089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/45107"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=62089"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/62089\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=62089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=62089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=62089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}