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

Using shell to monitor cpu, disk and memory utilization

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Use shell to monitor cpu, disk and memory utilization, and email to notify when the alarm threshold is reached

And cooperate with the task plan, the alarm information can be obtained in time.

#! / bin/bash###Author: Liuzhengwei-1135960569@qq.com#QQ:1135960569#Last modified: 2017-04-19 21:50#Filename: jiankong.sh#Description: # # # obtain cpu utilization cpuUsage= `top-n 1 | awk-F'[%] +''NR==3 {print $2}' `# obtain disk utilization data_name= "/ dev/vda1" diskUsage= `df-h | grep $data_name | awk-F'[%] +'{print $5} '`logFile=/tmp/jiankong.log# obtain memory mem_total= `free-m | awk-F' [:] +'' NR==2 {print $2} '`mem_used= `free-m | awk-F' [:] + 'NR==3 {print $3}' `# Statistics memory usage mem_used_persent= `awk 'BEGIN {printf ".0f\ n" ('$mem_used'/'$mem_total') * 100}'`# get the alarm time now_time= `date'+% F% T'` function send_mail () {mail-s "monitoring alarm" 1135960569@qq.com

< /tmp/jiankong.log}function check(){ if [[ "$cpuUsage" >

80]] | | [["$diskUsage" > 80]] | | [["$mem_used_persent" > 80]] Then echo "alarm time: ${now_time}" > $logFile echo "CPU utilization: ${cpuUsage}%-- > disk utilization: ${diskUsage}%-- > memory utilization: ${mem_used_persent}%" > $logFile send_mail fi} function main () {check} main

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

Network Security

Wechat

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

12
Report