-
Notifications
You must be signed in to change notification settings - Fork 9
/
mom-guestd
executable file
·84 lines (75 loc) · 2.88 KB
/
mom-guestd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/bin/env python
# Memory Overcommitment Manager
# Copyright (C) 2010 Adam Litke, IBM Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import socket
import signal
import ConfigParser
import logging
from mom.Collectors.GuestNetworkDaemon import _Server
from mom.Collectors.Collector import *
def signal_quit(signum, frame):
print "Received signal", signum, "shutting down."
sys.exit(0)
def configure_logger(config):
logger = logging.getLogger()
verbosity = config.get('logging', 'verbosity').lower()
if verbosity == '5' or verbosity == 'debug':
level = logging.DEBUG
elif verbosity == '4' or verbosity == 'info':
level = logging.INFO
elif verbosity == '3' or verbosity == 'warn':
level = logging.WARN
elif verbosity == '2' or verbosity == 'error':
level = logging.ERROR
elif verbosity == '1' or verbosity == 'critical':
level = logging.CRITICAL
else:
level = logging.DEBUG
logger.setLevel(level)
log = config.get('logging', 'log')
if log.lower() == 'stdio':
handler = logging.StreamHandler()
else:
print "logging to file %s" % log
bytes = config.getint('logging', 'max-bytes')
backups = config.getint('logging', 'backup-count')
handler = logging.handlers.RotatingFileHandler(log, 'a', bytes, backups)
handler.setLevel(level)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
def main():
"""
Executable code for running a network collector server on a guest.
"""
signal.signal(signal.SIGINT, signal_quit)
signal.signal(signal.SIGTERM, signal_quit)
config = ConfigParser.ConfigParser()
config.add_section('main')
config.set('main', 'host', '')
config.set('main', 'port', '2187')
config.set('main', 'min_free', '0.20') # These two variables
config.set('main', 'max_free', '0.50') # are currently unused
config.add_section('logging')
config.set('logging', 'log', 'stdio')
config.set('logging', 'verbosity', 'info')
config.set('logging', 'max-bytes', '2097152')
config.set('logging', 'backup-count', '5')
configure_logger(config)
server = _Server(config)
server.run()
if __name__ == "__main__":
main()