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

How to implement the shell script to get disk IO and system load Load

2025-01-18 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 the access to disk IO and system load Load shell script, 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.

1. Extract system load information

The code is as follows:

#! / bin/sh

Host=$ (hostname)

Channel=$ (hostname | sed's / [0-9] / / g')

Runday=$ (date +% Y-%m-%d)

IPhost=$ (/ sbin/ifconfig | grep 'inet addr:' | grep-v' 127.0.0.1'| cut-d:-f2 | awk'{print $1}')

I, 1

While [$I-le 120]; do

Rundaytime=$ (date "+% Y-%m-%d% H:%M:%S")

/ bin/cat / proc/loadavg | awk-F "'{print"'"$rundaytime", "$1", "$2", "$3", "$4", "$5}'> > / tmp/$ (hostname)-${runday} load.txt

/ usr/bin/sar-u 1 1 | grep-v Average | / bin/sed-n'4 awk-F "'{print"'"$rundaytime"'"," $4 "," $6 "," $7 "," $9}'> > / tmp/$ (hostname)-${runday} sar.txt

ITunes $((iTun1))

Sleep 59

Done

Awk-F "," {print "" $host "," $channel "," $IPhost "," $1 "," $2 "," $3 "," $4 "," $5}'/ tmp/$ (hostname)-${runday} sar.txt > / tmp/$ (hostname) ${runday} sar.txt

Awk-F "," {print "" $host "," $channel "," $IPhost "," $1 "," $2 "," $3 "," $4 "," $5 "," $6}'/ tmp/$ (hostname)-${runday} load.txt > / tmp/$ (hostname) ${runday} load.txt

Rm-rf / tmp/$ (hostname)-${runday} sar.txt

Rm-rf / tmp/$ (hostname)-${runday} load.txt

2, Code 2

The code is as follows:

#! / bin/sh

PDIR=/monitor/nagios/shell/sarlog

Runday=$ (date +% Y-%m-%d)

TmpDir=/monitor/nagios/tmp

For i in `/ bin/cat / monitor/nagios/shell/sarlog/ machine.lst`

Do

/ usr/bin/scp ${PDIR} / sarlog.sh ${I}: / root & & / usr/bin/rsh ${I} / root/sarlog.sh &

Done

3, Code 3

The code is as follows:

#! / bin/sh

PDIR=/monitor/nagios/shell/sarlog

Runday=$ (date +% Y-%m-%d)

TmpDir=/monitor/nagios/shell/sarlog/log

Machinelst=/monitor/nagios/shell/sarlog/machine.lst

For i in `/ bin/cat / monitor/nagios/shell/sarlog/ machine.lst`

Do

/ usr/bin/scp ${I}: / tmp/*$ {runday} sar.txt ${TmpDir}

/ usr/bin/scp ${I}: / tmp/*$ {runday} load.txt ${TmpDir}

Done

/ bin/cat ${TmpDir} / * ${runday} sar.txt > > ${TmpDir} / Tmp$ {runday} .txt

/ bin/cat ${TmpDir} / * ${runday} load.txt > > ${TmpDir} / ${runday} loadResult.txt

Count=1

Line=$ (cat ${TmpDir} / Tmp$ {runday} .txt | wc-l)

> ${TmpDir} / Result$ {runday} .txt

While ["$count"-le "$Line"]

Do

Idle=$ (sed-n "${count} p" ${TmpDir} / Tmp$ {runday} .txt | awk-F ","'{print $8}')

Busy= `echo "scale=2;100-$Idle" | bc`

Sed-n "${count} p" ${TmpDir} / Tmp$ {runday} .txt | sed "TmpDir @ / ${runday} sarResult.txt

Let count=count+1

Done

/ usr/local/mysql/bin/mysql-u root-D nagios-pbj7n48dM

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

Development

Wechat

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

12
Report