This commit is contained in:
azure-sdk 2024-03-27 01:27:04 +00:00
Родитель ab08d75241
Коммит 1c89954534
2 изменённых файлов: 101 добавлений и 46 удалений

Просмотреть файл

@ -1,12 +1,12 @@
---
title: Azure Monitor Query client library for Java
keywords: Azure, java, SDK, API, azure-monitor-query, monitor
ms.date: 02/21/2024
ms.date: 03/27/2024
ms.topic: reference
ms.devlang: java
ms.service: monitor
---
# Azure Monitor Query client library for Java - version 1.2.9
# Azure Monitor Query client library for Java - version 1.3.0
The Azure Monitor Query client library is used to execute read-only queries against [Azure Monitor][azure_monitor_overview]'s two data platforms:
@ -38,7 +38,7 @@ The Azure Monitor Query client library is used to execute read-only queries agai
#### Include the BOM file
Please include the azure-sdk-bom to your project to take dependency on the General Availability (GA) version of the library. In the following snippet, replace the {bom_version_to_target} placeholder with the version number.
To learn more about the BOM, see the [AZURE SDK BOM README](https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.2.9/sdk/boms/azure-sdk-bom/README.md).
To learn more about the BOM, see the [AZURE SDK BOM README](https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.3.0/sdk/boms/azure-sdk-bom/README.md).
```xml
<dependencyManagement>
@ -75,7 +75,7 @@ add the direct dependency to your project as follows.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-monitor-query</artifactId>
<version>1.2.9</version>
<version>1.3.0</version>
</dependency>
```
@ -96,7 +96,7 @@ To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.9.0</version>
<version>1.11.2</version>
</dependency>
```
[//]: # ({x-version-update-end})
@ -117,6 +117,13 @@ MetricsQueryClient metricsQueryClient = new MetricsQueryClientBuilder()
.buildClient();
```
```java readme-sample-createMetricsClient
MetricsClient metricsClient = new MetricsClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
```
#### Asynchronous clients
```java readme-sample-createLogsQueryAsyncClient
@ -131,6 +138,13 @@ MetricsQueryAsyncClient metricsQueryAsyncClient = new MetricsQueryClientBuilder(
.buildAsyncClient();
```
```java readme-sample-createMetricsAsyncClient
MetricsAsyncClient metricsAsyncClient = new MetricsClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildAsyncClient();
```
#### Configure clients for non-public Azure clouds
By default, `LogQueryClient` and `MetricQueryClient` are configured to connect to the public Azure Cloud. These can be configured to connect to non-public Azure clouds by setting the correct `endpoint` in the client builders: For example:
@ -191,7 +205,8 @@ Each set of metric values is a time series with the following characteristics:
- [Handle metrics query response](#handle-metrics-query-response)
- [Get average and count metrics](#get-average-and-count-metrics)
- [Create a metrics client for non-public Azure clouds](#configure-clients-for-non-public-azure-clouds)
- [Metrics query resources](#metrics-query-resources)
- [Handle metrics query resources response](#handle-metrics-query-resources-response)
### Logs query
```java readme-sample-logsquery
@ -438,6 +453,10 @@ raw JSON response. For example:
}
```
#### Overcome Log Analytics query size limitations
If your query exceeds the [service limits][service_limits], see the large log query documentation to learn how to overcome them.
### Metrics query
A resource ID, as denoted by the `{resource-id}` placeholder in the sample below, is required to query metrics. To find the resource ID:
@ -519,9 +538,44 @@ for (MetricResult metric : metricsQueryResult.getMetrics()) {
}
```
### Metrics query resources
#### Handle metrics query resources response
```java readme-sample-metricsquerymultipleresources
MetricsClient metricsClient = new MetricsClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint("{endpoint}")
.buildClient();
MetricsQueryResourcesResult metricsQueryResourcesResult = metricsClient.queryResources(
Arrays.asList("{resourceId1}", "{resourceId2}"),
Arrays.asList("{metric1}", "{metric2}"),
"{metricNamespace}");
for (MetricsQueryResult metricsQueryResult : metricsQueryResourcesResult.getMetricsQueryResults()) {
// Each MetricsQueryResult corresponds to one of the resourceIds in the batch request.
List<MetricResult> metrics = metricsQueryResult.getMetrics();
metrics.forEach(metric -> {
System.out.println(metric.getMetricName());
System.out.println(metric.getId());
System.out.println(metric.getResourceType());
System.out.println(metric.getUnit());
System.out.println(metric.getTimeSeries().size());
System.out.println(metric.getTimeSeries().get(0).getValues().size());
metric.getTimeSeries()
.stream()
.flatMap(ts -> ts.getValues().stream())
.forEach(mv -> System.out.println(mv.getTimeStamp().toString()
+ "; Count = " + mv.getCount()
+ "; Average = " + mv.getAverage()));
});
}
```
## Troubleshooting
See our [troubleshooting guide](https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.2.9/sdk/monitor/azure-monitor-query/TROUBLESHOOTING.md)
See our [troubleshooting guide](https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.3.0/sdk/monitor/azure-monitor-query/TROUBLESHOOTING.md)
for details on how to diagnose various failure scenarios.
## Next steps
@ -542,21 +596,22 @@ comments.
<!-- LINKS -->
[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.2.9/sdk/identity/azure-identity/README.md
[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.3.0/sdk/identity/azure-identity/README.md
[azure_monitor_create_using_portal]: https://learn.microsoft.com/azure/azure-monitor/logs/quick-create-workspace
[azure_monitor_overview]: https://learn.microsoft.com/azure/azure-monitor/overview
[azure_subscription]: https://azure.microsoft.com/free/java
[changelog]: https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.2.9/sdk/monitor/azure-monitor-query/CHANGELOG.md
[changelog]: https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.3.0/sdk/monitor/azure-monitor-query/CHANGELOG.md
[custom_subdomain]: https://learn.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#create-a-resource-with-a-custom-subdomain
[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.2.9/sdk/identity/azure-identity/README.md#defaultazurecredential
[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.3.0/sdk/identity/azure-identity/README.md#defaultazurecredential
[jdk_link]: https://learn.microsoft.com/java/azure/jdk/?view=azure-java-stable
[kusto_query_language]: https://learn.microsoft.com/azure/data-explorer/kusto/query/
[log_levels]: https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.2.9/sdk/core/azure-core/src/main/java/com/azure/core/util/logging/ClientLogger.java
[log_levels]: https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.3.0/sdk/core/azure-core/src/main/java/com/azure/core/util/logging/ClientLogger.java
[msdocs_apiref]: https://learn.microsoft.com/java/api/com.azure.monitor.query?view=azure-java-stable
[package]: https://search.maven.org/artifact/com.azure/azure-monitor-query
[samples]: https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.2.9/sdk/monitor/azure-monitor-query/src/samples/java/README.md
[source]: https://github.com/Azure/azure-sdk-for-java/tree/azure-monitor-query_1.2.9/sdk/monitor/azure-monitor-query/src
[package]: https://central.sonatype.com/artifact/com.azure/azure-monitor-query
[samples]: https://github.com/Azure/azure-sdk-for-java/blob/azure-monitor-query_1.3.0/sdk/monitor/azure-monitor-query/src/samples/java/README.md
[source]: https://github.com/Azure/azure-sdk-for-java/tree/azure-monitor-query_1.3.0/sdk/monitor/azure-monitor-query/src
[performance_tuning]: https://github.com/Azure/azure-sdk-for-java/wiki/Performance-Tuning
[service_limits]: https://learn.microsoft.com/azure/azure-monitor/service-limits#log-queries-and-language
[cla]: https://cla.microsoft.com
[coc]: https://opensource.microsoft.com/codeofconduct/

Просмотреть файл

@ -1,6 +1,6 @@
{
"Name": "azure-monitor-query",
"Version": "1.2.9",
"Version": "1.3.0",
"DevVersion": null,
"DirectoryPath": "sdk/monitor/azure-monitor-query",
"ServiceDirectory": "monitor",
@ -10,5 +10,5 @@
"SdkType": "client",
"IsNewSdk": true,
"ArtifactName": "azure-monitor-query",
"ReleaseStatus": "2024-02-20"
"ReleaseStatus": "2024-03-26"
}