The premise: you want to write your own Zabbix monitoring script, and then configure the template to achieve high utilization of resources (CPU and memory) process monitoring.
Process Description:
The Zabbix version is 2.21 and the host operating system is monitored for CentOS 6.4.
The main commands in the script are as follows:
percent=0;
#Enter parameters via script
process=$1;
#通过ps the aux parameter, get the cpu% and mem% values, and use awk to filter the mem% value of line fourth
Percent=ps aux | grep $process | grep -v grep | head -1 | awk ‘{print $4}‘;
Echo $percent
Problem Description:
It is found that running the above script command in the CLI can obtain a numeric value corresponding to the utilization of the process resource.
However, the script contains the same command conditions, the execution of the script, but often obtained a value of 0.0, and only changed the script input, that is, the input process name, the script executes, the resulting value is often not 0.0, but the normal data.
Effect:
Because the DataView of the data is configured on the Zabbix Web page, the data display of DataView is inaccurate.
Workaround (Pending validation):
1. Use the built-in Zabbix variable proc.cpu.util[<name>,<user>,<type>,<cmdline>,<mode>,<zone>] and Proc.mem.util[<name>,<user>,<type>,<cmdline>,<mode>,<zone>].
2. Modify the commands in the script, using the following method instead:
First, get the PID of the process name, and then combine top to run the following command:
Top-b-n 1-p $pid 2>&1 | Awk-v pid= $pid ' {if (= = pid) print $9} '
3. Modify the commands in the script, using the following method instead:
The PID of the process name is obtained first, and then the relevant data is read from the/proc/$pid/directory for calculation.
PostScript: Not to the above three solutions to verify, but personally think or use Zabbix built-in variable configuration template for a better solution, after all, personal ability is limited, or choose to believe the professional Zabbix bar.
about using the PS command in the ZABBIX monitoring script to monitor process CPU usage and memory usage to get a description of the 0 data