Azure App Insights 记录外部数据操作员的功能

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

伙计们 在应用程序洞察日志中,我在自定义指标customDimensions中有一个列,用于存储来自不同进程的性能计数器,我使用自定义服务导出到洞察力和进程,我使用命令行标签,应用程序洞察中的记录是“D:\SvcFab_App\Services.AppType_App3058\Services .MyServicePkg.Code.1.0.0.20231208.3\Services.City.MyService.exe”。问题是我有大约 40 个服务结构应用程序类型,我想进行查询读取用作映射的 Blob 存储 JSON 文件,例如 App3058 是 TenantName/MyService.exe。看看我的示例查询,但我不知道该怎么做。

let LookupTargetApp = (cmdline: string) {
    toscalar(
        externaldata(targetApp: string, testline: string)
        [ 
            h@'https://mytest-blob.blob.core.windows.net/test/test.json?somesastoken'
        ]
        with(format='multijson', ingestionMapping='[{"Column":"targetApp","Properties":{"Path":"$.targetApp"}},{"Column":"testline","Properties":{"Path":"$.testline"}}]')
        | where testline == cmdline
        | project targetApp
    )
};

customMetrics
| where customDimensions != "" and name contains "procstat_memory_usage"
| extend cmdLineJson = parse_json(customDimensions).cmdline
| extend appType = trim('"' , tostring(split(cmdLineJson, '\\')[3]))
| extend appName = trim('"' , tostring(split(cmdLineJson, '\\')[4]))
| extend parts = split(appName, ".")
| extend result = strcat(parts[0], ".", parts[1], ".", parts[2])
| extend applicationName = strcat(appType, '\\', result)
| extend TargetApp = LookupTargetApp(applicationName)
| where name == "procstat_memory_usage"
| project TargetApp,value,valueMax,customDimensions

在上面的示例中,我收到错误不能使用“”,因为它是在其行上下文范围之外定义的。没关系,我想这是设计的限制。

我的想法是,我有一个 Json 文件,其中有两个属性,一个是

testline:Services.AppType_App3058\Services.City.MyService.exe
targetapp:MyTenant/MyService.exe
是否有可能我想要一个需要字符串输入的函数,然后从 blob 映射列中读取文件并比较和输出给定的 targetApp。在应用程序洞察和替换工作中也尝试过 case() 但想象一下我有 40 个应用程序类型,每个应用程序类型有 7 个服务,查询将很难维护。 谢谢!

azure azure-application-insights kql
1个回答
0
投票

toscalar()
功能有限制。您正在尝试使用扩展运算符调用表中具有
toscalar()
的用户定义函数。但在查询执行期间该函数只能被调用固定次数。

toscalar()
无法应用于每行都应用该函数的场景

解决方法是使用联接运算符并联接两个表,而不是使用扩展运算符。

代码:

let LookupTargetApp =
        externaldata(targetApp: string, testline: string)
        [ 
            h@'https://mytest-blob.blob.core.windows.net/test/test.json?somesastoken'
        ]
        with(format='multijson', ingestionMapping='[{"Column":"targetApp","Properties":{"Path":"$.targetApp"}},{"Column":"testline","Properties":{"Path":"$.testline"}}]')
        | where testline == cmdline
        | project targetApp;

customMetrics
| where customDimensions != "" and name contains "procstat_memory_usage"
| extend cmdLineJson = parse_json(customDimensions).cmdline
| extend appType = trim('"' , tostring(split(cmdLineJson, '\\')[3]))
| extend appName = trim('"' , tostring(split(cmdLineJson, '\\')[4]))
| extend parts = split(appName, ".")
| extend result = strcat(parts[0], ".", parts[1], ".", parts[2])
| extend applicationName = strcat(appType, '\\', result)
| join kind = inner (LookupTargetApp) on $left.applicationName = $right.testline
| where name == "procstat_memory_usage"
| project TargetApp,value,valueMax,customDimensions

在上面的代码中,用连接运算符替换了扩展运算符。

请参阅 MS 文档,其中包含示例代码。

© www.soinside.com 2019 - 2024. All rights reserved.