The following two tabs change content below.
Hi, I have written and developed this site to share my experience and ideas with other colleagues. I also started to prepare interview questions and answers for job seekers. I hope it will help you a lot.

Today we are going to discuss about the very important topic related to CPU and Memory monitoring. As we know CPU and Memory monitoring is the main items to monitor while we are doing the server monitoring.

How to monitor CPU in zabbix please visit on my previous post.

If CPU and Memory usage is exeeded from given threasold value then we are notifing the admin team with SMS/Telegram/email etc.

But now admin team need to login that server and have to check which process are consuming more CPU and Memory. and then admin will inform to the concern application team for the same.

To reduce admin team’s effort to login into server they need top 3/5 process list which are consuming more CPU/Memory in the email alert itself so they no need to login into the server.


How to get top five CPU and Memory consuming processes from zabbix using SNMP?

To achive this we have two option which we are going to discuss one by one.

  1. We have 2 OID (from hrSWRunPerfTable) for every process to get CPU and Memory consumption as given below.


But using this first option have problem suppose we have 10-12k server which we are monitoring and every                  server have approximate 100 process then if we are adding these both OID that means we are increaing items              multiply by 2.

Total process we have  = 100

After CPU(100) and Memory(100) = 100+100+100 =300 (we need only 10 more item to get top five process and we are going to create extra 190 un-necessary items this way)

If this way we are increasing the items at the end our system face big performance issue.

To avoid this such performance issue we can use second trick.

2. Achive this using run external script from SNMP and genrate custom OID and access the output in server/proxy script and pass to given item. This way we need to create only 1 items rather then 200 items.

Now let’s see how to achive this using second option.

Before to start discussion on this i am assuming you already done the server onboarding in zabbix and also SNMP is configured on this server and also you already setup the CPU & Memory items for monitoring.

1. Login to server which we are going to monitor using putty or any other tool.

2.goto under /etc/snmp/ directory.


3.Now we will use linux command to get the top 5 CPU and Memory consuming process as shown below.

ps -eo user,pid,comm,%mem,%cpu --sort=-%cpu | head -6



4.Now this comand we need to run from SNMP and will get custom OID to get this command’s output.

5.Created file and kept this above command under this file. File full content is given below:

ps -eo user,pid,comm,%mem,%cpu --sort=-%cpu | head -6

and put this file under /etc/snmp/ . Note: We can keep this file on some other location also if you want

6.Once file create give the read write permission to this file using below command

chmod 777

7. Now open the snmpd.conf from /etc/snmp/ and at the bottom of file append this below line

#Entry to map the external script in SNMP
extend 12 /etc/snmp/

Let’s descrive the use of “extend” keyword

The Net-SNMP Agent provides an extension MIB (NET-SNMP-EXTEND-MIB) that can be used to query arbitrary shell scripts. To specify the shell script to run, use the extend directive in the /etc/snmp/snmpd.conf file. Once defined, the Agent will provide the exit code and any output of the command over SNMP.

8.Once we done all these changes then please restart the SNMP process to reflact the changes. Restart snmp using below command.

service snmpd restart



9. To test this functionality use snmpwalk command we can use this OID (.

snmpwalk -v2c -c <<COMMUNITY_STRING>> <<HOSTNAME>> .



Seems that we are good to go.

Note: If we have 10-12k server we no need to worry about admin/server team can prepare a script to push this changes to all server in bulk. This is one time action only.


Now how to call this OID in zabbix so that we can get data on frontend and send it in email alert also.

As we know output of this OId is not properly format and have some extra string because zabbix history table for this value column have max size is 255 character only. So now rather then creating item from SNMP directly lets achive this using external check.

1.login to zabbix server or proxy server which you are using for this server monitoring and goto /usr/lib/zabbix/externalscript/


2.Now create file ( which will run snmpwalk and accespt two runtime parameter 1-> for hostname and 2->community-string.

3.Now give the read write permission to this file.

chmod 777

4. Put the snmpwalk command inside this file. i also used “sed” command to cut the un-necessary text from snmpwalk output.

snmpwalk -v2c -c $2 $1 . | sed 's+NET-SNMP-EXTEND-MIB::nsExtendOutputFull."12" = STRING: + +g'

$1->First parameter which will get from zabbix UI for Hostname using {HOST:NAME} macro

$2-> Second parameter which will get COMMUNITY_STRING from UI using {$SNMP_COMMUNITY} macro

lets try to run this script to pass runtime paremeter



We have done proxy part also and now last thing is to enable this on zabbix UI to create a item.

1. Open the server/host which are going to monitor and click on items as mention below.



2. Click “Create Item” and item detail form will open as shown below:


Now fill the details one by one

1.Name : TOP Utilization

2.Type : External Check (To get output from external script)


4.Host Interface : it will automatically get selected .

5.Type of Information : Character

6.Update Interval : 5m (“You can give as per your requirement”);

and other details you can mention according to requirement.

Afetr filling the item form click on “Add”



All Done and now lets wait for some time to get value from server and that send this item value to MEM and CPU alert so that server/admin team get the required details as well.



Please let me know if you need any further details for this post. How to monitor process and services please follow How to monitor Services/Processes in zabbix using SNMP?

1,576 total views, 7 views today

Leave a Reply

Your email address will not be published. Required fields are marked *