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 to make Linux shell script realize CPU early warning

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "how to make Linux shell scripts achieve CPU early warning". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

#! / bin/bash#cpu idle percentcpu_idle= `top-b-d 1-n 2 | grep Cpu | awk'NR > 1 {print $5}'| cut-f 1-d "." `if [- d "/ opt/scripts/log"] then cd / opt/scriptselse mkdir / opt/scripts/logfi count=0condition=truewhile conditiondo if [$cpu_idle-le 20] then pids= `top-b-d 1-n 1 | grep java | awk'{if ($9 > 80) print $1} '`for (a = 1; a;

< 10; a++)) do for pid in $pids doi #involve jdk existence check later date=`date +%Y%m%d%H%M` sh showstack.sh -c 30 -p $pid >

Log/stack_$pid_$date.log jstat-gcutil $pid > log/gc_$pid_$date.log done done for pid in $pids do date= `date +% Y% m% d% H% M`jmap-heap $pid > log/heap_$pid_$date.log done count++ cpu_idle= `top-b-d 1-n 2 | grep Cpu | awk'NR > 1 {print $5}'| cut-f 1-d "." `if [$count-ge 3] then # send emaili # server ip address ip= `ifconfig eth0 | grep "inet addr" | cut-f 2-d ":" | cut-f 1-d "`condition=false count=0 fi else condition=false count=0 fidone" how to make Linux shell scripts achieve CPU early warning "this is the end of the introduction. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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: 0

*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