You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-monitor/essentials/query-azure-monitor-workspaces.md
+72-56Lines changed: 72 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,81 +10,53 @@ ms.reviewer: aul
10
10
11
11
# Query Prometheus metrics from an Azure Monitor Workspace using PromQL.
12
12
13
-
Azure Monitor managed service for Prometheus (preview), collects metrics from Azure Kubernetes Clusters and stores them in an Azure Monitor workspace. PromQL - Prometheus query language, is a functional query language that allows you to query and aggregate time series data. Use PromQL to query and aggregate metrics stored in a Azure Monitor workspace.
13
+
Azure Monitor managed service for Prometheus (preview), collects metrics from Azure Kubernetes Clusters and stores them in an Azure Monitor workspace. PromQL - Prometheus query language, is a functional query language that allows you to query and aggregate time series data. Use PromQL to query and aggregate metrics stored in an Azure Monitor workspace.
14
14
15
-
This article describes how to query an Azure Monitor workspace using PromQL via REST API.
16
-
For more information on ProQL, see [QUERYING PROMETHEUS](https://prometheus.io/docs/prometheus/latest/querying/basics/).
15
+
This article describes how to query an Azure Monitor workspace using PromQL via REST API.
16
+
For more information on PromQL, see [Querying prometheus](https://prometheus.io/docs/prometheus/latest/querying/basics/).
17
17
18
18
## Prerequisites
19
-
To query a n Azure montior workspace using PromQL you need the following:
19
+
To query an Azure monitor workspace using PromQL you need the following prerequisites:
20
20
+ An Azure Kubernetes Cluster or remote Kubernetes cluster.
21
21
+ Azure Monitor managed service for Prometheus (preview) scraping metrics from a Kubernetes cluster
22
-
+ An Azure Monitor Workspace where Prometheus metrics asr being stored.
22
+
+ An Azure Monitor Workspace where Prometheus metrics Azure Site Recovery being stored.
23
23
24
24
## Authentication
25
25
26
-
To query your Azure Monitor workspace, you must use authenticate using Azure Active Directory.
26
+
To query your Azure Monitor workspace, authenticate using Azure Active Directory.
27
27
The API supports Azure Active Directory authentication using Client credentials. Register a client app with Azure Active Directory and request a token.
28
28
29
-
1.[Register an app in Azure Active Directory](https://learn.microsoft.com/en-us/azure/azure-monitor/logs/api/register-app-for-token)
30
-
31
-
On the app's overview page, select API permissions.
32
-
33
-
Select Add a permission.
34
-
35
-
On the APIs my organization uses tab, search for Log Analytics and select Log Analytics API from the list.
36
-
37
29
To set up Azure Active Directory authentication, follow the steps below:
38
30
39
31
1. Register an app with Azure Active Directory.
40
32
1. Grant access for the app to your Azure Monitor workspace.
41
-
1. Configure your self-hosted Grafana with the app's credentials.
42
-
43
-
### Register an app with Azure Active Directory
44
-
45
-
1. To register an app, open the Active Directory Overview page in the Azure portal.
46
-
47
-
1. Select **Add** from the tool bar and **App registration** from the dropdown.
33
+
1. Request a token.
48
34
49
-
1. On the **Register an application page**, enter a Name for the application.
50
35
51
-
1. Select Register.
52
-
53
-
1. Note the** Application (client) ID** and **Directory(Tenant) ID**. They're used in the body of the authentication request.
1. On the app's overview page, select **Certificates and Secrets**.
57
-
58
-
1. In the Client secrets tab, select New client secret.
59
-
60
-
1. Enter a Description.
61
-
62
-
1. Select an expiry period from the dropdown and select Add.
63
-
64
-
>[!Note]
65
-
> Create a process to renew the secret and update your API REST calls before the secret expires. Once the secret expires you won't able to authenticate with this client ID and won't be able to query data from your Azure Monitor workspace using the API.
1. To register an app, follow the steps in [Register an App to request authorization tokens and work with APIs](../logs/api/register-app-for-token?tabs=portal)
68
39
69
-
1. Copy and save the client secret Value.
40
+
<<<<Is this required ?>>>>>
41
+
1. On the app's overview page, select API permissions.
70
42
71
-
>[!Note]
72
-
> Client secret values can only be viewed immediately after creation. Be sure to save the secret value before leaving the page.
43
+
1. Select Add a permission.
73
44
74
-
:::image type="content" source="./media/query-azure-monitor-workspaces/client-secret.png" lightbox="./media/query-azure-monitor-workspaces/client-secret.png" alt-text="A screenshot showing the client secret page with generated secret value.":::
45
+
1. On the APIs my organization uses tab, search for Log Analytics and select Log Analytics API from the list.
75
46
76
47
### Allow your app access to your workspace
77
48
Allow your app to query data from your Azure Monitor workspace.
78
49
79
50
1. Open your Azure Monitor workspace in the Azure portal.
80
51
81
-
1. On the Overview page, take note of your Query endpoint. The query endpoint is used when setting up your Grafana data source.
52
+
1. On the Overview page, take note of your Query endpoint foe use in your REST request.
82
53
83
-
1. Select Access control (IAM). A screenshot showing the Azure Monitor workspace overview page
1. Select **Add**, then **Add role assignment** from the Access Control (IAM) page.
86
58
87
-
1. On the Add role Assignment page, search for *Monitoring*.
59
+
1. On the **Add role Assignment page**, search for *Monitoring*.
88
60
89
61
1. Select **Monitoring Data Reader**, then select the Members tab.
90
62
@@ -94,16 +66,16 @@ Allow your app to query data from your Azure Monitor workspace.
94
66
95
67
1. Search for the app that you registered in the Register an app with Azure Active Directory section and select it.
96
68
97
-
1.Click**Select**.
69
+
1.Choose**Select**.
98
70
99
71
1. Select **Review + assign**.
100
72
101
73
:::image type="content" source="./media/query-azure-monitor-workspaces/select-members.png" lightbox="./media/query-azure-monitor-workspaces/select-members.png.png" alt-text="A screenshot showing the Add role assignment, select members page.":::
102
74
103
-
You've created your App registration and have assigned it access to query data from your Azure Monitor workspace.
75
+
You've created your App registration and have assigned it access to query data from your Azure Monitor workspace. You can now generate a token and use it in a query.
104
76
105
77
106
-
## Request a Token
78
+
###Request a Token
107
79
Send the following request in the command prompt or by using a client like Postman.
108
80
109
81
```shell
@@ -129,18 +101,62 @@ Sample response body:
129
101
}
130
102
```
131
103
132
-
## Endpoints
104
+
Save the access token from the response for use in the following HTTP requests.
105
+
106
+
## Query Endpoints
133
107
134
-
Two endpoints are supported for wuering Azure Monitor workspaces:
135
-
+ Azure monitor workspace query endpoint
108
+
Two endpoints are supported for querying Azure Monitor workspaces:
109
+
+ The Azure monitor workspace query endpoint, using POST
When using the management end point, request a token using `--data-urlencode 'resource= https://prometheus.monitor.azure.com'` instead of `prometheus.monitor.azure.com`
114
+
+ The Azure management endpoint using GET.
115
+
116
+
```
117
+
GET https://management.azure.com/subscriptions/<subscriptionId>/resourcegroups/<resourceGroupName>/providers/microsoft.monitor/accounts/<amwName>?api-version=2021-06-01-preview
118
+
```
119
+
120
+
When using the management end point, request a token using `--data-urlencode 'resource= https://management.azure.com'` instead of `prometheus.monitor.azure.com`
**name** is the only supported version of this API, which effectively means GET all metric names. Any other /api/v1/label/{name}/values aren't supported. <<<< More explanantion needed>>>>
136
+
137
+
For the full specification of OSS prom APIs, see [Prometheus HTTP API](https://prometheus.io/docs/prometheus/latest/querying/api/#http-api )
138
+
## API limitations
139
+
(differing from prom specification)
140
+
+ Scoped to metric
141
+
Any time series fetch queries (/series or /query or /query_range) must contain name label matcher that is, each query must be scoped to a metric. And there should be exactly one name label matcher in a query, not more than one.
142
+
<<< name label matcher ??>>>
143
+
144
+
+ Supported time range
145
+
+ /query_range API supports a time range of 32 days (end time minus start time).
146
+
<<<history depth ?>>>
147
+
148
+
+ /series API fetches data only for 12 hours time range. If endTime isn't provided, endTime = time.now().
149
+
150
+
+ range selectors (time range baked in query itself) supports 32d.
151
+
<<<more explanation needed - time range baked in query itself>>>
152
+
+ Ignore time range
153
+
Start time and end time provided with /labels and /label/name/values are ignored, and all retained data in MDM is queried.
154
+
<<<more explanation needed>>>
155
+
156
+
+ Experimental features
157
+
The experimental features such as exemplars, @ Modifier, or negative offsets aren't supported.
144
158
159
+
For more information on Prometheus metrics limits, see [Prometheus metrics](https://learn.microsoft.com/en-us/azure/azure-monitor/service-limits#prometheus-metrics)
145
160
146
-
Save the access token from the response for use in the following HTTP requests.
161
+
>[!NOTE]
162
+
> Some of the limits can be increased. Please contact [PromWebApi]([email protected]) to request an increase for these limits on your Azure Monitor workspace.
0 commit comments