In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how shell implements monitoring CPU scripts. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
In the process of operation and maintenance, we sometimes need to optimize the CPU, when to optimize it? Naturally, there is a time when something goes wrong, so when will it go wrong? You can use our shell script for this problem.
Principle: by monitoring the use of CPU for a period of time, find out the process that has occupied CPU for a long time and optimize it, so as to improve the efficiency of CPU.
Let's start by writing a script that monitors CPU and calculates CPU usage within an hour:
#! / bin/bashSECS=3600UNIT_TIME=60STEPS=$ (($SECS / $UNIT_TIME)) echo Watching CPU usage... ; for (/ tmp/cpu_usage.$$ sleep $UNIT_TIMEdoneechoecho CPU eaters: cat / tmp/cpu_usage.$$ |\ awk'{process [$1] + = $2;} 'END {for (i in process) {printf ("%-20s% s\ n", iMagin process [I]);}' | sort-nrk 2 | headrm / tmp/cpu_usage.$$
If you are used to writing python, when you write shell scripts, you will find that shell scripts are more obscure, while python is different, simple and easy to understand.
The residents of the planet with knowledge before asked: what can shell be used for? it seems that I still don't know what to write after learning.
In addition to this script, shell can also write a number of administrative scripts here to illustrate several directions:
Zoom and format conversion of image file
Use shell to read mysql database
User management
Check for disk and file system errors
Monitoring user login to prevent hacker intrusion
Build a firewall
Write picture loader and download tool
Track website changes, etc.
In fact, sometimes you don't have to be superstitious about python. Most of the time you think python is good and shell is bad. It's because our ability to write shell scripts is too poor.
Of course, there are some things python can do, but shell can't. We'll discuss the beauty of python later.
This is the end of the article on "how to monitor the CPU script in shell". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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: 229
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.