top_process_utilization
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.
    hrSWRunPerfTable 1.3.6.1.2.1.25.5.1
     hrSWRunPerfEntry 1.3.6.1.2.1.25.5.1.1
     hrSWRunPerfCPU 1.3.6.1.2.1.25.5.1.1.1
     hrSWRunPerfMem 1.3.6.1.2.1.25.5.1.1.2

 

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.

under_etc_snmp

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

Output:

ps_command_output

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

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

#!/bin/sh
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 util.sh

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/uti1.sh

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

restart_snmp_service

 

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

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

snmp_output

 

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/

proxy_folder

2.Now create file (topprocess.sh) 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 topprocess.sh

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 .1.3.6.1.4.1.8072.1.3.2.3.1.2 | 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

proxy_script_output

 

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.

open_host_details

 

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

item_details_form

Now fill the details one by one

1.Name : TOP Utilization

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

3.Key : topprocess.sh[{HOST.HOST},{$SNMP_COMMUNITY}]

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”

item_details_form_fill
item_details_form_fill

 

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.

top_utilization_item_output

 

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?

126 total views, 1 views today

Leave a Reply

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