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

What are the commonly used Linux operating system monitoring scripts

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Editor to share with you what the commonly used Linux operating system monitoring scripts are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1. View the traffic of the host network card

#! / bin/bash # network # Mike.Xu while: Do time='date +% m "-"% d ""% k ":"% M 'day='date +% m "-"% d' rx_before='ifconfig eth0 | sed-n "8" p | awk'{print\ $2}'| cut-c7lily 'tx_before='ifconfig eth0 | sed-n "8" p | awk' {print\ $6}'| cut-c7mura 'sleep 2 rx_after='ifconfig eth0 | sed-n "8" p | awk' {print\ $2}'| cut-c7lue 'tx_after='ifconfig eth0 | sed-n "8" P | awk'{print\ $6}'| cut-c7Musi 'rx_result=\ $[(rx_after-rx_before) / 256] tx_result=\ $[(tx_after-tx_before) / 256] echo "\ $time Now_In_Speed:"\ $rx_result "kbps Now_OUt_Speed:"\ $tx_result "kbps" sleep 2 done

2. System condition monitoring

#! / bin/sh # systemstat.sh # Mike.Xu IP=192.168.1.227 top-n 2 | grep "Cpu". / temp/cpu.txt free-m | grep "Mem". / temp/mem.txt df-k | grep "sda1". / temp/drive_sda1.txt # df-k | grep sda2 ". / temp/drive_sda2.txt df-k | grep" / mnt/storage_0 ". / temp/mnt_storage_0. Txt df-k | grep "/ mnt/storage_pic". / temp/mnt_storage_pic.txt time= `date +% m ".% d"% k": "% M`connect= `netstat-na | grep" 219.238.148.30 connect 80 "| wc-l`date"\ $time\ $connect ". / temp/connect_count.txt

3. Monitor the disk space of the host. When the disk space exceeds 90%, send a warning by sending mail.

#! / bin/bash # monitor available disk space SPACE='df | sed-n'/\ /\ $/ p' | gawk'{print\ $5}'| sed's if% if [\ $SPACE-ge 90] then fty89@163.com fi

4. Monitor the usage of CPU and memory

#! / bin/bash # script to capture system statistics OUTFILE=/home/xu/capstats.csv

DATE='date +% m _% Y'

TIME='date +% k _ v% m _ v% s'

TIMEOUT='uptime'

VMOUT='vmstat 1 2'

USERS='echo\ $TIMEOUT | gawk'{print\ $4}'

LOAD='echo\ $TIMEOUT | gawk'{print\ $9}'| sed

FREE='echo\ $VMOUT | sed-n'/ [0-9] / p'| sed-n '2p' | gawk' {print\ $4}'

IDLE='echo\ $VMOUT | sed-n'/ [0-9] / p'| sed-n '2p' | gawk' {print\ $15}'

Echo "\ $DATE,\ $TIME,\ $USERS,\ $LOAD,\ $FREE,\ $IDLE"\ $OUTFILE

5. Omni-directional monitoring of the host

#! / bin/bash # check_xu.sh # 0 * / home/check_xu.sh DAT= "`date +% Y% m% d`" HOUR= "`date +% H`" DIR= "/ home/oslog/host_\ ${DAT} /\ ${HOUR}" DELAY=60 COUNT=60 # whether the responsible directory exist if! Test-d\ {DIR} then / bin/mkdir-p\ ${DIR} fi # general check export TERM=linux / usr/bin/top-b-d\ ${DELAY}-n\ ${COUNT} >\ ${DIR} / top_\ ${DAT} .log 2 > & 1 & # cpu check / usr/bin/sar-u\ ${DELAY}\ ${COUNT} >\ ${DIR} / cpu_\ ${DAT} .log 2 > & 1 & # / usr/bin/mpstat -P 0\ ${DELAY}\ ${COUNT} >\ ${DIR} / cpu_0_\ ${DAT} .log 2 > & 1 & # / usr/bin/mpstat-P 1\ ${DELAY}\ ${COUNT} >\ ${DIR} / cpu_1_\ ${DAT} .log 2 > & 1 & # memory check / usr/bin/vmstat\ ${DELAY}\ {COUNT} >\ ${DIR} / vmstat_\ ${DAT} .log 2 > & 1 & # DELAY O check / usr/bin/iostat\ ${DELAY}\ ${COUNT} >\ ${DIR} / iostat_\ ${DAT} .log 2 > & 1 & # network check / usr/bin/sar-n DEV\ ${DELAY}\ ${COUNT} >\ ${DIR} / net_\ ${DAT} .log 2 > & 1 & # / usr/bin/sar-n EDEV\ ${DELAY}\ {COUNT} >\ ${DIR} / net_edev_\ ${DAT} .log 2 > & 1 & 1

Automatically executed hourly in crontab:

0 * / home/check_xu.sh

This will generate hourly cpu, memory, network, and IO statistics in the / home/oslog/host_yyyymmdd/hh directory.

The above is all the contents of the article "what are the commonly used Linux operating system monitoring scripts?" 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: 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

Servers

Wechat

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

12
Report