ericek111

dstats monitoring daemon for Linux

Aug 30th, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.88 KB | None | 0 0
  1. #!/bin/bash
  2. PID=$$
  3. STARTDATE="`date +'%Y-%m-%d_%H-%M-%S'`"
  4.  
  5. echo $PID > /var/run/dstatsdaemon.pid
  6. mkdir /root/backup/data/dstats/$PID
  7. echo "[`date`] dstats monitoring daemon starting ($PID)..." >> /root/backup/data/dstatsdaemon.log
  8.  
  9. 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
  10. sed -i 1,13d /root/backup/data/dstats/$PID/dstats.csv
  11.  
  12. echo "rip in pid, plotting!"
  13. echo "[`date`] dstats stoppin' 'n' plottin'... ($PID)..." >> /root/backup/data/dstatsdaemon.log
  14.  
  15. 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
  16. mv /root/backup/data/dstats/$PID/tmpplot.png /root/backup/data/dstats/$PID/plot_cpu0-7.png
  17.  
  18. 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
  19. mv /root/backup/data/dstats/$PID/tmpplot.png /root/backup/data/dstats/$PID/plot_cpu8-15.png
  20.  
  21. 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
  22. mv /root/backup/data/dstats/$PID/tmpplot.png /root/backup/data/dstats/$PID/plot_ram.png
  23.  
  24. 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
  25. mv /root/backup/data/dstats/$PID/tmpplot.png /root/backup/data/dstats/$PID/plot_hddnet.png
  26.  
  27. recepient="[email protected]"
  28. subject="Daily report for $(hostname)"
  29.  
  30. message="<html><head></head><body>"
  31. message+="<h2>Daily report of usage of system resources on $(hostname)</h2>"
  32. 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 />"
  33. 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 />"
  34. message+="<b>RAM + swap usage:</b><br /> <img src='data:image/png;base64,$(base64 /root/backup/data/dstats/$PID/plot_ram.png)' /><br />"
  35. 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 />"
  36. message+="<br /><b>Disk usage:</b><pre style='background-color:#e8e8e8;border:1px solid #ccc;padding:10px;'>$(df -hl |head -n7)</pre>"
  37. message+="</body></html>"
  38.  
  39. echo $message | mutt -e "set content_type=text/html" -e "my_hdr Reply-to: [email protected]" $recepient -s "$subject"
  40.  
  41. mkdir /root/backup/data/dstats/$STARTDATE
  42. mv /root/backup/data/dstats/$PID/* /root/backup/data/dstats/$STARTDATE/
  43. rm -R /root/backup/data/dstats/$PID
  44. rm /var/run/dstatsdaemon.pid
  45.  
  46. echo "[`date`] Plotting completed! dstats monitoring daemon stopping ($PID)..." >> /root/backup/data/dstatsdaemon.log
  47. exit 1
Advertisement
Add Comment
Please, Sign In to add comment