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

Source: Internet
Author: User
Tags cpu usage


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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.