Tim Buckley | a83e90b | 2015-08-05 10:25:00 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # **tools/dstat.sh** - Execute instances of DStat to log system load info |
| 4 | # |
| 5 | # Multiple instances of DStat are executed in order to take advantage of |
| 6 | # incompatible features, particularly CSV output and the "top-cpu-adv" and |
| 7 | # "top-io-adv" flags. |
| 8 | # |
| 9 | # Assumes: |
| 10 | # - dstat command is installed |
| 11 | |
youri jeong | f68f6f2 | 2017-04-12 19:23:40 +0900 | [diff] [blame] | 12 | # Retrieve log directory as argument from calling script. |
Tim Buckley | a83e90b | 2015-08-05 10:25:00 -0600 | [diff] [blame] | 13 | LOGDIR=$1 |
| 14 | |
Ian Wienand | 1124a05 | 2019-02-11 13:35:43 +1100 | [diff] [blame] | 15 | DSTAT_TOP_OPTS="--top-cpu-adv --top-io-adv --top-mem" |
| 16 | if dstat --version | grep -q 'pcp-dstat' ; then |
| 17 | # dstat is unmaintained, and moving to a plugin of performance |
| 18 | # co-pilot. Fedora 29 for example has rolled this out. It's |
| 19 | # mostly compatible, except for a few options which are not |
| 20 | # implemented (yet?) |
| 21 | DSTAT_TOP_OPTS="" |
| 22 | fi |
| 23 | |
Tim Buckley | a83e90b | 2015-08-05 10:25:00 -0600 | [diff] [blame] | 24 | # Command line arguments for primary DStat process. |
Ian Wienand | 1124a05 | 2019-02-11 13:35:43 +1100 | [diff] [blame] | 25 | DSTAT_OPTS="-tcmndrylpg ${DSTAT_TOP_OPTS} --swap --tcp" |
Tim Buckley | a83e90b | 2015-08-05 10:25:00 -0600 | [diff] [blame] | 26 | |
| 27 | # Command-line arguments for secondary background DStat process. |
melanie witt | fc572a5 | 2017-05-16 23:04:46 +0000 | [diff] [blame] | 28 | DSTAT_CSV_OPTS="-tcmndrylpg --tcp --output $LOGDIR/dstat-csv.log" |
Tim Buckley | a83e90b | 2015-08-05 10:25:00 -0600 | [diff] [blame] | 29 | |
| 30 | # Execute and background the secondary dstat process and discard its output. |
| 31 | dstat $DSTAT_CSV_OPTS >& /dev/null & |
| 32 | |
| 33 | # Execute and background the primary dstat process, but keep its output in this |
| 34 | # TTY. |
| 35 | dstat $DSTAT_OPTS & |
| 36 | |
| 37 | # Catch any exit signals, making sure to also terminate any child processes. |
| 38 | trap "kill -- -$$" EXIT |
| 39 | |
| 40 | # Keep this script running as long as child dstat processes are alive. |
| 41 | wait |