使用警报规则从 Azure Application Insights 发送自定义尺寸

问题描述 投票:0回答:1

我是 Azure 新手,对 Azure 中的自定义指标功能有一些疑问。我的应用程序正在向 Azure Application Insights 发送自定义指标信号。如果我转到 Azure 中的日志,我可以清楚地看到信号以及以 customDimentions 形式表示的内容。此信号由 Azure 警报捕获,该警报将有效负载发送到指定的 Webhook。问题是我找不到将 customDImentions 对象添加到警报有效负载中。我知道警报有自定义属性,但这些属性是静态的。

有人知道解决方案或解决方法吗?

从我的应用程序发送信号后,我可以在警报中获取一些信息,例如信号名称和值,但不是其属性

java azure azure-application-insights metrics open-telemetry
1个回答
0
投票

cbiebcfo

  • 使用
    TelemetryClient
    设置自定义属性。确保将
    "CustomProperty1"
    "CustomProperty2"
    替换为您实际的自定义维度名称
import com.microsoft.applicationinsights.TelemetryClient;
import com.microsoft.applicationinsights.telemetry.MetricTelemetry;

public class MyApp {
    private static TelemetryClient telemetry = new TelemetryClient();

    public static void main(String[] args) {
        // Your custom telemetry object
        MyTelemetryObject customTelemetry = new MyTelemetryObject();

        // Track custom metric
        telemetry.trackMetric(new MetricTelemetry("MetricName", customTelemetry.getValue()));

        // Add custom dimensions
        telemetry.getContext().getProperties().put("CustomProperty1", customTelemetry.getCustomProperty1());
        telemetry.getContext().getProperties().put("CustomProperty2", customTelemetry.getCustomProperty2());

        // Flush telemetry data
        telemetry.flush();
    }
}

  • 使用 Kusto 查询语言 (KQL) 过滤和提取相关数据。
customDimensions.CustomProperty1 == "Value1" and customDimensions.CustomProperty2 == "Value2"

我们需要检查 Log Analytics 查询是否在结果集中包含必要的自定义维度。
enter image description here

  • 更新 Azure Monitor 警报规则以触发您创建的 Azure 逻辑应用,而不是直接发送 Webhook。在 Java 应用程序中设置服务器或端点来处理逻辑应用程序发送的 Webhook 通知。
© www.soinside.com 2019 - 2024. All rights reserved.