zabbix 6.0 监控cpu,内存使用率前10的应用程序

新增脚本

CPU 使用率脚本 (top_cpu.ps1):

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Get-Process | 
    Sort-Object -Property CPU -Descending | 
    Select-Object -First 10 Name, 
        @{Name='CPU (Seconds)'; Expression={$_.CPU}} | 
    Format-Table -AutoSize | 
    Out-String

内存使用率脚本 (top_memory.ps1):

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Get-Process | 
    Sort-Object -Property WS -Descending | 
    Select-Object -First 10 Name, 
        @{Name='WS (Bytes)'; Expression={$_.WS}} | 
    Format-Table -AutoSize | 
    Out-String

我将这俩脚本放在agent的目录下

紧接着配置zabbix_agent2.conf

找到UserParameter,放开注释并将这两项配置进去

UserParameter=custom.cpu.top.processes,powershell.exe -NoProfile -ExecutionPolicy Bypass -File "D:\Program Files\Zabbix Agent 2\top_cpu.ps1"

UserParameter=custom.memory.top.processes,powershell.exe -NoProfile -ExecutionPolicy Bypass -File "D:\Program Files\Zabbix Agent 2\top_memory.ps1"

调试脚本

按下 Windows 键,然后输入 PowerShell

在搜索结果中找到 Windows PowerShell,右键选择“以管理员身份运行”

在打开的 PowerShell 窗口中,使用 cd 命令切换到你的脚本所在的目录

cd 'D:\Program Files\Zabbix Agent 2'

然后运行脚本:

.\top_cpu.ps1

如果报上图这个错,错误信息是关于 PowerShell 的执行策略问题。PowerShell 的执行策略决定了哪些 PowerShell 脚本可以在系统上运行,以及如何运行它们。错误信息指出你的系统阻止了脚本的执行,因为它没有被标记为“受信任”

改执行策略以允许脚本运行,可以使用以下命令:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

再次运行

此时重启agent就行

Web页面中添加监控以及视图

添加监控项,确保键值正确,类型选文本。键值是刚才配置UserParameter设置的键值

cpu键:custom.cpu.top.processes

内存键:custom.memory.top.processes

然后在仪表盘中添加文本类型,并关联监控项:

最终结果:

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值