initial plugin for monitoring error logs
authorArthur Lutz <arthur.lutz@logilab.fr>
Mon, 30 Jun 2008 14:46:50 +0200
changeset 3 ea25521b42b5
parent 2 5132ebd0932b
child 4 80b859422abf
initial plugin for monitoring error logs
munin_error_stats.py
zope_errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/munin_error_stats.py	Mon Jun 30 14:46:50 2008 +0200
@@ -0,0 +1,44 @@
+## Script (Python) "munin_error_stats.py"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+"""
+Fetches data about the ZODB for the munin plugin "zope_error_stats".
+Needs the Manager proxy role to work.
+Only answers requests from localhost directly to zopes port.
+"""
+
+req = context.REQUEST
+
+if req['HTTP_X_FORWARDED_FOR'] or req['REMOTE_ADDR'] != '127.0.0.1':
+    return "This script can only be called frm localhost"
+
+sec = 60*5 # 5 min is munins update frequency
+
+now = float(DateTime())
+then = now-sec
+
+request = {'chart_start':then,
+               'chart_end':now}
+
+error_log = context.restrictedTraverse('error_log')
+entries = []
+types = []
+users = []
+for entry in error_log.getLogEntries():
+    if entry['time'] <= float(DateTime()-1):
+        pass
+    entries.append(entry)
+    if entry['type'] not in types:
+        types.append(entry['type'])
+    if entry['userid'] not in users:
+        users.append(entry['userid'])
+
+print len(entries), len(types), len(users)
+
+return printed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zope_errors	Mon Jun 30 14:46:50 2008 +0200
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+
+from sys import argv
+import httplib
+conns = []
+
+# this should really go in plugins.conf
+conn = httplib.HTTPConnection("localhost",9080)
+
+
+url = "/munin_error_stats.py"
+sites = ['root', 'plone', 'portal']
+
+if len(argv) > 1 and argv[1] == 'config':
+
+    print """graph_title Zope Errors 
+    graph_vlabel Count 
+    graph_category Zope
+    graph_info The number of errors in error_log over the past 24h""".replace("\n    ","\n")
+    for i in range(0,len(sites)):
+        print """error_count%(i)s.label %(n)s error count
+        type_count%(i)s.label %(n)s type counts
+        user_count%(i)s.label %(n)s nb of user""".replace("\n        ","\n") % dict(i=i,
+                                                                                     n=sites[i])
+else:
+    for i in range(0,len(sites)):
+        site = sites[i]
+        if site == 'root':
+            site = ''
+        conn.request("GET", '/%s%s' % (site, url))
+
+        r1 = conn.getresponse()
+        #print r1.status, r1.reason
+        #200 OK
+        data = r1.read().strip()
+        conn.close()
+        #print data
+        (error_count, type_count, user_count) = data.split()
+        id = dict(i=i)
+        print 'error_count%(i)s.value' % id, error_count
+        print 'type_count%(i)s.value'% id, type_count
+        print 'user_count%(i)s.value'% id, user_count
+