Add some config options

Add a fileservers option (which extends the cell list if specified).

Add debug option to config file

Better handle all config variables and better document the sample
config file.
This commit is contained in:
Ian Wienand 2018-06-05 11:54:37 +10:00
parent 52734ec18e
commit cacf936df8
2 changed files with 37 additions and 9 deletions

View File

@ -110,7 +110,14 @@ class AFSMonCmd(object):
self.args = parser.parse_args(args) self.args = parser.parse_args(args)
if self.args.debug: if not os.path.exists(self.args.config):
parser.error("Config file %s does not exist" % self.args.config)
self.config = configparser.RawConfigParser()
self.config.read(self.args.config)
if self.args.debug or \
self.config.getboolean('main', 'debug', fallback=False):
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logger.debug("Debugging enabled") logger.debug("Debugging enabled")
@ -118,18 +125,26 @@ class AFSMonCmd(object):
parser.print_help() parser.print_help()
return 1 return 1
if not os.path.exists(self.args.config): fs_addrs = []
raise ValueError("Config file %s does not exist" %
self.args.config)
self.config = configparser.RawConfigParser() # Look for fileservers from a given cell
self.config.read(self.args.config) cell = self.config.get('main', 'cell', fallback=None)
if cell:
fs_addrs = afsmon.get_fs_addresses(cell.strip())
logger.debug("cell %s fileservers: %s" % (
cell, ", ".join(fs_addrs)))
cell = self.config.get('main', 'cell').strip() # Add in any specific fileservers from config
cfg_fs = self.config.get('main', 'fileservers', fallback=None)
if cfg_fs:
cfg_fs = cfg_fs.strip().split('\n')
logger.debug("cfg fileservers: %s" % ", ".join(cfg_fs))
fs_addrs.extend(cfg_fs)
fs_addrs = afsmon.get_fs_addresses(cell) if not fs_addrs:
logger.debug("Found fileservers: %s" % ", ".join(fs_addrs)) raise ValueError("No fileservers found!")
# populate self.fileservers
for addr in fs_addrs: for addr in fs_addrs:
logger.debug("Finding stats for: %s" % addr) logger.debug("Finding stats for: %s" % addr)
fs = afsmon.FileServerStats(addr) fs = afsmon.FileServerStats(addr)

View File

@ -1,4 +1,17 @@
[main] [main]
# Enable debugging output
debug = True
# If specified, all fileservers in this cell will be queried
cell = openstack.org cell = openstack.org
# You can specify a specific list of fileservers. This is appended to
# the cell fileservers if present, otherwise is the canonical list
fileservers = fileserver01.afs.company.com
fileserver02.afs.company.com
fileserver03.afs.company.com
# Options for remote statsd host if required
[statsd]
host = localhost
port = 8125