mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
Real timeout added. Version bump to beta1.
This commit is contained in:
parent
8f5607b2a6
commit
ba0efcacfb
@ -3,6 +3,7 @@
|
|||||||
A very simple munin-node written in pure python (no external libraries
|
A very simple munin-node written in pure python (no external libraries
|
||||||
required)
|
required)
|
||||||
"""
|
"""
|
||||||
|
from datetime import datetime
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from os import listdir, access, X_OK, getpid
|
from os import listdir, access, X_OK, getpid
|
||||||
@ -16,11 +17,12 @@ import sys
|
|||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||||
|
SESSION_TIMEOUT = 10 # Amount of seconds until an unused session is closed
|
||||||
|
|
||||||
from daemon import createDaemon
|
from daemon import createDaemon
|
||||||
|
|
||||||
|
|
||||||
__version__ = '1.0dev4'
|
__version__ = '1.0b1'
|
||||||
|
|
||||||
|
|
||||||
class CmdHandler(object):
|
class CmdHandler(object):
|
||||||
@ -193,6 +195,12 @@ class CmdHandler(object):
|
|||||||
|
|
||||||
func(arg)
|
func(arg)
|
||||||
|
|
||||||
|
def is_timed_out(self):
|
||||||
|
return (datetime.now() - self._last_command).seconds > SESSION_TIMEOUT
|
||||||
|
|
||||||
|
def reset_time(self):
|
||||||
|
self._last_command = datetime.now()
|
||||||
|
|
||||||
|
|
||||||
def usage(option, opt, value, parser):
|
def usage(option, opt, value, parser):
|
||||||
"""
|
"""
|
||||||
@ -321,15 +329,14 @@ def process_socket(options):
|
|||||||
conn, addr = s.accept()
|
conn, addr = s.accept()
|
||||||
handler = CmdHandler(conn.recv, conn.send, options)
|
handler = CmdHandler(conn.recv, conn.send, options)
|
||||||
handler.do_version(None)
|
handler.do_version(None)
|
||||||
counter = 0
|
handler.reset_time()
|
||||||
|
|
||||||
LOG.info("Accepting incoming connection from %s" % (addr, ))
|
LOG.info("Accepting incoming connection from %s" % (addr, ))
|
||||||
while True:
|
while True:
|
||||||
data = conn.recv(1024)
|
data = conn.recv(1024)
|
||||||
if not data.strip():
|
if not data.strip():
|
||||||
sleep(1)
|
sleep(1)
|
||||||
counter += 1
|
if handler.is_timed_out():
|
||||||
if counter > 3:
|
|
||||||
LOG.info('Session timeout.')
|
LOG.info('Session timeout.')
|
||||||
conn.shutdown(socket.SHUT_RDWR)
|
conn.shutdown(socket.SHUT_RDWR)
|
||||||
conn.close()
|
conn.close()
|
||||||
@ -337,7 +344,7 @@ def process_socket(options):
|
|||||||
LOG.info('Listening on host %r, port %r' % (host, port))
|
LOG.info('Listening on host %r, port %r' % (host, port))
|
||||||
|
|
||||||
conn, addr = s.accept()
|
conn, addr = s.accept()
|
||||||
counter = 0
|
handler.reset_time()
|
||||||
handler.get_fun = conn.recv
|
handler.get_fun = conn.recv
|
||||||
handler.put_fun = conn.send
|
handler.put_fun = conn.send
|
||||||
handler.do_version(None)
|
handler.do_version(None)
|
||||||
@ -348,7 +355,7 @@ def process_socket(options):
|
|||||||
except socket.error, exc:
|
except socket.error, exc:
|
||||||
LOG.warning("Socket error. Reinitialising.: %s" % exc)
|
LOG.warning("Socket error. Reinitialising.: %s" % exc)
|
||||||
conn, addr = s.accept()
|
conn, addr = s.accept()
|
||||||
counter = 0
|
handler.reset_time()
|
||||||
handler.get_fun = conn.recv
|
handler.get_fun = conn.recv
|
||||||
handler.put_fun = conn.send
|
handler.put_fun = conn.send
|
||||||
handler.do_version(None)
|
handler.do_version(None)
|
||||||
@ -363,7 +370,7 @@ def process_socket(options):
|
|||||||
LOG.info('Listening on host %r, port %r' % (host, port))
|
LOG.info('Listening on host %r, port %r' % (host, port))
|
||||||
|
|
||||||
conn, addr = s.accept()
|
conn, addr = s.accept()
|
||||||
counter = 0
|
handler.reset_time()
|
||||||
handler.get_fun = conn.recv
|
handler.get_fun = conn.recv
|
||||||
handler.put_fun = conn.send
|
handler.put_fun = conn.send
|
||||||
handler.do_version(None)
|
handler.do_version(None)
|
||||||
|
Loading…
Reference in New Issue
Block a user