In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to achieve statistics of cpu memory and utilization of shell script code, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The code is as follows:
#! / bin/sh
Clear
While ((1 > 0))
Do
NET=$ (netstat-anp | grep 1000 | grep EST | wc-l)
PRC=$ (ps aux | grep thread1 | grep-v grep | grep-v SCREEN | awk'{print "CPU:" $3 "%, MEM:" $4 "%, RSS:" $6max 1024 "M, VSZ:" $5pm 1024 "M, PID:" $2 ""}')
Tput sc; echo-n-e "\ b"; tput rc
Echo "SRV: thread1, NET: $NET, $PRC"
Echo ""
NET=$ (netstat-anp | grep 1011 | grep EST | wc-l)
PRC=$ (ps aux | grep thread2 | grep-v grep | grep-v SCREEN | awk'{print "CPU:" $3 "%, MEM:" $4 "%, RSS:" $6max 1024 "M, VSZ:" $5pm 1024 "M, PID:" $2 ""}')
Tput sc; echo-n-e "\ b"; tput rc
Echo "SRV: thread2, NET: $NET, $PRC"
Echo ""
NET=$ (netstat-anp | grep 1022 | grep EST | wc-l)
PRC=$ (ps aux | grep thread3 | grep-v grep | grep-v SCREEN | awk'{print "CPU:" $3 "%, MEM:" $4 "%, RSS:" $6max 1024 "M, VSZ:" $5pm 1024 "M, PID:" $2 ""}')
Tput sc; echo-n-e "\ b"; tput rc
Echo "SRV: thread3, NET: $NET, $PRC"
Echo ""
NET=$ (netstat-anp | grep 1033 | grep EST | wc-l)
PRC=$ (ps aux | grep thread4 | grep-v grep | grep-v SCREEN | awk'{print "CPU:" $3 "%, MEM:" $4 "%, RSS:" $6max 1024 "M, VSZ:" $5pm 1024 "M, PID:" $2 ""}')
Tput sc; echo-n-e "\ b"; tput rc
Echo "SRV: thread4, NET: $NET, $PRC"
Echo ""
NET=$ (netstat-anp | grep beam.smp | grep EST | grep 222.222.18.222 NET=$ 800 | wc-l)
PRC=$ (ps aux | grep thread | grep-v grep | awk'{CPU + = $3} {RSS + = $6} {VSZ + = $5} END {print "CPU:" CPU "%, MEM:" MEM "%, RSS:" RSS/1024 "M, VSZ:" VSZ/1024 "M,"}'| awk 'END {print}')
Tput sc; echo-n-e "\ b"; tput rc
Echo "SRV: All, NET: $NET, $PRC"
Echo ""
Sleep 0.5
Tput cup 0 0
Done
Thank you for reading this article carefully. I hope the article "how to realize the shell script code for counting cpu memory and usage" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
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.