* AzureMonitor: docs for multiple subscriptions
Also, links to images in Grafana.org instead of the images
in the plugin GitHub repo.
* Update docs/sources/features/datasources/azuremonitor.md
Co-Authored-By: Marcus Efraimsson <marcus.efraimsson@gmail.com>
* Update docs/sources/features/datasources/azuremonitor.md
Co-Authored-By: Marcus Efraimsson <marcus.efraimsson@gmail.com>
* docs: fix auto format errors
VS code automatically escapes the dollar sign.
@ -31,34 +31,37 @@ The datasource can access metrics from four different services. You can configur
- [Guide to setting up an Azure Active Directory Application for Azure Log Analytics.](https://dev.loganalytics.io/documentation/Authorization/AAD-Setup)
- [Quickstart Guide for Application Insights.](https://dev.applicationinsights.io/quickstart/)
1. Accessed from the Grafana main menu, newly installed data sources can be added immediately within the Data Sources section. Next, click the "Add data source" button in the upper right. The data source will be available for selection in the Type select box.
1. Accessed from the Grafana main menu, newly installed data sources can be added immediately within the Data Sources section. Next, click the "Add data source" button in the upper right. The Azure Monitor data source will be available for selection in the Cloud section in the list of data sources.
2. Select Azure Monitor from the Type dropdown:<br/>
3. In the name field, fill in a name for the data source. It can be anything. Some suggestions are Azure Monitor or App Insights.
2. In the name field, Grafana will automatically fill in a name for the data source - `Azure Monitor` or something like `Azure Monitor - 3`. If you are going to configure multiple data sources then change the name to something more informative.
4. If you are using Azure Monitor, then you need 4 pieces of information from the Azure portal (see link above for detailed instructions):
6. If you are also using the Azure Log Analytics service, then you need to specify these two config values (or you can reuse the Client Id and Secret from the previous step).
- Client Id (Azure Active Directory -> App Registrations -> Choose your app -> Application ID)
- Client Secret ( Azure Active Directory -> App Registrations -> Choose your app -> Keys -> Create a key -> Use client secret)
4. Paste these four items into the fields in the Azure Monitor API Details section:
7. If you are are using Application Insights, then you need two pieces of information from the Azure Portal (see link above for detailed instructions):
- Application ID
- API Key
- The Subscription Id can be changed per query. Save the datasource and refresh the page to see the list of subscriptions available for the specified Client Id.
8. Paste these two items into the appropriate fields in the Application Insights API Details section:<br/>

5. If you are also using the Azure Log Analytics service, then you need to specify these two config values (or you can reuse the Client Id and Secret from the previous step).
9. Test that the configuration details are correct by clicking on the "Save & Test" button:<br/>

- Client Id (Azure Active Directory -> App Registrations -> Choose your app -> Application ID)
- Client Secret (Azure Active Directory -> App Registrations -> Choose your app -> Keys -> Create a key -> Use client secret)
6. If you are using Application Insights, then you need two pieces of information from the Azure Portal (see link above for detailed instructions):
- Application ID
- API Key
7. Paste these two items into the appropriate fields in the Application Insights API Details section:
8. Test that the configuration details are correct by clicking on the "Save & Test" button:
{{<docs-imageboximg="/img/docs/v62/config_3_save_and_test.png"class="docs-image--no-shadow"caption="Save and Test">}}
Alternatively on step 4 if creating a new Azure Active Directory App, use the [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/?view=azure-cli-latest):
@ -68,17 +71,25 @@ az ad sp create-for-rbac -n "http://localhost:3000"
## Choose a Service
In the query editor for a panel, after choosing your Azure Monitor datasource, the first option is to choose a service. There are three options here: Azure Monitor, Application Insights and Azure Log Analytics. The query editor will change depending on which one you pick. Azure Monitor is the default.
In the query editor for a panel, after choosing your Azure Monitor datasource, the first option is to choose a service. There are three options here:
- `Azure Monitor`
- `Application Insights`
- `Azure Log Analytics`
The query editor will change depending on which one you pick. Azure Monitor is the default.
## Querying the Azure Monitor Service
The Azure Monitor service provides metrics for all the Azure services that you have running. It helps you understand how your applications on Azure are performing and to proactively find issues affecting your applications.
If your Azure Monitor credentials give you access to multiple subscriptions then choose the appropriate subscription first.
Examples of metrics that you can get from the service are:
- Microsoft.Compute/virtualMachines - Percentage CPU
- Microsoft.Network/networkInterfaces - Bytes sent
- Microsoft.Storage/storageAccounts - Used Capacity
@ -112,12 +123,17 @@ Note that the Azure Monitor service does not support multiple values yet. If you
The Azure Monitor Datasource Plugin provides the following queries you can specify in the `Query` field in the Variable edit view. They allow you to fill a variable's options list.
| _Subscriptions()_ | Returns a list of subscriptions. |
| _ResourceGroups()_ | Returns a list of resource groups. |
| _ResourceGroups(12345678-aaaa-bbbb-cccc-123456789aaa)_ | Returns a list of resource groups for a specified subscription. |
| _Namespaces(aResourceGroup)_ | Returns a list of namespaces for the specified resource group. |
| _Namespaces(12345678-aaaa-bbbb-cccc-123456789aaa, aResourceGroup)_ | Returns a list of namespaces for the specified resource group and subscription. |
| _ResourceNames(aResourceGroup, aNamespace)_ | Returns a list of resource names. |
| _ResourceNames(12345678-aaaa-bbbb-cccc-123456789aaaaResourceGroup, aNamespace)_ | Returns a list of resource names for a specified subscription. |
| _MetricNames(aResourceGroup, aNamespace, aResourceName)_ | Returns a list of metric names. |
| _MetricNames(12345678-aaaa-bbbb-cccc-123456789aaaaResourceGroup, aNamespace, aResourceName)_ | Returns a list of metric names for a specified subscription. |
`datetimeColumn ≤ datetime(2018-06-05T20:09:58.907Z)` where the from and to datetimes are from the Grafana time picker.
- `$__escapeMulti($myVar)` - is to be used with multi-value template variables that contains illegal characters. If $myVar has the value `'\\grafana-vm\Network(eth0)\Total','\\hello!'`, it expands to: `@'\\grafana-vm\Network(eth0)\Total', @'\\hello!'`. If using single value variables there no need for this macro, simply escape the variable inline instead - `@'\$myVar'`
- `$__escapeMulti($myVar)` - is to be used with multi-value template variables that contain illegal characters. If `$myVar` has the following two valuesas a string`'\\grafana-vm\Network(eth0)\Total','\\hello!'`, then it expands to: `@'\\grafana-vm\Network(eth0)\Total', @'\\hello!'`. If using single value variables there is no need for this macro, simply escape the variable inline instead - `@'\$myVar'`.
- `$__contains(colName, $myVar)` - is to be used with multi-value template variables. If $myVar has the value `'value1','value2'`, it expands to: `colName in ('value1','value2')`.
- `$__contains(colName, $myVar)` - is to be used with multi-value template variables. If `$myVar` has the value `'value1','value2'`, it expands to: `colName in ('value1','value2')`.
If using the `All` option, then check the `Include All Option` checkbox and in the `Custom all value` field type in the following value: `all`. If $myVar has value `all` then the macro will instead expand to `1 == 1`. For template variables with a lot of options, this will increase the query performance by not building a large where..in clause.
If using the `All` option, then check the `Include All Option` checkbox and in the `Custom all value` field type in the following value: `all`. If `$myVar` has value `all` then the macro will instead expand to `1 == 1`. For template variables with a lot of options, this will increase the query performance by not building a large where..in clause.