一键导入
azure-monitor-query-java
Azure Monitor Query SDK for Java. Execute Kusto queries against Log Analytics workspaces and query metrics from Azure resources.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Azure Monitor Query SDK for Java. Execute Kusto queries against Log Analytics workspaces and query metrics from Azure resources.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when the user wants to plan a content strategy, decide what content to create, figure out topics, or mentions content strategy, content planning, or editorial calendars.
Research and analyze competitors from their URLs to build structured competitor profile documents, dossiers, and competitive intelligence overviews.
Conduct comprehensive SSH security assessments including enumeration, credential attacks, vulnerability exploitation, tunneling techniques, and post-exploitation activities. This skill covers the complete methodology for testing SSH service security.
Azure AI Document Intelligence SDK for .NET. Extract text, tables, and structured data from documents using prebuilt and custom models.
Build and leverage online communities to drive product growth and brand loyalty.
The Gemini API provides access to Google's most advanced AI models. Key capabilities include:
| name | azure-monitor-query-java |
| description | Azure Monitor Query SDK for Java. Execute Kusto queries against Log Analytics workspaces and query metrics from Azure resources. |
| risk | unknown |
| source | community |
| date_added | 2026-02-27 |
Client libraries for querying Azure Monitor Logs and Metrics using the new, modular azure-monitor-query-logs and azure-monitor-query-metrics SDKs.
Add the corresponding packages to your pom.xml depending on your needs.
For Logs:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-monitor-query-logs</artifactId>
<version>1.x.x</version> <!-- Use the latest version -->
</dependency>
For Metrics:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-monitor-query-metrics</artifactId>
<version>1.x.x</version> <!-- Use the latest version -->
</dependency>
Or use the Azure SDK BOM for version management:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-sdk-bom</artifactId>
<version>{bom_version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-monitor-query-logs</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-monitor-query-metrics</artifactId>
</dependency>
</dependencies>
LOG_ANALYTICS_WORKSPACE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
AZURE_RESOURCE_ID=/subscriptions/{sub}/resourceGroups/{rg}/providers/{provider}/{resource}
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.monitor.query.logs.LogsQueryClient;
import com.azure.monitor.query.logs.LogsQueryClientBuilder;
import com.azure.core.credential.TokenCredential;
TokenCredential credential = new DefaultAzureCredentialBuilder().build();
LogsQueryClient logsClient = new LogsQueryClientBuilder()
.credential(credential)
.buildClient();
import com.azure.monitor.query.logs.LogsQueryAsyncClient;
LogsQueryAsyncClient logsAsyncClient = new LogsQueryClientBuilder()
.credential(credential)
.buildAsyncClient();
import com.azure.monitor.query.metrics.MetricsQueryClient;
import com.azure.monitor.query.metrics.MetricsQueryClientBuilder;
MetricsQueryClient metricsClient = new MetricsQueryClientBuilder()
.credential(credential)
.buildClient();
import com.azure.monitor.query.metrics.MetricsQueryAsyncClient;
MetricsQueryAsyncClient metricsAsyncClient = new MetricsQueryClientBuilder()
.credential(credential)
.buildAsyncClient();
| Concept | Description |
|---|---|
| Logs | Log and performance data from Azure resources via Kusto Query Language |
| Metrics | Numeric time-series data collected at regular intervals |
| Workspace ID | Log Analytics workspace identifier |
| Resource ID | Azure resource URI for metrics queries |
| LogsQueryTimeInterval | Time range for the log query |
import com.azure.monitor.query.logs.models.LogsQueryResult;
import com.azure.monitor.query.logs.models.LogsTableRow;
import com.azure.monitor.query.logs.models.LogsQueryTimeInterval;
import java.time.Duration;
LogsQueryResult result = logsClient.queryWorkspace(
"{workspace-id}",
"AzureActivity | summarize count() by ResourceGroup | top 10 by count_",
new LogsQueryTimeInterval(Duration.ofDays(7))
);
for (LogsTableRow row : result.getTable().getRows()) {
System.out.println(row.getColumnValue("ResourceGroup").get().getValueAsString() + ": " + row.getColumnValue("count_").get().getValueAsString());
}
LogsQueryResult result = logsClient.queryResource(
"{resource-id}",
"AzureMetrics | where TimeGenerated > ago(1h)",
new LogsQueryTimeInterval(Duration.ofDays(1))
);
for (LogsTableRow row : result.getTable().getRows()) {
System.out.println(row.getColumnValue("MetricName") + " " + row.getColumnValue("Average"));
}
// Define model class
public class ActivityLog {
private String resourceGroup;
private String operationName;
public String getResourceGroup() { return resourceGroup; }
public String getOperationName() { return operationName; }
}
// Query with model mapping
List<ActivityLog> logs = logsClient.queryWorkspace(
"{workspace-id}",
"AzureActivity | project ResourceGroup, OperationName | take 100",
new QueryTimeInterval(Duration.ofDays(2)),
ActivityLog.class
);
for (ActivityLog log : logs) {
System.out.println(log.getOperationName() + " - " + log.getResourceGroup());
}
import com.azure.monitor.query.logs.models.LogsBatchQuery;
import com.azure.monitor.query.logs.models.LogsBatchQueryResult;
import com.azure.monitor.query.logs.models.LogsBatchQueryResultCollection;
import com.azure.monitor.query.logs.models.LogsQueryResultStatus;
import com.azure.core.util.Context;
LogsBatchQuery batchQuery = new LogsBatchQuery();
String q1 = batchQuery.addWorkspaceQuery("{workspace-id}", "AzureActivity | count", new LogsQueryTimeInterval(Duration.ofDays(1)));
String q2 = batchQuery.addWorkspaceQuery("{workspace-id}", "Heartbeat | count", new LogsQueryTimeInterval(Duration.ofDays(1)));
String q3 = batchQuery.addWorkspaceQuery("{workspace-id}", "Perf | count", new LogsQueryTimeInterval(Duration.ofDays(1)));
LogsBatchQueryResultCollection results = logsClient
.queryBatchWithResponse(batchQuery, Context.NONE)
.getValue();
LogsBatchQueryResult result1 = results.getResult(q1);
LogsBatchQueryResult result2 = results.getResult(q2);
LogsBatchQueryResult result3 = results.getResult(q3);
// Check for failures
if (result3.getQueryResultStatus() == LogsQueryResultStatus.FAILURE) {
System.err.println("Query failed: " + result3.getError().getMessage());
}
import com.azure.monitor.query.metrics.models.MetricsQueryResult;
import com.azure.monitor.query.metrics.models.MetricResult;
import com.azure.monitor.query.metrics.models.TimeSeriesElement;
import com.azure.monitor.query.metrics.models.MetricValue;
import java.util.Arrays;
MetricsQueryResult result = metricsClient.queryResource(
"{resource-uri}",
Arrays.asList("SuccessfulCalls", "TotalCalls")
);
for (MetricResult metric : result.getMetrics()) {
System.out.println("Metric: " + metric.getMetricName());
for (TimeSeriesElement ts : metric.getTimeSeries()) {
System.out.println(" Dimensions: " + ts.getMetadata());
for (MetricValue value : ts.getValues()) {
System.out.println(" " + value.getTimeStamp() + ": " + value.getTotal());
}
}
}
import com.azure.monitor.query.metrics.models.MetricsQueryOptions;
import com.azure.monitor.query.metrics.models.AggregationType;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
Response<MetricsQueryResult> response = metricsClient.queryResourceWithResponse(
"{resource-id}",
Arrays.asList("SuccessfulCalls", "TotalCalls"),
new MetricsQueryOptions()
.setGranularity(Duration.ofHours(1))
.setAggregations(Arrays.asList(AggregationType.AVERAGE, AggregationType.COUNT)),
Context.NONE
);
MetricsQueryResult result = response.getValue();
The legacy combined package azure-monitor-query is deprecated. Code must be updated to use the modular packages azure-monitor-query-logs and azure-monitor-query-metrics.
Key changes:
com.azure.monitor.query -> com.azure.monitor.query.logs and com.azure.monitor.query.metricsQueryTimeInterval has been renamed to LogsQueryTimeInterval for the logs package, and similarly separated for the metrics package if applicable.azure-monitor-query Maven dependency with azure-monitor-query-logs and/or azure-monitor-query-metrics.import com.azure.core.exception.HttpResponseException;
import com.azure.monitor.query.logs.models.LogsQueryResultStatus;
try {
LogsQueryResult result = logsClient.queryWorkspace(workspaceId, query, timeInterval);
// Check partial failure
if (result.getQueryResultStatus() == LogsQueryResultStatus.PARTIAL_FAILURE) {
System.err.println("Partial failure: " + result.getError().getMessage());
}
} catch (HttpResponseException e) {
System.err.println("Query failed: " + e.getMessage());
System.err.println("Status: " + e.getResponse().getStatusCode());
}
top or take in Kusto queriesprojectThis skill is applicable to execute the workflow or actions described in the overview.