-
Notifications
You must be signed in to change notification settings - Fork 0
/
mon_debian.sh
executable file
·32 lines (28 loc) · 1.21 KB
/
mon_debian.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
# Only for localhost purposes only i.e. the script should be in the host which needs monitoring
INSTALL_CMD='sudo apt install -y';
PKG_LIST='htop sysstat iftop tmux';
ACTIVE_INTERFACE=$(route | grep '^default' | grep -o '[^ ]*$')
function install_packages() {
echo "INFO: Installing packages";
$INSTALL_CMD $PKG_LIST;
}
function main {
echo "INFO: Starting preparation";
echo "INFO: The following packages will be installed";
echo "INFO: htop(cpu usage), sysstat(iostat for io usage), iftop(network usage) and tmux for UI";
echo "Please press enter to continue or Ctrl+c to abort";
read n;
install_packages;
echo "INFO: Launching tumx";
# -s <name of the session>,
# -d <shell_command>
# panes are numbered from 0
cmd="tmux new-session -s linmon -d htop \; split-window -d 'watch -n1 iostat'\; select-pane -t1 \; split-window -dh 'sudo iftop -i $ACTIVE_INTERFACE' \; split-window -d 'bash -c \"echo Press enter to end monitoring; read n; tmux kill-session -t linmon\"' \; select-pane -t2";
echo "INFO: executing: $cmd";
echo $cmd | bash
echo "INFO: Press enter to attach or Ctrl+c to stay detached";
read n;
tmux attach -t linmon
}
main $*;