aboutsummaryrefslogtreecommitdiff
path: root/articles/2011-03-31_sheevaplug_ueberwachung.md
diff options
context:
space:
mode:
Diffstat (limited to 'articles/2011-03-31_sheevaplug_ueberwachung.md')
-rw-r--r--articles/2011-03-31_sheevaplug_ueberwachung.md112
1 files changed, 62 insertions, 50 deletions
diff --git a/articles/2011-03-31_sheevaplug_ueberwachung.md b/articles/2011-03-31_sheevaplug_ueberwachung.md
index 74dfa88..0cbea1c 100644
--- a/articles/2011-03-31_sheevaplug_ueberwachung.md
+++ b/articles/2011-03-31_sheevaplug_ueberwachung.md
@@ -9,7 +9,10 @@ Den Systemmonitor Conky lasse ich mit dem Befehl `ssh -X -vv -Y -p 22 adrian@ast
Zusätzlich loggt der SheevaPlug regelmäßig die aktuellen Systemdaten wie CPU-Auslastung, Netzwerkverkehr und belegten Arbeitsspeicher und generiert sie zu Graphen die mir dann jede Nacht per eMail zugesand werden.
Zum Loggen der Daten verwende ich dstat das mit folgendem, von einem Cron-Job gestarteten Befehl aufgerufen wird:
- dstat -tcmn 2 1 | tail -1 >> /var/log/systat.log
+~~~
+dstat -tcmn 2 1 | tail -1 >> /var/log/systat.log
+~~~
+{: .language-sh}
Die Argumente -tcmn geben hierbei die zu loggenden Systemdaten und deren Reihenfolge an – heraus kommen Zeilen wie diese:
@@ -17,61 +20,70 @@ Die Argumente -tcmn geben hierbei die zu loggenden Systemdaten und deren Reihenf
Um 0 Uhr wird dann die Log-Datei von einem Cron-Job mit diesem Script wegkopiert, Graphen werden von gnuplot generiert und dann mit einem kleinen Python-Programm versendet.
- #!/bin/sh
- mv /var/log/systat.log /root/sys_graph/stat.dat
- cd /root/sys_graph/
- ./generate_cpu.plot
- ./generate_memory.plot
- ./generate_network.plot
- ./send_report.py
+~~~
+#!/bin/sh
+mv /var/log/systat.log /root/sys_graph/stat.dat
+cd /root/sys_graph/
+./generate_cpu.plot
+./generate_memory.plot
+./generate_network.plot
+./send_report.py
+~~~
+{: .language-sh}
Hier das gnuplot-Script zur Erzeugung des CPU-Graphen als Beispiel:
- #!/usr/bin/gnuplot
- set terminal png
- set output "cpu.png"
- set title "CPU usage"
- set xlabel "time"
- set ylabel "percent"
- set xdata time
- set timefmt "%d-%m %H:%M:%S"
- set format x "%H:%M"
- plot "stat.dat" using 1:4 title "system" with lines, \
- "stat.dat" using 1:3 title "user" with lines, \
- "stat.dat" using 1:5 title "idle" with lines
+~~~
+#!/usr/bin/gnuplot
+set terminal png
+set output "cpu.png"
+set title "CPU usage"
+set xlabel "time"
+set ylabel "percent"
+set xdata time
+set timefmt "%d-%m %H:%M:%S"
+set format x "%H:%M"
+plot "stat.dat" using 1:4 title "system" with lines, \
+"stat.dat" using 1:3 title "user" with lines, \
+"stat.dat" using 1:5 title "idle" with lines
+~~~
+{: .language-sh}
… und hier noch das Python-Programm zum Versenden per Mail:
- #!/usr/bin/python2
- import smtplib
- from time import *
- from email.mime.image import MIMEImage
- from email.mime.multipart import MIMEMultipart
-
- lt = localtime()
-
- # Mail-Header
- msg = MIMEMultipart()
- msg['Subject'] = strftime('Leistungsreport – %d%m%Y', lt)
- msg['From'] = 'reports@asterix'
- msg['To'] = 'mail@mail.mail'
-
- msg.preamble = strftime('Leistungsreport – %d%m%Y', lt)
-
- # Attachments
- fileArray = ['cpu.png','memory.png','network.png']
- for file in fileArray:
- fp = open(file, ‘rb’)
- img = MIMEImage(fp.read())
- fp.close()
- msg.attach(img)
-
- # Login in SMTP-Server
- s = smtplib.SMTP('smtpmail.t-online.de')
- s.login('mail@mail.mail', '#####')
-
- s.sendmail('mail@mail.mail', 'mail@mail.mail', msg.as_string())
- s.quit()
+~~~
+#!/usr/bin/python2
+import smtplib
+from time import *
+from email.mime.image import MIMEImage
+from email.mime.multipart import MIMEMultipart
+
+lt = localtime()
+
+# Mail-Header
+msg = MIMEMultipart()
+msg['Subject'] = strftime('Leistungsreport – %d%m%Y', lt)
+msg['From'] = 'reports@asterix'
+msg['To'] = 'mail@mail.mail'
+
+msg.preamble = strftime('Leistungsreport – %d%m%Y', lt)
+
+# Attachments
+fileArray = ['cpu.png','memory.png','network.png']
+for file in fileArray:
+ fp = open(file, ‘rb’)
+ img = MIMEImage(fp.read())
+ fp.close()
+ msg.attach(img)
+
+# Login in SMTP-Server
+s = smtplib.SMTP('smtpmail.t-online.de')
+s.login('mail@mail.mail', '#####')
+
+s.sendmail('mail@mail.mail', 'mail@mail.mail', msg.as_string())
+s.quit()
+~~~
+{: .language-python}
Als Endergebniss erhalte ich dann täglich solche Grafiken per Mail: