[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-86d1b313-2679-47f1-bd32-dfc9d2280ad2":3,"$fhRFr4ly_lCBZjiKL6Cs_rVLROARjA2GkjazTZZ5JcZg":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"86d1b313-2679-47f1-bd32-dfc9d2280ad2","azure-monitor-query-java","Azure Monitor 查询 SDK for Java。针对日志分析工作区执行 Kusto 查询并查询 Azure 资源指标。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-monitor-query-java\ndescription: Azure Monitor Query SDK for Java. Execute Kusto queries against Log Analytics workspaces and query metrics from Azure resources.\nrisk: safe\nsource: community\ndate_added: '2026-02-27'\n---\n\n# Azure Monitor Query SDK for Java\n\n> **DEPRECATION NOTICE**: This package is deprecated in favor of:\n> - `azure-monitor-query-logs` — For Log Analytics queries\n> - `azure-monitor-query-metrics` — For metrics queries\n>\n> See migration guides: [Logs Migration](https:\u002F\u002Fgithub.com\u002FAzure\u002Fazure-sdk-for-java\u002Fblob\u002Fmain\u002Fsdk\u002Fmonitor\u002Fazure-monitor-query-logs\u002Fmigration-guide.md) | [Metrics Migration](https:\u002F\u002Fgithub.com\u002FAzure\u002Fazure-sdk-for-java\u002Fblob\u002Fmain\u002Fsdk\u002Fmonitor\u002Fazure-monitor-query-metrics\u002Fmigration-guide.md)\n\nClient library for querying Azure Monitor Logs and Metrics.\n\n## Installation\n\n```xml\n\u003Cdependency>\n    \u003CgroupId>com.azure\u003C\u002FgroupId>\n    \u003CartifactId>azure-monitor-query\u003C\u002FartifactId>\n    \u003Cversion>1.5.9\u003C\u002Fversion>\n\u003C\u002Fdependency>\n```\n\nOr use Azure SDK BOM:\n\n```xml\n\u003CdependencyManagement>\n    \u003Cdependencies>\n        \u003Cdependency>\n            \u003CgroupId>com.azure\u003C\u002FgroupId>\n            \u003CartifactId>azure-sdk-bom\u003C\u002FartifactId>\n            \u003Cversion>{bom_version}\u003C\u002Fversion>\n            \u003Ctype>pom\u003C\u002Ftype>\n            \u003Cscope>import\u003C\u002Fscope>\n        \u003C\u002Fdependency>\n    \u003C\u002Fdependencies>\n\u003C\u002FdependencyManagement>\n\n\u003Cdependencies>\n    \u003Cdependency>\n        \u003CgroupId>com.azure\u003C\u002FgroupId>\n        \u003CartifactId>azure-monitor-query\u003C\u002FartifactId>\n    \u003C\u002Fdependency>\n\u003C\u002Fdependencies>\n```\n\n## Prerequisites\n\n- Log Analytics workspace (for logs queries)\n- Azure resource (for metrics queries)\n- TokenCredential with appropriate permissions\n\n## Environment Variables\n\n```bash\nLOG_ANALYTICS_WORKSPACE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\nAZURE_RESOURCE_ID=\u002Fsubscriptions\u002F{sub}\u002FresourceGroups\u002F{rg}\u002Fproviders\u002F{provider}\u002F{resource}\n```\n\n## Client Creation\n\n### LogsQueryClient (Sync)\n\n```java\nimport com.azure.identity.DefaultAzureCredentialBuilder;\nimport com.azure.monitor.query.LogsQueryClient;\nimport com.azure.monitor.query.LogsQueryClientBuilder;\n\nLogsQueryClient logsClient = new LogsQueryClientBuilder()\n    .credential(new DefaultAzureCredentialBuilder().build())\n    .buildClient();\n```\n\n### LogsQueryAsyncClient\n\n```java\nimport com.azure.monitor.query.LogsQueryAsyncClient;\n\nLogsQueryAsyncClient logsAsyncClient = new LogsQueryClientBuilder()\n    .credential(new DefaultAzureCredentialBuilder().build())\n    .buildAsyncClient();\n```\n\n### MetricsQueryClient (Sync)\n\n```java\nimport com.azure.monitor.query.MetricsQueryClient;\nimport com.azure.monitor.query.MetricsQueryClientBuilder;\n\nMetricsQueryClient metricsClient = new MetricsQueryClientBuilder()\n    .credential(new DefaultAzureCredentialBuilder().build())\n    .buildClient();\n```\n\n### MetricsQueryAsyncClient\n\n```java\nimport com.azure.monitor.query.MetricsQueryAsyncClient;\n\nMetricsQueryAsyncClient metricsAsyncClient = new MetricsQueryClientBuilder()\n    .credential(new DefaultAzureCredentialBuilder().build())\n    .buildAsyncClient();\n```\n\n### Sovereign Cloud Configuration\n\n```java\n\u002F\u002F Azure China Cloud - Logs\nLogsQueryClient logsClient = new LogsQueryClientBuilder()\n    .credential(new DefaultAzureCredentialBuilder().build())\n    .endpoint(\"https:\u002F\u002Fapi.loganalytics.azure.cn\u002Fv1\")\n    .buildClient();\n\n\u002F\u002F Azure China Cloud - Metrics\nMetricsQueryClient metricsClient = new MetricsQueryClientBuilder()\n    .credential(new DefaultAzureCredentialBuilder().build())\n    .endpoint(\"https:\u002F\u002Fmanagement.chinacloudapi.cn\")\n    .buildClient();\n```\n\n## Key Concepts\n\n| Concept | Description |\n|---------|-------------|\n| Logs | Log and performance data from Azure resources via Kusto Query Language |\n| Metrics | Numeric time-series data collected at regular intervals |\n| Workspace ID | Log Analytics workspace identifier |\n| Resource ID | Azure resource URI for metrics queries |\n| QueryTimeInterval | Time range for the query |\n\n## Logs Query Operations\n\n### Basic Query\n\n```java\nimport com.azure.monitor.query.models.LogsQueryResult;\nimport com.azure.monitor.query.models.LogsTableRow;\nimport com.azure.monitor.query.models.QueryTimeInterval;\nimport java.time.Duration;\n\nLogsQueryResult result = logsClient.queryWorkspace(\n    \"{workspace-id}\",\n    \"AzureActivity | summarize count() by ResourceGroup | top 10 by count_\",\n    new QueryTimeInterval(Duration.ofDays(7))\n);\n\nfor (LogsTableRow row : result.getTable().getRows()) {\n    System.out.println(row.getColumnValue(\"ResourceGroup\") + \": \" + row.getColumnValue(\"count_\"));\n}\n```\n\n### Query by Resource ID\n\n```java\nLogsQueryResult result = logsClient.queryResource(\n    \"{resource-id}\",\n    \"AzureMetrics | where TimeGenerated > ago(1h)\",\n    new QueryTimeInterval(Duration.ofDays(1))\n);\n\nfor (LogsTableRow row : result.getTable().getRows()) {\n    System.out.println(row.getColumnValue(\"MetricName\") + \" \" + row.getColumnValue(\"Average\"));\n}\n```\n\n### Map Results to Custom Model\n\n```java\n\u002F\u002F Define model class\npublic class ActivityLog {\n    private String resourceGroup;\n    private String operationName;\n    \n    public String getResourceGroup() { return resourceGroup; }\n    public String getOperationName() { return operationName; }\n}\n\n\u002F\u002F Query with model mapping\nList\u003CActivityLog> logs = logsClient.queryWorkspace(\n    \"{workspace-id}\",\n    \"AzureActivity | project ResourceGroup, OperationName | take 100\",\n    new QueryTimeInterval(Duration.ofDays(2)),\n    ActivityLog.class\n);\n\nfor (ActivityLog log : logs) {\n    System.out.println(log.getOperationName() + \" - \" + log.getResourceGroup());\n}\n```\n\n### Batch Query\n\n```java\nimport com.azure.monitor.query.models.LogsBatchQuery;\nimport com.azure.monitor.query.models.LogsBatchQueryResult;\nimport com.azure.monitor.query.models.LogsBatchQueryResultCollection;\nimport com.azure.core.util.Context;\n\nLogsBatchQuery batchQuery = new LogsBatchQuery();\nString q1 = batchQuery.addWorkspaceQuery(\"{workspace-id}\", \"AzureActivity | count\", new QueryTimeInterval(Duration.ofDays(1)));\nString q2 = batchQuery.addWorkspaceQuery(\"{workspace-id}\", \"Heartbeat | count\", new QueryTimeInterval(Duration.ofDays(1)));\nString q3 = batchQuery.addWorkspaceQuery(\"{workspace-id}\", \"Perf | count\", new QueryTimeInterval(Duration.ofDays(1)));\n\nLogsBatchQueryResultCollection results = logsClient\n    .queryBatchWithResponse(batchQuery, Context.NONE)\n    .getValue();\n\nLogsBatchQueryResult result1 = results.getResult(q1);\nLogsBatchQueryResult result2 = results.getResult(q2);\nLogsBatchQueryResult result3 = results.getResult(q3);\n\n\u002F\u002F Check for failures\nif (result3.getQueryResultStatus() == LogsQueryResultStatus.FAILURE) {\n    System.err.println(\"Query failed: \" + result3.getError().getMessage());\n}\n```\n\n### Query with Options\n\n```java\nimport com.azure.monitor.query.models.LogsQueryOptions;\nimport com.azure.core.http.rest.Response;\n\nLogsQueryOptions options = new LogsQueryOptions()\n    .setServerTimeout(Duration.ofMinutes(10))\n    .setIncludeStatistics(true)\n    .setIncludeVisualization(true);\n\nResponse\u003CLogsQueryResult> response = logsClient.queryWorkspaceWithResponse(\n    \"{workspace-id}\",\n    \"AzureActivity | summarize count() by bin(TimeGenerated, 1h)\",\n    new QueryTimeInterval(Duration.ofDays(7)),\n    options,\n    Context.NONE\n);\n\nLogsQueryResult result = response.getValue();\n\n\u002F\u002F Access statistics\nBinaryData statistics = result.getStatistics();\n\u002F\u002F Access visualization data\nBinaryData visualization = result.getVisualization();\n```\n\n### Query Multiple Workspaces\n\n```java\nimport java.util.Arrays;\n\nLogsQueryOptions options = new LogsQueryOptions()\n    .setAdditionalWorkspaces(Arrays.asList(\"{workspace-id-2}\", \"{workspace-id-3}\"));\n\nResponse\u003CLogsQueryResult> response = logsClient.queryWorkspaceWithResponse(\n    \"{workspace-id-1}\",\n    \"AzureActivity | summarize count() by TenantId\",\n    new QueryTimeInterval(Duration.ofDays(1)),\n    options,\n    Context.NONE\n);\n```\n\n## Metrics Query Operations\n\n### Basic Metrics Query\n\n```java\nimport com.azure.monitor.query.models.MetricsQueryResult;\nimport com.azure.monitor.query.models.MetricResult;\nimport com.azure.monitor.query.models.TimeSeriesElement;\nimport com.azure.monitor.query.models.MetricValue;\nimport java.util.Arrays;\n\nMetricsQueryResult result = metricsClient.queryResource(\n    \"{resource-uri}\",\n    Arrays.asList(\"SuccessfulCalls\", \"TotalCalls\")\n);\n\nfor (MetricResult metric : result.getMetrics()) {\n    System.out.println(\"Metric: \" + metric.getMetricName());\n    for (TimeSeriesElement ts : metric.getTimeSeries()) {\n        System.out.println(\"  Dimensions: \" + ts.getMetadata());\n        for (MetricValue value : ts.getValues()) {\n            System.out.println(\"    \" + value.getTimeStamp() + \": \" + value.getTotal());\n        }\n    }\n}\n```\n\n### Metrics with Aggregations\n\n```java\nimport com.azure.monitor.query.models.MetricsQueryOptions;\nimport com.azure.monitor.query.models.AggregationType;\n\nResponse\u003CMetricsQueryResult> response = metricsClient.queryResourceWithResponse(\n    \"{resource-id}\",\n    Arrays.asList(\"SuccessfulCalls\", \"TotalCalls\"),\n    new MetricsQueryOptions()\n        .setGranularity(Duration.ofHours(1))\n        .setAggregations(Arrays.asList(AggregationType.AVERAGE, AggregationType.COUNT)),\n    Context.NONE\n);\n\nMetricsQueryResult result = response.getValue();\n```\n\n### Query Multiple Resources (MetricsClient)\n\n```java\nimport com.azure.monitor.query.MetricsClient;\nimport com.azure.monitor.query.MetricsClientBuilder;\nimport com.azure.monitor.query.models.MetricsQueryResourcesResult;\n\nMetricsClient metricsClient = new MetricsClientBuilder()\n    .credential(new DefaultAzureCredentialBuilder().build())\n    .endpoint(\"{endpoint}\")\n    .buildClient();\n\nMetricsQueryResourcesResult result = metricsClient.queryResources(\n    Arrays.asList(\"{resourceId1}\", \"{resourceId2}\"),\n    Arrays.asList(\"{metric1}\", \"{metric2}\"),\n    \"{metricNamespace}\"\n);\n\nfor (MetricsQueryResult queryResult : result.getMetricsQueryResults()) {\n    for (MetricResult metric : queryResult.getMetrics()) {\n        System.out.println(metric.getMetricName());\n        metric.getTimeSeries().stream()\n            .flatMap(ts -> ts.getValues().stream())\n            .forEach(mv -> System.out.println(\n                mv.getTimeStamp() + \" Count=\" + mv.getCount() + \" Avg=\" + mv.getAverage()));\n    }\n}\n```\n\n## Response Structure\n\n### Logs Response Hierarchy\n\n```\nLogsQueryResult\n├── statistics (BinaryData)\n├── visualization (BinaryData)\n├── error\n└── tables (List\u003CLogsTable>)\n    ├── name\n    ├── columns (List\u003CLogsTableColumn>)\n    │   ├── name\n    │   └── type\n    └── rows (List\u003CLogsTableRow>)\n        ├── rowIndex\n        └── rowCells (List\u003CLogsTableCell>)\n```\n\n### Metrics Response Hierarchy\n\n```\nMetricsQueryResult\n├── granularity\n├── timeInterval\n├── namespace\n├── resourceRegion\n└── metrics (List\u003CMetricResult>)\n    ├── id, name, type, unit\n    └── timeSeries (List\u003CTimeSeriesElement>)\n        ├── metadata (dimensions)\n        └── values (List\u003CMetricValue>)\n            ├── timeStamp\n            ├── count, average, total\n            ├── maximum, minimum\n```\n\n## Error Handling\n\n```java\nimport com.azure.core.exception.HttpResponseException;\nimport com.azure.monitor.query.models.LogsQueryResultStatus;\n\ntry {\n    LogsQueryResult result = logsClient.queryWorkspace(workspaceId, query, timeInterval);\n    \n    \u002F\u002F Check partial failure\n    if (result.getStatus() == LogsQueryResultStatus.PARTIAL_FAILURE) {\n        System.err.println(\"Partial failure: \" + result.getError().getMessage());\n    }\n} catch (HttpResponseException e) {\n    System.err.println(\"Query failed: \" + e.getMessage());\n    System.err.println(\"Status: \" + e.getResponse().getStatusCode());\n}\n```\n\n## Best Practices\n\n1. **Use batch queries** — Combine multiple queries into a single request\n2. **Set appropriate timeouts** — Long queries may need extended server timeout\n3. **Limit result size** — Use `top` or `take` in Kusto queries\n4. **Use projections** — Select only needed columns with `project`\n5. **Check query status** — Handle PARTIAL_FAILURE results gracefully\n6. **Cache results** — Metrics don't change frequently; cache when appropriate\n7. **Migrate to new packages** — Plan migration to `azure-monitor-query-logs` and `azure-monitor-query-metrics`\n\n## Reference Links\n\n| Resource | URL |\n|----------|-----|\n| Maven Package | https:\u002F\u002Fcentral.sonatype.com\u002Fartifact\u002Fcom.azure\u002Fazure-monitor-query |\n| GitHub | https:\u002F\u002Fgithub.com\u002FAzure\u002Fazure-sdk-for-java\u002Ftree\u002Fmain\u002Fsdk\u002Fmonitor\u002Fazure-monitor-query |\n| API Reference | https:\u002F\u002Flearn.microsoft.com\u002Fjava\u002Fapi\u002Fcom.azure.monitor.query |\n| Kusto Query Language | https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fdata-explorer\u002Fkusto\u002Fquery\u002F |\n| Log Analytics Limits | https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fazure-monitor\u002Fservice-limits#la-query-api |\n| Troubleshooting | https:\u002F\u002Fgithub.com\u002FAzure\u002Fazure-sdk-for-java\u002Fblob\u002Fmain\u002Fsdk\u002Fmonitor\u002Fazure-monitor-query\u002FTROUBLESHOOTING.md |\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,190,1132,"2026-05-16 13:07:19",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"6ab22754-8f58-4e1b-b72a-3ff91ff8271a","1.0.0","azure-monitor-query-java.zip",3872,"uploads\u002Fskills\u002F86d1b313-2679-47f1-bd32-dfc9d2280ad2\u002Fazure-monitor-query-java.zip","a26ba74d1ba14320c81d54c7e7f3f3d176f25fece351d58929b3a0a69c4c2046","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":13391}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]