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
+84-52Lines changed: 84 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,10 +16,10 @@ This article describes how to query an Azure Monitor workspace using PromQL via
16
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 an Azure monitor workspace using PromQL you need the following prerequisites:
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 Azure Site Recovery being stored.
22
+
+ An Azure Monitor Workspace where Prometheus metrics are being stored.
23
23
24
24
## Authentication
25
25
@@ -37,24 +37,17 @@ To set up Azure Active Directory authentication, follow the steps below:
37
37
38
38
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.md?tabs=portal)
39
39
40
-
<<<<Is this required ?>>>>>
41
-
1. On the app's overview page, select API permissions.
42
-
43
-
1. Select Add a permission.
44
-
45
-
1. On the APIs my organization uses tab, search for Log Analytics and select Log Analytics API from the list.
46
-
47
40
### Allow your app access to your workspace
48
41
Allow your app to query data from your Azure Monitor workspace.
49
42
50
43
1. Open your Azure Monitor workspace in the Azure portal.
51
44
52
-
1. On the Overview page, take note of your Query endpoint foe use in your REST request.
45
+
1. On the Overview page, take note of your Query endpoint for use in your REST request.
1. On the **Add role Assignment page**, search for *Monitoring*.
60
53
@@ -103,23 +96,21 @@ Sample response body:
103
96
104
97
Save the access token from the response for use in the following HTTP requests.
105
98
106
-
## Query Endpoints
107
-
108
-
### GET/query
109
-
110
-
```
111
-
GET https://management.azure.com/subscriptions/<subscriptionId>/resourcegroups/<resourceGroupName>/providers/microsoft.monitor/accounts/<workspace name>/api/v1/label/__name__/values?api-version=2021-06-01-preview
112
-
--header 'Authorization: Bearer <access token>'
113
-
```
114
-
When using the management end point, request a token using `--data-urlencode 'resource= https://management.azure.com'`
99
+
## Query Endpoint
115
100
116
-
### POST / query
101
+
Find your workspace's query endpoint on the overview page.
102
+
:::image type="content" source="./media/query-azure-monitor-workspaces/find-query-endpoint.png" lightbox="./media/query-azure-monitor-workspaces/find-query-endpoint.png" alt-text="A screenshot sowing the query endpoint on the Azure Monitor workspace overview page.":::
117
103
118
-
POST uses the Azure Monitor workspace query endpoint
group_left(workload, workload_type) namespace_workload_pod:kube_pod_owner:relabel{ workload_type="deployment"}) by (pod)'
129
120
130
121
```
122
+
```
123
+
GET https://k8s02-workspace-xy98.eastus.prometheus.monitor.azure.com/api/v1/query?api-version=2021-06-03-preview&query=container_memory_working_set_bytes'
124
+
--header 'Authorization: Bearer <access token>'
125
+
```
126
+
### Range queries
127
+
For more information, see [Range queries](https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries)
128
+
Path: `/api/v1/query_range`
129
+
Examples:
130
+
```
131
+
GET 'https://k8s02-workspace-xy98.eastus.prometheus.monitor.azure.com/api/v1/query_range?api-version=2021-06-03-preview&query=container_memory_working_set_bytes&start=2023-03-01T20%3A10%3A30.781Z&end=2023-03-20T20%3A11%3A00.781Z&step=6h' \
132
+
--header 'Authorization: Bearer <access token>
133
+
```
131
134
132
-
When using the Azure Monitor workspace query endpoint, request a token using `--data-urlencode 'resource= https://prometheus.monitor.azure.com'`
135
+
```
136
+
POST 'https://k8s02-workspace-xy98.eastus.prometheus.monitor.azure.com/api/v1/query_range?api-version=2021-06-03-preview'
GET 'https://k8s02-workspace-xy98.eastus.prometheus.monitor.azure.com/api/v1/series?api-version=2021-06-03-preview&match[]=container_network_receive_bytes_total&match[]=kube_pod_info{pod="bestapp-123abc456d-4nmfm"}'
**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>>>>
For the full specification of OSS prom APIs, see [Prometheus HTTP API](https://prometheus.io/docs/prometheus/latest/querying/api/#http-api)
152
-
## API limitations
153
-
(differing from prom specification)
154
-
+ Scoped to metric
155
-
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.
156
-
<<< name label matcher ??>>>
177
+
### Label values
178
+
For more information, see [Label values](https://prometheus.io/docs/prometheus/latest/querying/api/#query.ing-label-values)
179
+
Path: `/api/v1/label/\_\_name\_\_/values.`
157
180
158
-
+ Supported time range
159
-
+ /query_range API supports a time range of 32 days (end time minus start time).
160
-
<<<history depth ?>>>
161
181
162
-
+ /series API fetches data only for 12 hours time range. If endTime isn't provided, endTime = time.now().
182
+
> [!NOTE]
183
+
> `__name__` is the only supported version of this API and returns all metric names. No other /api/v1/label/<label_name>/values are supported.
163
184
164
-
+ range selectors (time range baked in query itself) supports 32d.
165
-
<<<more explanation needed - time range baked in query itself>>>
166
-
+ Ignore time range
167
-
Start time and end time provided with /labels and /label/name/values are ignored, and all retained data in MDM is queried.
168
-
<<<moreexplanationneeded>>>
185
+
Example:
186
+
```
187
+
GET 'https://k8s02-workspace-xy98.eastus.prometheus.monitor.azure.com/api/v1/label/__name__/values?api-version=2021-06-03-preview'
188
+
```
169
189
190
+
For the full specification of OSS prom APIs, see [Prometheus HTTP API](https://prometheus.io/docs/prometheus/latest/querying/api/#http-api)
191
+
192
+
## API limitations
193
+
(differing from prom specification)
194
+
+ Query must be scoped to metric
195
+
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. There can only be one name label matcher in a query.
196
+
+ Supported time range
197
+
+ /query_range API supports a time range of 32 days. This is the maximum time range allowed including range selectors specified in the query itself.
198
+
For example, the query `rate(http_requests_total[5m]` for last 24 hours would actually mean data is being queried for 25 hours. A 24 hours range + 1 hour specified in query itself.
199
+
+ /series API fetches data for a maximum 12-hour time range. If `endTime` isn't provided, endTime = time.now(). If yhr time rage is greater than 12 hours, the `startTime` is set to `endTime – 12h`
200
+
+ Ignored time range
201
+
Start time and end time provided with /labels and /label/name/values are ignored, and all retained data in the Azure Monitor Workspace is queried.
170
202
+ Experimental features
171
-
The experimental features such as exemplars aren't supported.
203
+
Experimental features such as exemplars aren't supported.
172
204
173
205
For more information on Prometheus metrics limits, see [Prometheus metrics](../../azure-monitor/service-limits.md#prometheus-metrics)
0 commit comments