[CalendarServer-changes] [1452] CalDAVTester/trunk/monitor.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Apr 5 11:21:28 PDT 2007
Revision: 1452
http://trac.macosforge.org/projects/calendarserver/changeset/1452
Author: cdaboo at apple.com
Date: 2007-04-05 11:21:28 -0700 (Thu, 05 Apr 2007)
Log Message:
-----------
Allow logging to a file.
Modified Paths:
--------------
CalDAVTester/trunk/monitor.py
Modified: CalDAVTester/trunk/monitor.py
===================================================================
--- CalDAVTester/trunk/monitor.py 2007-04-05 18:05:55 UTC (rev 1451)
+++ CalDAVTester/trunk/monitor.py 2007-04-05 18:21:28 UTC (rev 1452)
@@ -37,12 +37,17 @@
if __name__ == "__main__":
+ monitorinfoname = "scripts/monitoring/monitorinfo.xml"
+ if len(sys.argv) > 1:
+ monitorinfoname = sys.argv[1]
+
+ if len(sys.argv) > 2:
+ monitorlogname = sys.argv[2]
+ else:
+ monitorlogname = None
+
def readXML():
- monitorinfoname = "scripts/monitoring/monitorinfo.xml"
- if len(sys.argv) > 1:
- monitorinfoname = sys.argv[1]
-
# Open and parse the server config file
fd = open(monitorinfoname, "r")
doc = xml.dom.minidom.parse( fd )
@@ -88,39 +93,50 @@
signal.signal(signal.SIGINT, doEnd)
+ if monitorlogname:
+ log = open(monitorlogname, "a")
+ else:
+ log = None
+
+ def logtxt(txt):
+ if log:
+ log.write("%s\n" % (txt,))
+ else:
+ print txt
+
doStart()
if minfo.logging:
- print "Start:"
+ logtxt("Start:")
try:
last_notify = 0
while(True):
time.sleep(minfo.period)
result, timing = doScript(minfo.testinfo)
if minfo.logging:
- print "Result: %d, Timing: %.3f" % (result, timing,)
+ logtxt("Result: %d, Timing: %.3f" % (result, timing,))
if timing >= minfo.warningtime:
dt = str(datetime.datetime.now())
dt = dt[0:dt.rfind(".")]
msg = "[%s] WARNING: request time (%.3f) exceeds limit (%.3f)" % (dt, timing, minfo.warningtime,)
- print msg
+ logtxt(msg)
if minfo.notify_time_exceeded and (time.time() - last_notify > minfo.notify_interval * 60):
- print "Sending notification to %s" % (minfo.notify,)
+ logtxt("Sending notification to %s" % (minfo.notify,))
doNotification(msg)
last_notify = time.time()
if result != 0:
dt = str(datetime.datetime.now())
dt = dt[0:dt.rfind(".")]
msg = "[%s] WARNING: request failed" % (dt,)
- print msg
+ logtxt(msg)
if minfo.notify_request_failed and (time.time() - last_notify > minfo.notify_interval * 60):
- print "Sending notification to %s" % (minfo.notify,)
+ logtxt("Sending notification to %s" % (minfo.notify,))
doNotification(msg)
last_notify = time.time()
if minfo.logging:
- print "Done"
+ logtxt("Done")
except SystemExit:
pass
except Exception, e:
- print "Run exception: %s" % (str(e),)
+ log.write("Run exception: %s" % (str(e),))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070405/5c891601/attachment.html
More information about the calendarserver-changes
mailing list