Ad Widget

Collapse

Monitor CPU usage for specific processes on Linux

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • linuxgurugamer
    Member
    • Oct 2010
    • 66

    #1

    Monitor CPU usage for specific processes on Linux

    I had a need to monitor the cpu usage of a specific process. Actually, all processes with a specific name. I came up with the following, hopefully someone else will find this useful:

    I am using the following assumptions:

    1. Zabbix conf file is located in /etc/zabbix
    2. The process(es) being monitored is called: openvpn
    You can change openvpn to any process you want to monitor.
    3. A bin directory will be created by you in /etc/zabbix/bin
    4. A data directory will be created by you in /etc/zabbix/data, and the group/ownership will be changed to the Zabbix user.


    There are two files attached to this message. One is a C program called clean.c. Save it, and compile it using:

    cc clean.c -o clean

    The second file is a shell script, save it and rename it to

    getproctime.sh

    The script makes the assumption that it and the C program will be installed on the client in:

    /etc/zabbix/bin

    On the client, add the following line to /etc/zabbix_agentd:

    UserParameter=openvpn.cpu,/etc/zabbix/bin/getproctime.sh openvpn

    and restart the agent. I did it this way because I was unable to get the system.run() working on Linux.

    On the server, create an Item to monitor the usage. Add the following for the key:

    openvpn.cpu

    Set the update interval to 5, and if possible, make it an agent. If you like, you can add a percent sign to the Units field. I am using this as an active agent.

    Save it, and watch the monitoring. I use this as a standard agent, I haven't had luck yet with the active agent.
    Attached Files
  • Zaniwoop
    Senior Member
    • Jan 2010
    • 232

    #2
    you might want to look at http://www.zabbix.com/forum/showthre...ht=CPU+Process

    Comment

    • tof233
      Member
      • Nov 2010
      • 94

      #3
      Thank you Linuxgurugamer for this script.

      I was just trying to developp my own script to get process cpu usage and was blocked by the fact that "ps -o pcpu ... "return cpu usage since the process started and "top -n 1 -p pid1,pid2..." is limited to 20 pids.

      However I noticed in your script:
      Code:
      # This shell-script watch that <process> doesn't pass the <limit> of % cpu usage
      # If it does, the script kills that process and finish
      and did not find where your script would kill it (However, I don't need this functionality).

      Comment

      Working...