Compétences Azure Monitor Ingestion SDK for Java
📦

Azure Monitor Ingestion SDK for Java

Sûr

使用 Java 发送自定义日志到 Azure Monitor

自定义应用程序日志需要集中化监控。此技能帮助您使用数据收集规则 (DCR) 和官方 Java SDK 将日志摄入到 Azure Monitor。

Prend en charge: Claude Codex Code(CC)
🥉 72 Bronze
1

Télécharger le ZIP du skill

2

Importer dans Claude

Allez dans Paramètres → Capacités → Skills → Importer un skill

3

Activez et commencez à utiliser

Tester

Utilisation de "Azure Monitor Ingestion SDK for Java". 使用 DefaultAzureCredential 创建 LogsIngestionClient,端点从环境变量读取

Résultat attendu:

DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();

LogsIngestionClient client = new LogsIngestionClientBuilder()
.endpoint(System.getenv("DATA_COLLECTION_ENDPOINT"))
.credential(credential)
.buildClient();

Utilisation de "Azure Monitor Ingestion SDK for Java". 使用 DCR ID 和流名称上传 3 条日志条目到 Azure Monitor

Résultat attendu:

List<Object> logs = new ArrayList<>();
logs.add(new MyLogEntry("2024-01-15T10:30:00Z", "INFO", "Application started"));
logs.add(new MyLogEntry("2024-01-15T10:30:05Z", "DEBUG", "Processing request"));
logs.add(new MyLogEntry("2024-01-15T10:30:10Z", "WARN", "High memory usage detected"));

client.upload(ruleId, streamName, logs);
System.out.println("Logs uploaded successfully");

Audit de sécurité

Sûr
v1 • 2/25/2026

Documentation-only skill containing usage examples for the official Azure Monitor Ingestion SDK for Java. No executable code, no security risks detected. Static analysis found 0 files with 0 suspicious patterns. The skill provides legitimate Azure SDK integration patterns with proper authentication using DefaultAzureCredential.

0
Fichiers analysés
0
Lignes analysées
0
résultats
1
Total des audits
Aucun problème de sécurité trouvé
Audité par: claude

Score de qualité

38
Architecture
100
Maintenabilité
87
Contenu
50
Communauté
100
Sécurité
74
Conformité aux spécifications

Ce que vous pouvez construire

应用程序遥测摄入

将自定义应用程序日志、指标和事件从 Java 应用程序发送到 Azure Monitor,以实现集中化监控和告警。

安全事件收集

将安全审计日志和合规性事件摄入到 Azure Monitor 的 SecurityEvents 或 CommonSecurityLog 表中,用于 SIEM 集成。

自定义业务指标

通过将结构化日志上传到 Log Analytics 工作区中的自定义表来跟踪特定业务事件和 KPI。

Essayez ces prompts

基础客户端设置
使用环境变量(端点、DCR ID 和流名称)创建同步 LogsIngestionClient 用于 Azure Monitor。包含 DefaultAzureCredential 身份验证。
带错误处理的日志上传
生成 Java 代码将自定义日志列表上传到 Azure Monitor,支持部分失败处理。记录失败的条目而不中止整个批次。
并发大型上传
创建一个异步上传方法,将 10000 条日志条目发送到 Azure Monitor,maxConcurrency 设置为 5。使用 Reactor Mono 进行响应式流处理。
自定义日志条目模型
定义一个自定义日志条目的 Java 类,包含 timeGenerated、severity、source 和 message 字段。包含日志摄入 API 所需的 JSON 序列化 getter 方法。

Bonnes pratiques

  • 上传前批量处理日志条目,而不是逐个发送以获得更好的性能
  • 上传大型日志集合时设置 maxConcurrency 选项以提高吞吐量
  • 在日志条目中包含 TimeGenerated 字段,因为大多数 Azure Monitor 表都需要时间戳

Éviter

  • 为每次上传创建新客户端实例 - 应在整个应用程序生命周期中重用单个客户端
  • 在高吞吐量场景中同步上传日志 - 对于响应式模式请使用异步客户端
  • 忽略部分上传错误 - 应始终配置错误消费者以处理失败的条目

Foire aux questions

使用此技能前需要哪些先决条件?
您需要在 Azure Monitor 中配置数据收集端点 (DCE)、数据收集规则 (DCR)、Log Analytics 工作区和目标表。
如何向 Azure Monitor 进行身份验证?
使用 DefaultAzureCredential,它自动支持托管身份、环境凭证和其他 Azure 身份验证方法。
可以上传日志到自定义表吗?
是的,您可以在流名称中使用 Custom- 前缀上传到自定义表,或上传到内置表如 CommonSecurityLog 和 SecurityEvents。
如何处理上传失败?
使用带有 setLogsUploadErrorConsumer 的 LogsUploadOptions 来优雅地处理部分失败,而不中止整个批次。
同步和异步客户端之间有什么区别?
同步客户端会阻塞直到上传完成。异步客户端返回 Mono<Void> 用于非阻塞响应式模式,具有更好的吞吐量。
摄入后如何查询日志?
使用 azure-monitor-query 技能配合 LogsQueryClient 对您的 Log Analytics 工作区运行 KQL 查询。

Détails du développeur

Structure de fichiers

📄 SKILL.md