Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Nagios monitors the resource consumption of the program

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "Nagios how to monitor the program occupies resources", the content is easy to understand, clear, hope to help you solve the doubt, the following let the editor lead you to study and learn "how to monitor the program occupies resources" this article.

1. Shell script requirement analysis:

The threshold of cpu,mem can be set, and the alarm will be given if the resource occupancy exceeds the threshold.

To be able to determine whether this process exists, if one does not exist, call the police.

2. The execution effect of shell script is as follows:

1. If the input format is incorrect, output help information

[root@center230 libexec] # shcomponent_resource.sh

Usage parament:

Component_resource.sh [--cpu] [--mem]

Example:

Component_resource.sh-- cpu 50-- mem 50

2. If the threshold is not exceeded, the output resource usage is 0.

[root@center230 libexec] # shcomponent_resource.sh-- cpu 50-- mem 50

VueSERVER_cpu_use=5.6% VueCache_cpu_use=1.9%VueAgent_cpu_use=0.0% VueCenter_cpu_use=0.0% VueDaemon_cpu_use=0.0%;VueSERVER_mem_use=0.2% VueCache_mem_use=7.4% VueAgent_mem_use=0.5% VueCenter_mem_use=0.1%VueDaemon_mem_use=0.0%

[root@center230 libexec] # echo $?

0

3. If the threshold is exceeded, the output resource usage will be 2.

[root@center230 libexec] # shcomponent_resource.sh-cpu 5-mem 5

VueSERVER_cpu_use=9.4% VueCache_cpu_use=0.0%VueAgent_cpu_use=0.0% VueCenter_cpu_use=0.0% VueDaemon_cpu_use=0.0%;VueSERVER_mem_use=0.2% VueCache_mem_use=7.4% VueAgent_mem_use=0.5%VueCenter_mem_use=0.1% VueDaemon_mem_use=0.0%

[root@center230 libexec] # echo $?

two

4. If the process does not exist, output the process lost by down and the process resources in normal use. The exit value is 2.

[root@yckj scripts] # sh component_resource.sh--cpu 50-- mem 50

Current VueDaemon VueCenter VueAgent VueCache VueSERVER is down.

[root@yckj scripts] # echo $?

two

3. The code of the Shell script is as follows: [root@center230 libexec] # catenary cpu resource.VueDaemon VueCenter VueAgentVueCache VueSERVER script code is as follows: [root@center230 libexec] # VueDaemon VueCenter VueAgentVueCache VueSERVER script code is as follows: [root@center230 libexec] # VueDaemon VueCenter VueAgentVueCache VueSERVER script code is as follows: [root@center230 libexec] # VueDaemon VueCenter VueAgentVueCache VueSERVER script code is as follows: [VueDaemon VueCenter VueAgentVueCache VueSERVER VUEConnector Myswitch Slirpvde] # case script code is as follows: [catenary] # catamentum mem_crit=$2. Esac case $3 in-- cpu) cpu_crit=$4 -- mem) mem_crit=$4;; esac # determine the number of parameters passed. If the value is not 4, then the varvalue is 1 var var0, then normal # if [[$1 = = $3]]; then var=1 elif [$#-ne 4]; then var=1else var=0fi # print error message if [$var-eq 1] Then echo "Usage parament:" echo $0 [--cpu] [--mem] "echo"echo" Example: "echo" $0-- cpu 50-- mem50 "exitfi # put nonexistent processes in a variable num=$ ((${# pragrom_list [@]}-1)) NotExist="for digit in `seq 0$ num`do a = `ps-ef | grep-v grep | grep ${pragrom_list [$digit]} | wc-l`if [$a-eq 0] Then NotExist= "$NotExist ${pragrom_list [$digit]}" unset pragrom_list [$digit] fidone#echo "pragrom_list=$ {pragrom_list [@]}" # compare the resources occupied by the process with the threshold size cpu_use_all= "" mem_use_all= "" compare_cpu_temp=0compare_mem_temp=0for n in ${pragrom_list [@]} do cpu_use= `top-b-N1 | grep $n | awk'{print $9} 'mem_use= `top-b-N1 | grep $n | awk' { Print $10} '`if [[$cpu_use = = "]] Then cpu_use=0 fi if [[$mem_use= = ""]]; then mem_use=0 fi compare_cpu= `echo "$cpu_use > $cpu_crit" | bc`compare_mem= `echo "$mem_use > $mem_crit" | bc`if [[$compare_cpu= = 1]]; then compare_cpu_temp=1 fi if [[$compare_mem= = 1] Then compare_mem_temp=1 fi cpu_use_all= "${n} _ cpu_use=$ {cpu_use}% ${cpu_use_all}" mem_use_all= "${n} _ mem_use=$ {mem_use}% ${mem_use_all}" done # if this variable has a value, it means there is a process down. The exit value is 2if [["$NotExist"! = "]]; then echo-e" Current ${NotExist} isdown.$cpu_use_all;$mem_use_all "exit 2 requests # if the cpu comparison value is 1, then the process occupancy exceeds the threshold, then the exit value is 2elif [[" $compare_cpu_temp "= = 1]; then echo-e" $cpu_use_all $mem_use_all "exit 2employees # if the mem comparison value is 1, it means that the mem usage of the process exceeds the threshold, then the exit value is 2elif [[$compare_mem_temp = = 1]]; otherwise, the output is normal, and the ratio of cpu to memory else echo-e" $cpu_use_all The above $mem_use_all "exit 0fi" is all the contents of the article "how to monitor the use of resources by Nagios programs". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 231

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report