Azure Monitor Ingestion SDK for Java
使用 Java 发送自定义日志到 Azure Monitor
自定义应用程序日志需要集中化监控。此技能帮助您使用数据收集规则 (DCR) 和官方 Java SDK 将日志摄入到 Azure Monitor。
Télécharger le ZIP du skill
Importer dans Claude
Allez dans Paramètres → Capacités → Skills → Importer un skill
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ûrDocumentation-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.
Score de qualité
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 进行身份验证?
可以上传日志到自定义表吗?
如何处理上传失败?
同步和异步客户端之间有什么区别?
摄入后如何查询日志?
Détails du développeur
Auteur
sickn33Licence
MIT
Dépôt
https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/azure-monitor-ingestion-javaRéf
main
Structure de fichiers
📄 SKILL.md