Skip to content

Commit 12fbc88

Browse files
committed
draft1
1 parent 6350670 commit 12fbc88

File tree

1 file changed

+72
-56
lines changed

1 file changed

+72
-56
lines changed

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

Lines changed: 72 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,81 +10,53 @@ ms.reviewer: aul
1010

1111
# Query Prometheus metrics from an Azure Monitor Workspace using PromQL.
1212

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

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/).
1717

1818
## 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:
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 asr being stored.
22+
+ An Azure Monitor Workspace where Prometheus metrics Azure Site Recovery being stored.
2323

2424
## Authentication
2525

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.
2727
The API supports Azure Active Directory authentication using Client credentials. Register a client app with Azure Active Directory and request a token.
2828

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-
3729
To set up Azure Active Directory authentication, follow the steps below:
3830

3931
1. Register an app with Azure Active Directory.
4032
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.
4834

49-
1. On the **Register an application page**, enter a Name for the application.
5035

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.
54-
:::image type="content" source="./media/query-azure-monitor-workspaces/app-registration-overview.png" lightbox="./media/query-azure-monitor-workspaces/app-registration-overview.png" alt-text="A screen shot showing an app registration overview page.":::
55-
56-
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.
36+
### Register an app with Azure Active Directory
6637

67-
:::image type="content" source="./media/query-azure-monitor-workspaces/add-a-client-secret.png" lightbox="./media/query-azure-monitor-workspaces/add-a-client-secret.png" alt-text="A screenshot showing the Add client secret page.":::
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?tabs=portal)
6839

69-
1. Copy and save the client secret Value.
40+
<<<<Is this required ?>>>>>
41+
1. On the app's overview page, select API permissions.
7042

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

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

7647
### Allow your app access to your workspace
7748
Allow your app to query data from your Azure Monitor workspace.
7849

7950
1. Open your Azure Monitor workspace in the Azure portal.
8051

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

83-
1. Select Access control (IAM). A screenshot showing the Azure Monitor workspace overview page
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":::
8456

8557
1. Select **Add**, then **Add role assignment** from the Access Control (IAM) page.
8658

87-
1. On the Add role Assignment page, search for *Monitoring*.
59+
1. On the **Add role Assignment page**, search for *Monitoring*.
8860

8961
1. Select **Monitoring Data Reader**, then select the Members tab.
9062

@@ -94,16 +66,16 @@ Allow your app to query data from your Azure Monitor workspace.
9466

9567
1. Search for the app that you registered in the Register an app with Azure Active Directory section and select it.
9668

97-
1. Click **Select**.
69+
1. Choose **Select**.
9870

9971
1. Select **Review + assign**.
10072

10173
:::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.":::
10274

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

10577

106-
## Request a Token
78+
### Request a Token
10779
Send the following request in the command prompt or by using a client like Postman.
10880

10981
```shell
@@ -129,18 +101,62 @@ Sample response body:
129101
}
130102
```
131103

132-
## Endpoints
104+
Save the access token from the response for use in the following HTTP requests.
105+
106+
## Query Endpoints
133107

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
136110
For example:
137111
POST: Query endpoint from the over view page
138112
https://k8s02-workspace-abcd.eastus.prometheus.monitor.azure.com/api/v1/query
139113

140-
+ https://management.azure.com resource endpoint
141-
For example:
142-
GET: https://management.azure.com/subscriptions/<subscriptionId>/resourcegroups/<resourceGroupName>/providers/microsoft.monitor/accounts/<amwName>?api-version=2021-06-01-preview
143-
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`
121+
122+
## Supported APIs
123+
The following queries are supported:
124+
125+
+ [Instant queries](https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries): /api/v1/query
126+
127+
+ [Range queries](https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries): /api/v1/query_range
128+
129+
+ [Series](https://prometheus.io/docs/prometheus/latest/querying/api/#finding-series-by-label-matchers): /api/v1/series
130+
131+
+ [Labels](https://prometheus.io/docs/prometheus/latest/querying/api/#getting-label-names): /api/v1/labels
132+
133+
+ [Label values](https://prometheus.io/docs/prometheus/latest/querying/api/#querying-label-values): /api/v1/label/__name__/values.
134+
135+
**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.
144158
159+
For more information on Prometheus metrics limits, see [Prometheus metrics](https://learn.microsoft.com/en-us/azure/azure-monitor/service-limits#prometheus-metrics)
145160
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

Comments
 (0)