Skip to content

Instantly share code, notes, and snippets.

@yrsdi
Forked from azhargiri/io-monitor.sh
Created September 20, 2019 06:16
Show Gist options
  • Select an option

  • Save yrsdi/ebe6032cfb47d93923f1e37155190b86 to your computer and use it in GitHub Desktop.

Select an option

Save yrsdi/ebe6032cfb47d93923f1e37155190b86 to your computer and use it in GitHub Desktop.
Simple script to dump iostat command to CSV file
#!/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