azure-docs-sdk-java/docs-ref-autogen/com.azure.monitor.query.yml

24 строки
6.8 KiB
YAML

### YamlMime:JavaPackage
uid: "com.azure.monitor.query"
fullName: "com.azure.monitor.query"
name: "com.azure.monitor.query"
summary: "Azure Monitor Query service is a powerful tool that allows you to query and analyze log data from various sources in Azure."
classes:
- "com.azure.monitor.query.LogsQueryAsyncClient"
- "com.azure.monitor.query.LogsQueryClient"
- "com.azure.monitor.query.LogsQueryClientBuilder"
- "com.azure.monitor.query.MetricsAsyncClient"
- "com.azure.monitor.query.MetricsClient"
- "com.azure.monitor.query.MetricsClientBuilder"
- "com.azure.monitor.query.MetricsQueryAsyncClient"
- "com.azure.monitor.query.MetricsQueryClient"
- "com.azure.monitor.query.MetricsQueryClientBuilder"
enums:
- "com.azure.monitor.query.LogsQueryServiceVersion"
- "com.azure.monitor.query.MetricsQueryServiceVersion"
- "com.azure.monitor.query.MetricsServiceVersion"
desc: "Azure Monitor Query service is a powerful tool that allows you to query and analyze log data from various sources in Azure. It is built on top of the Kusto Query Language (KQL), which is a powerful query language that allows you to perform complex queries on large datasets. With Azure Monitor Query, you can easily search and analyze log data from various sources, including virtual machines, containers, and applications.\n\nAzure Monitor Query java client library is a library that allows you to execute read-only queries against Azure Monitor\\\\u2019s two data platforms: Logs and Metrics. The library provides both synchronous and asynchronous forms of the clients.\n\n * [Logs][] \\- Collects and organizes log and performance data from monitored resources. Data from different sources such as platform logs from Azure services, log and performance data from virtual machines agents, and usage and performance data from apps can be consolidated into a single [Azure Log Analytics workspace][]. The various data types can be analyzed together using the Kusto Query Language.\n * [Metrics][] \\- Collects numeric data from monitored resources into a time series database. Metrics are numerical values that are collected at regular intervals and describe some aspect of a system at a particular time. Metrics are lightweight and capable of supporting near real-time scenarios, making them particularly useful for alerting and fast detection of issues.\n\n## Getting Started ##\n\nIn order to interact with the Monitor service you'll need to create an instance of the <xref uid=\"com.azure.monitor.query.LogsQueryClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.monitor.query.LogsQueryClient\"></xref> or <xref uid=\"com.azure.monitor.query.MetricsQueryClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.monitor.query.MetricsQueryClient\"></xref> class. To make this possible you'll need to use AAD authentication via [ Azure Identity][Azure Identity] to connect to the service.\n\n**Sample: Construct Asynchronous Clients**\n\nThe following code sample demonstrates the creation of a <xref uid=\"com.azure.monitor.query.LogsQueryAsyncClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.monitor.query.LogsQueryAsyncClient\"></xref> using the <xref uid=\"com.azure.monitor.query.LogsQueryClientBuilder\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.monitor.query.LogsQueryClientBuilder\"></xref>.\n\n```java\nLogsQueryAsyncClient logsQueryAsyncClient = new LogsQueryClientBuilder()\n .credential(tokenCredential)\n .buildAsyncClient();\n```\n\nThe following code sample demonstrates the creation of a <xref uid=\"com.azure.monitor.query.MetricsQueryAsyncClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.monitor.query.MetricsQueryAsyncClient\"></xref> using the <xref uid=\"com.azure.monitor.query.MetricsQueryClientBuilder\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.monitor.query.MetricsQueryClientBuilder\"></xref>.\n\n```java\nMetricsQueryAsyncClient metricsQueryAsyncClient = new MetricsQueryClientBuilder()\n .credential(tokenCredential)\n .buildAsyncClient();\n```\n\n**Sample: Construct Synchronous Clients**\n\nThe following code sample demonstrates the creation of a <xref uid=\"com.azure.monitor.query.LogsQueryClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.monitor.query.LogsQueryClient\"></xref> using the <xref uid=\"com.azure.monitor.query.LogsQueryClientBuilder\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.monitor.query.LogsQueryClientBuilder\"></xref>.\n\n```java\nLogsQueryClient logsQueryClient = new LogsQueryClientBuilder()\n .credential(tokenCredential)\n .buildClient();\n```\n\nThe following code sample demonstrates the creation of a <xref uid=\"com.azure.monitor.query.MetricsQueryClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.monitor.query.MetricsQueryClient\"></xref> using the <xref uid=\"com.azure.monitor.query.MetricsQueryClientBuilder\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.monitor.query.MetricsQueryClientBuilder\"></xref>.\n\n```java\nMetricsQueryClient metricsQueryClient = new MetricsQueryClientBuilder()\n .credential(tokenCredential)\n .buildClient();\n```\n\n\n--------------------\n\n## Query Workspace ##\n\nThe <xref uid=\"com.azure.monitor.query.LogsQueryClient.queryWorkspace(java.lang.String,java.lang.String,com.azure.monitor.query.models.QueryTimeInterval)\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Query Workspace API\"></xref> method can be used to query logs from a given workspace.\n\nThe sample below shows how to query logs from the last 24 hours\n\n```java\nLogsQueryResult queryResult = logsQueryClient.queryWorkspace(\"{workspace-id}\", \"{kusto-query}\",\n QueryTimeInterval.LAST_DAY);\n for (LogsTableRow row : queryResult.getTable().getRows()) {\n System.out.println(row.getRow()\n .stream()\n .map(LogsTableCell::getValueAsString)\n .collect(Collectors.joining(\",\")));\n }\n```\n\n**Note:** For asynchronous sample, refer to <xref uid=\"com.azure.monitor.query.LogsQueryAsyncClient.queryWorkspace(java.lang.String,java.lang.String,com.azure.monitor.query.models.QueryTimeInterval)\" data-throw-if-not-resolved=\"false\" data-raw-source=\"QueryWorkspace Async API\"></xref>.\n\n\n--------------------\n\n\n[Logs]: https://learn.microsoft.com/azure/azure-monitor/logs/data-platform-logs\n[Azure Log Analytics workspace]: https://learn.microsoft.com/azure/azure-monitor/logs/data-platform-logs#log-analytics-and-workspaces\n[Metrics]: https://learn.microsoft.com/azure/azure-monitor/essentials/data-platform-metrics\n[Azure Identity]: https://learn.microsoft.com/java/api/overview/azure/identity-readme?view=azure-java-stable"
metadata: {}
package: "com.azure.monitor.query"
artifact: com.azure:azure-monitor-query:1.5.3