Plugin keystone_stats: migrate to Python3, format documentation

This commit is contained in:
Lars Kruse 2020-11-26 00:03:57 +01:00
parent b02548ccd8
commit 0d055149cc
2 changed files with 52 additions and 36 deletions

View File

@ -1,14 +1,31 @@
#!/usr/bin/env python #!/usr/bin/env python3
#
# Plugin to monitor status of Keystone """
# =head1 NAME
# Needs following minimal configuration in plugin-conf.d/keystone:
# [keystone_*]
# user keystone keystone_stats - monitor status of Keystone
#
# Magic markers =head1 CONFIGURATION
#%# capabilities=autoconf
#%# family=auto
Needs following minimal configuration in plugin-conf.d/keystone:
[keystone_*]
user keystone
=head1 AUTHORS
Copyright 2012 - Mehdi Abaakouk <sileht@sileht.net>
=head1 MAGIC MARKERS
#%# capabilities=autoconf
#%# family=auto
=cut
"""
import sys import sys
import traceback import traceback
@ -23,23 +40,24 @@ except ImportError:
else: else:
successful_import = True successful_import = True
stats = ['users', 'tenants'] stats = ['users', 'tenants']
def print_config(): def print_config():
global states print('graph_title Keystone Stats')
print 'graph_title Keystone Stats' print('graph_vlabel count')
print 'graph_vlabel count' print('graph_args --base 1000 --lower-limit 0')
print 'graph_args --base 1000 --lower-limit 0' print('graph_category auth')
print 'graph_category auth' print('graph_scale no')
print 'graph_scale no' print('graph_info This graph shows stats about keystone: ' + (', ').join(stats))
print 'graph_info This graph shows stats about keystone: ' + (', ').join(stats)
for field in stats: for field in stats:
print '%s_enabled.label enabled %s' % (field, field) print('%s_enabled.label enabled %s' % (field, field))
print '%s_enabled.draw LINE2' % field print('%s_enabled.draw LINE2' % field)
print '%s_enabled.info %s enabled' % (field, field) print('%s_enabled.info %s enabled' % (field, field))
print '%s_total.label total %s' % (field, field) print('%s_total.label total %s' % (field, field))
print '%s_total.draw LINE2' % field print('%s_total.draw LINE2' % field)
print '%s_total.info %s total' % (field, field) print('%s_total.info %s total' % (field, field))
def get_status(): def get_status():
@ -60,13 +78,12 @@ def get_status():
# kvs and sql implement get_tenants() instead of get_all_tenants() # kvs and sql implement get_tenants() instead of get_all_tenants()
# Whoo: None of backend implements the correct function # Whoo: None of backend implements the correct function
tenants = [] tenants = []
for api_func in [ 'get_all_tenants', 'get_tenants']: for api_func in ['get_all_tenants', 'get_tenants']:
try: try:
tenants = getattr(identity_api, api_func)(None) tenants = getattr(identity_api, api_func)(None)
except exception.NotImplemented, NotImplementedError: except (exception.NotImplemented, NotImplementedError):
pass pass
for tenant in tenants: for tenant in tenants:
total['tenants'] += 1 total['tenants'] += 1
if tenant['enabled']: if tenant['enabled']:
@ -78,29 +95,29 @@ def get_status():
def print_values(): def print_values():
stats = get_status() stats = get_status()
for state in stats.keys(): for state in stats.keys():
for (field, value) in stats[state].iteritems(): for (field, value) in stats[state].items():
print "%s_%s.value %s" % (field, state, value) print("%s_%s.value %s" % (field, state, value))
def load_conf(): def load_conf():
config.CONF(config_files=[utils.find_config('keystone.conf')]) config.CONF(config_files=[utils.find_config('keystone.conf')])
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) > 1: if len(sys.argv) > 1:
if sys.argv[1] == "config": if sys.argv[1] == "config":
print_config() print_config()
elif sys.argv[1] == "autoconf": elif sys.argv[1] == "autoconf":
if not successful_import: if not successful_import:
print 'no (failed import keystone module)' print('no (failed import keystone module)')
sys.exit(0) sys.exit(0)
try: try:
load_conf() load_conf()
identity.Manager() identity.Manager()
except: except Exception:
print 'no (failed to connect keystone backend: %s'%traceback.format_exc() print('no (failed to connect keystone backend: %s' % traceback.format_exc())
sys.exit(0) sys.exit(0)
print 'yes' print('yes')
elif successful_import: elif successful_import:
load_conf() load_conf()
print_values() print_values()

View File

@ -170,7 +170,6 @@ plugins/jmx/plugin/jmx_
plugins/jvm/jstat__gccount plugins/jvm/jstat__gccount
plugins/jvm/jstat__gctime plugins/jvm/jstat__gctime
plugins/jvm/jstat__heap plugins/jvm/jstat__heap
plugins/keystone/keystone_stats
plugins/libvirt/kvm_cpu plugins/libvirt/kvm_cpu
plugins/libvirt/kvm_io plugins/libvirt/kvm_io
plugins/libvirt/kvm_mem plugins/libvirt/kvm_mem