Get the App
SLTechnology News&Howtos  ›  Servers  › 

What are the commonly used Linux operating system monitoring scripts

Shulou Source: shulou.com Published: 2022-06-01 04:14:35 10月03日 Update

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!

Tags: Monitoring system host article operating system commonly used script memory content hour space not much omni-directional most situation data more traffic status directory Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL Shulou Information Shulou Tech Info MariaDB