-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh-getstats
More file actions
executable file
·67 lines (57 loc) · 1.77 KB
/
ssh-getstats
File metadata and controls
executable file
·67 lines (57 loc) · 1.77 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
#
# This script will ssh connect to the provided host using the provided account,
# or the name specified by $USER, and run commands to retrieve system state
# information such as
# - The amount of RAM being used
# - The amount of Disk space being used
# - CPU utilization
print_usage(){
echo "usage: $0 [-u REMOTE_ACCOUNT_NAME] HOSTS..."
}
ACCOUNT=$USER
while getopts ":u:" args; do
case "${args}" in
u)
ACCOUNT=${OPTARG}
;;
esac
done
# If we got an option, shift past it
shift $((OPTIND-1))
HOSTS=(${@})
echo "Using remote account name $ACCOUNT."
for h in "${HOSTS[@]}"
do
echo "Added host $h to queue."
done
if [ -z "$HOSTS" ] ; then
print_usage
echo "error: missing host argument!"
exit 1
fi
# Quoting EOF at the start prevents variable substitution before the command
# is passed to the remote. Without it, all the uname and lsb_release calls
# would be substituted with the local machine information.
for h in "${HOSTS[@]}"
do
ssh "$ACCOUNT"@$h /bin/bash << 'EOF'
printf "@%s: %s - %s (%s %s %s)\n" "$(uname -n)" "$(lsb_release -sd)" \
"$(lsb_release -sc)" "$(uname -o)" "$(uname -r)" "$(uname -m)"
uptime;
grep -ve '^$' /var/lib/update-notifier/updates-available
if [ -f /var/run/reboot-required ] ; then cat /var/run/reboot-required; fi
free -h;
df -hT -x tmpfs -x devtmpfs -x squashfs;
if which zpool > /dev/null ; then
zpool status
fi
mpstat 2 3 | perl -ne '/((^Average)|(.+CPU.+%)).+/ && print';
if which libvirtd > /dev/null ; then
if systemctl status libvirtd | grep -q "active (running)" ; then
virsh -c qemu:///system list --all
fi
fi
EOF
done
exit $?