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 monitoring scripts

2025-02-23 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 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-c7muri'

Tx_before='ifconfig eth0 | sed-n "8" p | awk'{print $6}'| cut-c7muri'

Sleep 2

Rx_after='ifconfig eth0 | sed-n "8" p | awk'{print $2}'| cut-c7muri'

Tx_after='ifconfig eth0 | sed-n "8" p | awk'{print $6}'| cut-c7muri'

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 grep 80" | wc-l`

Echo "$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 Universe% Universe'

If [$SPACE-ge 90]

Then

Jbxue123@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 &

# I/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 &

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.

If there is a problem in a certain period of time, you can look at the corresponding log information to see what the performance of the host is at that time.

The above is all the contents of the article "what are the commonly used Linux 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