-
-
Save yrsdi/ebe6032cfb47d93923f1e37155190b86 to your computer and use it in GitHub Desktop.
Simple script to dump iostat command to CSV file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| ### | |
| ## The original code is taken from snippet https://pastebin.com/SxxuaVy4 | |
| ## Thank's to Harry Sufehmi | |
| ## | |
| ## Usage: | |
| ## Simply put in your crontab. | |
| ## Example below will run io-monitor.sh every minutes | |
| ## */1 * * * * /path/to/you/io-monitor.sh | |
| ### | |
| logfile=$HOME/.io-monitor/`date +%Y-%m-%d`.csv | |
| logdir=$(dirname $logfile) | |
| # Create directory if not exists | |
| test ! -d "$logdir" && mkdir -p "$logdir" | |
| # Capture value of %iowait | |
| # Example output of command `iostat -c` | |
| # avg-cpu: %user %nice %system %iowait %steal %idle | |
| # 29,58 0,32 5,58 3,76 0,00 60,75 | |
| if [ ! -s "$logfile" ]; then | |
| echo '"time";"%user";"%nice";"%system";"%iowait";"%steal";"%idle"' > "$logfile" | |
| fi | |
| result=`iostat -d 1 3 -c | tail -n5 | head -n1 | awk -v 's="' '{ print s$1s ";" s$2s ";" s$3s ";" s$4s ";" s$5s ";" s$6s }'` | |
| echo "\"`date +%H%M%S`\";$result" >> "$logfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment