Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- PID=$$
- STARTDATE="`date +'%Y-%m-%d_%H-%M-%S'`"
- echo $PID > /var/run/dstatsdaemon.pid
- mkdir /root/backup/data/dstats/$PID
- echo "[`date`] dstats monitoring daemon starting ($PID)..." >> /root/backup/data/dstatsdaemon.log
- dstat -tcdmnrs -C 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,total --output /root/backup/data/dstats/$PID/dstats.csv 5 17280
- sed -i 1,13d /root/backup/data/dstats/$PID/dstats.csv
- echo "rip in pid, plotting!"
- echo "[`date`] dstats stoppin' 'n' plottin'... ($PID)..." >> /root/backup/data/dstatsdaemon.log
- gnuplot -e "source='/root/backup/data/dstats/$PID/dstats.csv'" -e "out='/root/backup/data/dstats/$PID/tmpplot.png'" /root/backup/scripts/dstatsplot_cpu0-7.gnuplotscript
- mv /root/backup/data/dstats/$PID/tmpplot.png /root/backup/data/dstats/$PID/plot_cpu0-7.png
- gnuplot -e "source='/root/backup/data/dstats/$PID/dstats.csv'" -e "out='/root/backup/data/dstats/$PID/tmpplot.png'" /root/backup/scripts/dstatsplot_cpu8-15.gnuplotscript
- mv /root/backup/data/dstats/$PID/tmpplot.png /root/backup/data/dstats/$PID/plot_cpu8-15.png
- gnuplot -e "source='/root/backup/data/dstats/$PID/dstats.csv'" -e "out='/root/backup/data/dstats/$PID/tmpplot.png'" /root/backup/scripts/dstatsplot_ram.gnuplotscript
- mv /root/backup/data/dstats/$PID/tmpplot.png /root/backup/data/dstats/$PID/plot_ram.png
- gnuplot -e "source='/root/backup/data/dstats/$PID/dstats.csv'" -e "out='/root/backup/data/dstats/$PID/tmpplot.png'" /root/backup/scripts/dstatsplot_hddnet.gnuplotscript
- mv /root/backup/data/dstats/$PID/tmpplot.png /root/backup/data/dstats/$PID/plot_hddnet.png
- recepient="[email protected]"
- subject="Daily report for $(hostname)"
- message="<html><head></head><body>"
- message+="<h2>Daily report of usage of system resources on $(hostname)</h2>"
- message+="<b>CPU cores 0 - 7:</b><br /> <img src='data:image/png;base64,$(base64 /root/backup/data/dstats/$PID/plot_cpu0-7.png)' /><br />"
- message+="<b>CPU cores 8 - 15:</b><br /> <img src='data:image/png;base64,$(base64 /root/backup/data/dstats/$PID/plot_cpu8-15.png)' /><br />"
- message+="<b>RAM + swap usage:</b><br /> <img src='data:image/png;base64,$(base64 /root/backup/data/dstats/$PID/plot_ram.png)' /><br />"
- message+="<b>HDD and network interfaces usage:</b><br /> <img src='data:image/png;base64,$(base64 /root/backup/data/dstats/$PID/plot_hddnet.png)' /><br />"
- message+="<br /><b>Disk usage:</b><pre style='background-color:#e8e8e8;border:1px solid #ccc;padding:10px;'>$(df -hl |head -n7)</pre>"
- message+="</body></html>"
- echo $message | mutt -e "set content_type=text/html" -e "my_hdr Reply-to: [email protected]" $recepient -s "$subject"
- mkdir /root/backup/data/dstats/$STARTDATE
- mv /root/backup/data/dstats/$PID/* /root/backup/data/dstats/$STARTDATE/
- rm -R /root/backup/data/dstats/$PID
- rm /var/run/dstatsdaemon.pid
- echo "[`date`] Plotting completed! dstats monitoring daemon stopping ($PID)..." >> /root/backup/data/dstatsdaemon.log
- exit 1
Advertisement
Add Comment
Please, Sign In to add comment