当前位置: 首页 > 知识库问答 >
问题:

Azure应用程序洞察Kusto语言汇总时生成值的位置(where Time Generated Value)

庄实
2023-03-14

有没有办法用Kusto语言将where子句放在不同的列中。我知道“pivot”语法,它也与SQL一起用于创建基于唯一值的列。但别以为这对我的案子有帮助。还有一个SO的问题几乎和我有同样的问题。但他的解决方案也不奏效。

我的查询的上下文:这个查询获取每个月每台机器的运行时。您可能想知道为什么我要用这么长的查询来实现这一点。欢迎您的任何意见和调整。我对这门语言很陌生。并且我已经使用top查询来获取另一个项目中每个VM的启动和停止时间。

原始查询:

AzureActivity
| where ResourceProvider == "Microsoft.Compute"
and ActivityStatus == "Succeeded"
and OperationName == "Deallocate Virtual Machine"
| project DeallocateResource=Resource
,DeallocatedDate=format_datetime(EventSubmissionTimestamp, 'yyyy-MM-dd')
,DeallocatedTime=format_datetime(EventSubmissionTimestamp, 'HH:mm:ss')
| join kind=fullouter (AzureActivity
| where ResourceProvider == "Microsoft.Compute"
and ActivityStatus == "Succeeded"
and OperationName == "Start Virtual Machine"
| project StartupResource=Resource
,StartDate=format_datetime(EventSubmissionTimestamp, 'yyyy-MM-dd')
,StartTime=format_datetime(EventSubmissionTimestamp, 'HH:mm:ss')
) on $right.StartupResource == $left.DeallocateResource
| where StartDate == DeallocatedDate
| project Resource=coalesce(StartupResource, DeallocateResource) ,
Runtime = round(todouble(datetime_diff('minute', todatetime(strcat(StartDate , " " , DeallocatedTime )) , todatetime(strcat(StartDate , " " , StartTime )))) / 60)
| summarize sum(Runtime) by Resource
| where TimeGenerated > ago(30d)
| where TimeGenerated between(ago(30d) .. ago(60d) )
| where TimeGenerated between(ago(60d) .. ago(90d) )

| summarize sum(Runtime) by Resource , bin(TimeGenerated, 1m)
| summarize Fistmonth = TimeGenerated > ago(30d),  
            SecondMonth = TimeGenerated between(ago(30d) .. ago(60d)) ,
            ThirdMonth = Runtime_,TimeGenerated between(ago(60d) .. ago(90d) ) by Resource

有没有人知道我在这里错过了什么。这对库斯托可能吗?并且我是否使用了一个开销的查询来完成一些可以在几行中完成的事情。

共有1个答案

訾渝
2023-03-14

如果我正确地理解了您的场景,那么您可以使用sumif来实现这一目标,前提是您事先知道目标的月份。

这里有一个例子:

datatable(Resource:string, Runtime:double, TimeGenerated:datetime)
[
    "A", 13.4, datetime(2019-01-01 11:11:11),
    "B", 1.34, datetime(2019-01-01 10:10:10),
    "C", 0.13, datetime(2019-01-01 12:12:12),
    "A", 12.4, datetime(2019-02-01 11:11:11),
    "B", 1.24, datetime(2019-02-01 09:09:09),
    "B", 2.24, datetime(2019-02-01 09:10:09),
    "B", 3.24, datetime(2019-02-01 09:11:09),
    "C", 0.12, datetime(2019-02-01 08:08:08),
    "A", 14.4, datetime(2019-03-01 07:07:07),
    "B", 1.44, datetime(2019-03-01 05:05:05),
    "C", 0.14, datetime(2019-03-01 06:06:06),
]
| summarize Month1 = sumif(Runtime, TimeGenerated between(datetime(2019-01-01)..datetime(2019-02-01))),
            Month2 = sumif(Runtime, TimeGenerated between(datetime(2019-02-01)..datetime(2019-03-01))),
            Month3 = sumif(Runtime, TimeGenerated between(datetime(2019-03-01)..datetime(2019-04-01))) 
         by Resource
 类似资料:
  • 在运行.NET Core3.1控制台应用程序时,我正在尝试获取应用程序的见解,以便在azure批处理作业/任务中工作。 https://docs.microsoft.com/en-us/Azure/Batch/Monitor-Application-Insights https://docs.microsoft.com/en-us/Azure/Azure-monitor/app/worker-se

  • 有没有人有关于如何将Azure应用程序洞察集成到作为控制台应用程序构建的Azure WebJob的示例或文章的链接?

  • 我想通过创建遥测初始化器为azure函数定制application insight配置。我当前的工作范围是确定一种方法,将从HTTP触发的azure函数发送的消息与另一个HTTP触发的azure函数相关联,为此,我试图遵循dzimchuk.net上的帮助。但是,我在我的azure函数项目中没有看到ApplicationInsights.config。我找到了包含app insight配置文件的Gi

  • 我怎么能看到它?在portal中,我发现了一个选项,可以看到会话计数,但不是持续时间。

  • 我们有一堆azure函数记录执行上下文的度量...您似乎无法使用OOTB或(至少在我所看到的情况下)来完成此操作,因为没有一个与我假设的名称为的等价物。 所以..此url(https://docs.microsoft.com/en-us/Azure/azure-functions/functions-monitoring#custom-telemetry-in-c-functions)显示了利用A

  • 我们正在设计一个应用程序,它将托管在AKS(Azure kubernetes service)上。应用程序将由一组用asp.NET内核编写的服务组成,这些服务运行在docker容器中。我希望监视服务以及容器/节点,并在整个集群中具有可观察性。Azure monitor for containers似乎是监视容器、节点和整个集群的一个很好的解决方案,但我需要asp.NET核心服务的应用程序insig