Microsoft Azure – 单个表格图表中 Azure VM 的 CPU 和内存利用率
在本文中,您将了解如何使用 Azure 日志查询同时分析 Azure 虚拟机的 CPU 利用率和内存利用率性能。这些 KQL 查询将帮助您以表格图表的形式了解所有 Azure VM 性能,这也将允许您将数据导出到 CSV 文件中。
使用这些数据,您可以轻松分析哪些服务器需要调整大小以扩大(增加大小)或缩小(减小大小)。
使用这些 KQL 查询的优点:
- 您可以在几秒钟内分析虚拟机。
- 轻松过滤虚拟机
- 使用条件轻松过滤日志数据。
- 易于分析时间范围之间的性能(例如 7 天、15 天、2 个月、2 小时、12 小时等)
- 允许我们以 CSV 格式导出数据,以供将来参考过去的表现。
执行:
步骤 1:登录到 Azure 门户。
步骤 2:转到Log Analytics 工作区>> 从左侧菜单导航到常规部分 >> 选择日志
粘贴以下 KQL 查询以在单个表图表中获取合并的 CPU 和内存利用率
VM CPU 使用率和内存使用率——在所有计算机上按操作系统类型等于选择范围中的“Windows/Linux”
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total"
| where Computer in ((Heartbeat | where OSType == "Linux" or OSType == "Windows" | distinct Computer))
| summarize MIN_CPU = min(CounterValue), AVG_CPU = avg(CounterValue), MAX_CPU = max(CounterValue) by Computer
| join
(
Perf
| where ObjectName == "Memory"
| where CounterName == "% Used Memory" or CounterName == "% Committed Bytes In Use"
| summarize MIN_MEM = min(CounterValue), AVG_MEM = avg(CounterValue), MAX_MEM = max(CounterValue) by Computer
) on Computer
| project Computer, MIN_CPU, AVG_CPU, MAX_CPU, MIN_MEM, AVG_MEM, MAX_MEM
输出:
注意:您可以通过单击导出以 CSV 的形式下载表格数据
示例 1:根据平均 CPU 利用率大于 50% 过滤解决方案
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total"
| where Computer in ((Heartbeat | where OSType == "Linux" or OSType == "Windows" | distinct Computer))
| summarize MIN_CPU = min(CounterValue), AVG_CPU = avg(CounterValue), MAX_CPU = max(CounterValue) by Computer
| join
(
Perf
| where ObjectName == "Memory"
| where CounterName == "% Used Memory" or CounterName == "% Committed Bytes In Use"
| summarize MIN_MEM = min(CounterValue), AVG_MEM = avg(CounterValue), MAX_MEM = max(CounterValue) by Computer
) on Computer
| project Computer, MIN_CPU, AVG_CPU, MAX_CPU, MIN_MEM, AVG_MEM, MAX_MEM
| where AVG_CPU > 50
输出:
示例 2:根据平均 CPU 利用率大于 50% 和平均内存利用率大于 50% 过滤解决方案。当我们在查询中使用and时,条件应该同时满足这两个条件。
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total"
| where Computer in ((Heartbeat | where OSType == "Linux" or OSType == "Windows" | distinct Computer))
| summarize MIN_CPU = min(CounterValue), AVG_CPU = avg(CounterValue), MAX_CPU = max(CounterValue) by Computer
| join
(
Perf
| where ObjectName == "Memory"
| where CounterName == "% Used Memory" or CounterName == "% Committed Bytes In Use"
| summarize MIN_MEM = min(CounterValue), AVG_MEM = avg(CounterValue), MAX_MEM = max(CounterValue) by Computer
) on Computer
| project Computer, MIN_CPU, AVG_CPU, MAX_CPU, MIN_MEM, AVG_MEM, MAX_MEM
| where AVG_CPU > 50 and AVG_MEM > 50
输出: