Skip to content

Commit f2bb8a6

Browse files
Update Readme with Batch Query Example (Azure#26900)
### Packages impacted by this PR @azure/monitor-query ### Issues associated with this PR N/A ### Describe the problem that is addressed by this PR This PR is to update the Readme file with the example of batch metrics query. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? No special design considerations for this issue. This is just to update the Readme ### Are there test cases added in this PR? _(If not, why?)_ N/A ### Provide a list of related PRs _(if any)_ N/A ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [X] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary) --------- Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com>
1 parent be1a95f commit f2bb8a6

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

sdk/monitor/monitor-query/README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,20 @@ An authenticated client is required to query Logs or Metrics. To authenticate, t
4646

4747
```ts
4848
import { DefaultAzureCredential } from "@azure/identity";
49-
import { LogsQueryClient, MetricsQueryClient } from "@azure/monitor-query";
49+
import { LogsQueryClient, MetricsQueryClient, MetricsBatchQueryClient } from "@azure/monitor-query";
5050

5151
const credential = new DefaultAzureCredential();
5252

53-
const logsQueryClient = new LogsQueryClient(credential);
53+
const logsQueryClient: LogsQueryClient = new LogsQueryClient(credential);
54+
// or
55+
const metricsQueryClient: MetricsQueryClient = new MetricsQueryClient(credential);
5456
// or
55-
const metricsQueryClient = new MetricsQueryClient(credential);
57+
const batchEndPoint: string = "<YOUR_METRICS_ENDPOINT>"; //for example, https://eastus.metrics.monitor.azure.com/
58+
59+
const metricsBatchQueryClient: MetricsBatchQueryClient = new MetricsBatchQueryClient(
60+
batchEndPoint,
61+
credential
62+
);
5663
```
5764

5865
#### Configure clients for non-public Azure clouds
@@ -110,6 +117,7 @@ Each set of metric values is a time series with the following characteristics:
110117
- [Metrics query](#metrics-query)
111118
- [Handle metrics query response](#handle-metrics-query-response)
112119
- [Example of handling response](#example-of-handling-response)
120+
- [Batch metrics query](#batch-metrics-query)
113121

114122
### Logs query
115123

@@ -716,6 +724,32 @@ main().catch((err) => {
716724

717725
A full sample can be found [here](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/monitor/monitor-query/samples/v1/typescript/src/metricsQuery.ts).
718726

727+
### Batch metrics query
728+
729+
The following example executes multiple metrics queries in a single request using the `MetricsBatchQueryClient.queryBatch` method:
730+
731+
```ts
732+
let resourceIds: string[] = [
733+
"/subscriptions/0000000-0000-000-0000-000000/resourceGroups/test/providers/Microsoft.OperationalInsights/workspaces/test-logs",
734+
"/subscriptions/0000000-0000-000-0000-000000/resourceGroups/test/providers/Microsoft.OperationalInsights/workspaces/test-logs2",
735+
];
736+
let metricsNamespace: string = "<YOUR_METRICS_NAMESPACE>";
737+
let metricNames: string[] = ["requests", "count"];
738+
const batchEndPoint: string = "<YOUR_METRICS_ENDPOINT>"; //for example, https://eastus.metrics.monitor.azure.com/
739+
740+
const credential = new DefaultAzureCredential();
741+
const metricsBatchQueryClient: MetricsBatchQueryClient = new MetricsBatchQueryClient(
742+
batchEndPoint,
743+
credential
744+
);
745+
746+
const result: MetricResultsResponseValuesItem[] = await metricsBatchQueryClient.queryBatch(
747+
resourceIds,
748+
metricsNamespace,
749+
metricNames
750+
);
751+
```
752+
719753
## Troubleshooting
720754

721755
To diagnose various failure scenarios, see the [troubleshooting guide](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/monitor/monitor-query/TROUBLESHOOTING.md).

0 commit comments

Comments
 (0)