linux - How can I check the last 5 min overall cpu usage using SAR -
i know example of sar sar -u 1 3
gives statistics next 3 seconds 1 second interval .
however sar keeps on collecting information in background (my cron set collect stats every minute ) . there way can query using sar command tell last 5 mins statistics , average .
right using following below command
interval=5; sar -f /var/log/sysstat/sa22 | tail -n $interval | head -n -1 | awk '{print $4+$6}'| awk '{s+=$1} end {print s/$interval}'
to check overall cpu usage in last 5 min .
is there better way ?
unfortunately when using -f option in sar interval , count doesn't return average value given interval (as expect). instead returns first recorded value in sar file
the way work around use -s option allows specify time @ start sampling period. i've provided perl script below finishes call sar constructed in way return you're looking for.
hope helps.
peter rhodes.
#!/usr/bin/perl $interval = 300; # seconds. $epoch = `date +%s`; $epoch -= $interval; $time = `date -d \@$epoch +%h:%m:00`; $dom = `date +%d`; chomp($time,$dom); system("sar -f /var/log/sysstat/sa$dom -b -s $time 300 1");
Comments
Post a Comment