first commit
This commit is contained in:
42
scripts/mon_io
Executable file
42
scripts/mon_io
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
export LANG=en_US.UTF-8
|
||||
LOG_PATH="/var/log/monitor"
|
||||
LOG_NAME="io"
|
||||
SAR_INTERVAL=20
|
||||
SAR_COUNT=6
|
||||
|
||||
function Init {
|
||||
local self_count=$(pgrep -cx "$(basename $0)")
|
||||
[ 0 -eq $? ] || exit 1
|
||||
[ 1 -eq $self_count ] || exit 1
|
||||
type sar > /dev/null || exit 1
|
||||
mkdir -p $LOG_PATH || exit 1
|
||||
}
|
||||
|
||||
function Log {
|
||||
local msg="$1"
|
||||
local log_time="$(date +'%F %T')"
|
||||
local log_file="$LOG_PATH/$LOG_NAME-${log_time% *}.log"
|
||||
echo "$log_time $msg" >> $log_file
|
||||
cd $LOG_PATH && ls ${LOG_NAME}-* 2>/dev/null \
|
||||
| head -n -7 | xargs rm -f
|
||||
}
|
||||
|
||||
function GetIOInfo {
|
||||
sar -dp $SAR_INTERVAL $SAR_COUNT | grep '^Average' \
|
||||
| tail -n +2 \
|
||||
| awk '{print $2,$3,-$4/2,$5/2,$8,$10}'
|
||||
}
|
||||
|
||||
function Main {
|
||||
local line=
|
||||
GetIOInfo | while read line; do
|
||||
Log "$line"
|
||||
done
|
||||
}
|
||||
|
||||
# start
|
||||
Init
|
||||
Main
|
||||
|
Reference in New Issue
Block a user