KQL查询基于Azure AVD主机池中用户的CPU和内存利用率

aiqt4smr  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(93)

整个查询由WVDConnection、Perf处理器和Perf内存这两个不同的部分组成。他们能够单独运行,但不能作为一个整体运行。我得到的错误“没有结果发现从过去24小时尝试选择另一个时间范围”。我已经将时间范围更改为30分钟,输出是相同的。查询在日志分析工作区上运行。输出示例(用户名、CPU利用率和内存利用率)我是否遗漏了什么?
查询和输出如下:enter image description here

//list all users in a hostpool
WVDConnections
| where _ResourceId =~ 'resource id of hostpool'

//CPU and memory utilization
Perf
    | where ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total"
    | summarize CPUUtilization = avg(CounterValue) by TimeGenerated
) on TimeGenerated
| join kind=inner (
    Perf
    | where ObjectName == "Memory" and CounterName == "Available MBytes"
    | summarize MemoryUtilization = avg(CounterValue) by TimeGenerated
) on TimeGenerated
| project TimeGenerated, CPUUtilization, MemoryUtilization

//The whole query after joining both altogether
WVDConnections
| where _ResourceId =~ 'resource id of hostpool'
| project CorrelationId, State, TimeGenerated, UserName
| summarize TimeGenerated=min(TimeGenerated) by CorrelationId, State, UserName
| join kind=inner (
    Perf
    | where ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total"
    | summarize CPUUtilization = avg(CounterValue) by TimeGenerated
) on TimeGenerated
| join kind=inner (
    Perf
    | where ObjectName == "Memory" and CounterName == "Available MBytes"
    | summarize MemoryUtilization = avg(CounterValue) by TimeGenerated
) on TimeGenerated
| project TimeGenerated, UserName, CPUUtilization, MemoryUtilization
c2e8gylq

c2e8gylq1#

整个查询由WVDConnection、Perf处理器和Perf内存这两个不同的部分组成。他们能够单独运行,但不能作为一个整体运行。
您可以使用下面的KQL查询在单个查询中获得ProcessorMemory结果。

第一种方式:

Perf
| where (ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total")
    or (ObjectName == "Memory" and CounterName == "Available MBytes")
| summarize avg(CounterValue) by TimeGenerated, ObjectName, CounterName, InstanceName
| project TimeGenerated, ObjectName, CounterName, InstanceName, CounterValue = avg_CounterValue

输出:

第二种方法:

我使用了join运算符来合并基于TimeGenerated列的ProcessorDataMemoryData表。

let ProcessorData = Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total"
| summarize CPUUtilization = avg(CounterValue) by TimeGenerated;
let MemoryData = Perf
| where ObjectName == "Memory" and CounterName == "Available MBytes"
| summarize MemoryUtilization = avg(CounterValue) by TimeGenerated;
ProcessorData
| join kind=inner MemoryData on TimeGenerated
| project TimeGenerated, CPUUtilization, MemoryUtilization;

输出:

相关问题