Commits

Alfonso de la Guarda Reyes committed f2c1c5d

Monitor Server - Initial Release

Comments (0)

Files changed (3)

+Server Monitor
+author: Alfonso de la Guarda Reyes
+
+License: Under GPL/v2
+
+Summary:
+Simple script which extracts system information and saves to a sqlite db, which you can export to csv.
+You can also add some additional features or events.
+
+Requires:
+mpstat

server_monitor.py

+#!/usr/bin/python2.5
+"""
+Monitoring memory and cpu
+"""
+import os
+import sqlite3 as db
+import time
+
+CONEXION = db.connect("servers.db")
+CRSR = CONEXION.cursor()
+
+DAT_TIME = time.strftime('%Y-%m-%d %H:%M:%S')
+DAT_HNAM = os.popen('uname -n').read().strip()
+DAT_KERN = os.popen('uname -r').read().strip()
+
+#Memory
+DAT = os.popen("""egrep '(MemTotal|MemFree|SwapTotal|SwapFree):' 
+    /proc/meminfo """)
+DAT_MEM = [data.split(':')[1].strip().split(' ')[0] for data in DAT]
+SQL = """insert into memoria (hostname,date_time,kernel,mem_total,
+    mem_free,swap_total,swap_free) values ('%s','%s','%s','%s','%s',
+    '%s','%s')""" % (DAT_HNAM, DAT_TIME, DAT_KERN, DAT_MEM[0],
+    DAT_MEM[1], DAT_MEM[2], DAT_MEM[3])
+CRSR.execute(SQL)
+
+#CPU
+DAT = os.popen("mpstat -P ALL").readlines()
+DAT_TMP = [data.strip().split(' ') for data in DAT[3:]]
+for val in DAT_TMP:
+    nli = []
+    for ele in val:
+        if ele and ':' not in ele:
+            nli.append(ele)
+    nli.insert(0, DAT_KERN)
+    nli.insert(0, DAT_TIME)
+    nli.insert(0, DAT_HNAM)
+    sql = """insert into procesador (hostname,date_time,kernel,cpu_num,
+        usr,nice,sys,iowait,irq,soft,steal,guest,idle) values ('%s',
+        '%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',
+        '%s')""" % tuple(nli)
+    CRSR.execute(SQL)
+
+CONEXION.commit()
+CONEXION.close()
+

Binary file added.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.