Skip to content

Commit 6e11543

Browse files
committed
for review
1 parent d75a7e9 commit 6e11543

File tree

3 files changed

+84
-52
lines changed

3 files changed

+84
-52
lines changed
91 KB
Loading

articles/azure-monitor/essentials/query-azure-monitor-workspaces.md

Lines changed: 84 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ This article describes how to query an Azure Monitor workspace using PromQL via
1616
For more information on PromQL, see [Querying prometheus](https://prometheus.io/docs/prometheus/latest/querying/basics/).
1717

1818
## 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:
2020
+ An Azure Kubernetes Cluster or remote Kubernetes cluster.
2121
+ 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.
2323

2424
## Authentication
2525

@@ -37,24 +37,17 @@ To set up Azure Active Directory authentication, follow the steps below:
3737

3838
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)
3939

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-
4740
### Allow your app access to your workspace
4841
Allow your app to query data from your Azure Monitor workspace.
4942

5043
1. Open your Azure Monitor workspace in the Azure portal.
5144

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.
5346

54-
1. Select Access control (IAM).
55-
:::image type="content" source="./media/query-azure-monitor-workspaces/workspace-overview.png" lightbox="./media/query-azure-monitor-workspaces/workspace-overview.png" alt-text="A screenshot showing the Azure Monitor workspace overview page":::
47+
1. Select Access control (IAM).
5648

5749
1. Select **Add**, then **Add role assignment** from the Access Control (IAM) page.
50+
:::image type="content" source="./media/query-azure-monitor-workspaces/access-control.png" lightbox="./media/query-azure-monitor-workspaces/access-control.png" alt-text="A screenshot showing the Azure Monitor workspace overview page":::
5851

5952
1. On the **Add role Assignment page**, search for *Monitoring*.
6053

@@ -103,23 +96,21 @@ Sample response body:
10396

10497
Save the access token from the response for use in the following HTTP requests.
10598

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
115100

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.":::
117103

118-
POST uses the Azure Monitor workspace query endpoint
104+
## Supported APIs
105+
The following queries are supported:
119106

120-
```http
121-
https://k8s-02-workspace-abcd.eastus.prometheus.monitor.azure.com/api/v1/query
107+
### Instant queries
108+
For more information, see [Instant queries](https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries)
122109

110+
Path: `/api/v1/query`
111+
Examples:
112+
```
113+
POST https://k8s-02-workspace-abcd.eastus.prometheus.monitor.azure.com/api/v1/query
123114
--header 'Authorization: Bearer <access token>'
124115
--header 'Content-Type: application/x-www-form-urlencoded'
125116
--data-urlencode 'query=sum(
@@ -128,47 +119,88 @@ https://k8s-02-workspace-abcd.eastus.prometheus.monitor.azure.com/api/v1/query
128119
group_left(workload, workload_type) namespace_workload_pod:kube_pod_owner:relabel{ workload_type="deployment"}) by (pod)'
129120
130121
```
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+
```
131134

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'
137+
--header 'Authorization: Bearer <access token>'
138+
--header 'Content-Type: application/x-www-form-urlencoded' \
139+
--data-urlencode 'query=up' \
140+
--data-urlencode 'start=2023-03-01T20:10:30.781Z' \
141+
--data-urlencode 'end=2023-03-20T20:10:30.781Z' \
142+
--data-urlencode 'step=6h'
143+
```
144+
### Series
145+
For more information, see [Series](https://prometheus.io/docs/prometheus/latest/querying/api/#finding-series-by-label-matchers)
133146

134-
Find your workspace's query endpoint on the overview page.
135-
:::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 endpoin on the Azure Monitor workspace overview page.":::
136-
## Supported APIs
137-
The following queries are supported:
147+
Path: `/api/v1/series`
148+
Examples:
149+
```
150+
POST 'https://k8s02-workspace-xy98.eastus.prometheus.monitor.azure.com/api/v1/series?api-version=2021-06-03-preview'
151+
--header 'Authorization: Bearer <access token>
152+
--header 'Content-Type: application/x-www-form-urlencoded'
153+
--data-urlencode 'match%5B%5D=container_network_receive_bytes_total'
154+
--data-urlencode 'match%5B%5D=kube_pod_info{pod="bestapp-123abc456d-4nmfm"}'
138155
139-
+ [Instant queries](https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries): /api/v1/query
156+
```
140157

141-
+ [Range queries](https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries): /api/v1/query_range
158+
```
159+
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"}'
160+
```
142161

143-
+ [Series](https://prometheus.io/docs/prometheus/latest/querying/api/#finding-series-by-label-matchers): /api/v1/series
162+
### Labels
144163

145-
+ [Labels](https://prometheus.io/docs/prometheus/latest/querying/api/#getting-label-names): /api/v1/labels
164+
For more information, see [Labels](https://prometheus.io/docs/prometheus/latest/querying/api/#getting-label-names)
165+
Path: `/api/v1/labels`
166+
Examples:
167+
```
168+
GET 'https://k8s02-workspace-xy98.eastus.prometheus.monitor.azure.com/api/v1/labels?api-version=2021-06-03-preview'
146169
147-
+ [Label values](https://prometheus.io/docs/prometheus/latest/querying/api/#querying-label-values): /api/v1/label/__name__/values.
170+
```
148171

149-
**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>>>>
172+
```
173+
POST
174+
'https://k8s02-workspace-xy98.eastus.prometheus.monitor.azure.com/api/v1/labels?api-version=2021-06-03-preview'
175+
```
150176

151-
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.`
157180

158-
+ Supported time range
159-
+ /query_range API supports a time range of 32 days (end time minus start time).
160-
<<<history depth ?>>>
161181

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.
163184
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-
<<<more explanation needed>>>
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+
```
169189

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.
170202
+ Experimental features
171-
The experimental features such as exemplars aren't supported.
203+
Experimental features such as exemplars aren't supported.
172204

173205
For more information on Prometheus metrics limits, see [Prometheus metrics](../../azure-monitor/service-limits.md#prometheus-metrics)
174206

0 commit comments

Comments
 (0)