myscripts
#!/bin/bash
## System monitoring
mymonitor () {
# Vars
declare -a allhosts=("mc1" "mc2" "mc11" "gm1" "gm2" "gm3" "gm4" "gm5" "gm6" "gm7" "gm8" "mem" "pre")
declare -a nas1=("nas1")
# Show global info
for i in "${allhosts[@]}"
do
echo "##### $i #####"
echo "CPU: $(ssh root@$i grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}')"
echo "RAM: $(ssh root@$i free -m | awk 'NR==2{printf "%s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }')"
echo "HDD: $(ssh root@$i df -h | grep "/$")"
echo "UPTIME: $(ssh root@$i uptime)"
echo ""
done
# Show nas1 info
for i in "${nas1[@]}"
do
echo "##### $i #####"
echo "CPU: $(ssh -p12345 root@$i vmstat | awk 'NR==3 {print $(NF-2)" "$(NF-1)" "$(NF)}')"
echo "RAM: $(ssh -p12345 root@$i top | grep Mem)"
echo "HDD: $(ssh -p12345 root@$i df -h | grep "/$")"
echo "UPTIME: $(ssh -p12345 root@$i uptime)"
echo ""
done
echo "##### BACKUP NAS1#####"
ssh -p12345 root@nas1 tail -16 rsync.log | grep "Number of files"
ssh -p12345 root@nas1 tail -16 rsync.log | grep "Number of created files"
ssh -p12345 root@nas1 tail -16 rsync.log | grep "Total file size"
ssh -p12345 root@nas1 tail -16 rsync.log | grep "Total transferred file size"
ssh -p12345 root@nas1 tail -16 rsync.log | grep "sent "
ssh -p12345 root@nas1 tail -16 rsync.log | grep "rsync error"
echo ""
# Show gluster info
echo "TAMAÑO VOLUMEN GLUSTER: $(ssh root@mc11 df -h | grep /mnt/altafonte)"
echo "##### GLUSTER VOLUME STATUS ALTAFONTE #####"
ssh root@gm1 gluster volume status altafonte
echo "##### GLUSTER VOLUME STATUS ALTAFONTE #####"
ssh root@gm1 gluster volume info all
}
myinfodisk () {
declare -a hosts=("gm1" "gm2" "gm3" "gm4" "gm5" "gm6" "gm7" "gm8")
# Show disk info
for i in "${hosts[@]}"
do
echo "##### $i #####"
#echo "$(ssh root@$i lshw -class disk)"
echo "$(ssh root@$i df -Th)"
echo ""
done
}
# myping <ip_target>
myping () {
while true; do echo $(date && ping -c 1 $1 | grep "64 bytes from") >>/$PWD/logs/$(date '+%Y%m%d')_myping_$1.log; sleep 300; done;
}