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

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

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

  1. //list all users in a hostpool
  2. WVDConnections
  3. | where _ResourceId =~ 'resource id of hostpool'
  4. //CPU and memory utilization
  5. Perf
  6. | where ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total"
  7. | summarize CPUUtilization = avg(CounterValue) by TimeGenerated
  8. ) on TimeGenerated
  9. | join kind=inner (
  10. Perf
  11. | where ObjectName == "Memory" and CounterName == "Available MBytes"
  12. | summarize MemoryUtilization = avg(CounterValue) by TimeGenerated
  13. ) on TimeGenerated
  14. | project TimeGenerated, CPUUtilization, MemoryUtilization
  15. //The whole query after joining both altogether
  16. WVDConnections
  17. | where _ResourceId =~ 'resource id of hostpool'
  18. | project CorrelationId, State, TimeGenerated, UserName
  19. | summarize TimeGenerated=min(TimeGenerated) by CorrelationId, State, UserName
  20. | join kind=inner (
  21. Perf
  22. | where ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total"
  23. | summarize CPUUtilization = avg(CounterValue) by TimeGenerated
  24. ) on TimeGenerated
  25. | join kind=inner (
  26. Perf
  27. | where ObjectName == "Memory" and CounterName == "Available MBytes"
  28. | summarize MemoryUtilization = avg(CounterValue) by TimeGenerated
  29. ) on TimeGenerated
  30. | project TimeGenerated, UserName, CPUUtilization, MemoryUtilization
c2e8gylq

c2e8gylq1#

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

第一种方式:

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

输出:

第二种方法:

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

  1. let ProcessorData = Perf
  2. | where ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total"
  3. | summarize CPUUtilization = avg(CounterValue) by TimeGenerated;
  4. let MemoryData = Perf
  5. | where ObjectName == "Memory" and CounterName == "Available MBytes"
  6. | summarize MemoryUtilization = avg(CounterValue) by TimeGenerated;
  7. ProcessorData
  8. | join kind=inner MemoryData on TimeGenerated
  9. | project TimeGenerated, CPUUtilization, MemoryUtilization;

输出:

展开查看全部

相关问题