Révision 0d055149
Plugin keystone_stats: migrate to Python3, format documentation
| plugins/keystone/keystone_stats | ||
|---|---|---|
| 1 |
#!/usr/bin/env python |
|
| 2 |
# |
|
| 3 |
# Plugin to monitor status of Keystone |
|
| 4 |
# |
|
| 5 |
# Needs following minimal configuration in plugin-conf.d/keystone: |
|
| 6 |
# [keystone_*] |
|
| 7 |
# user keystone |
|
| 8 |
# |
|
| 9 |
# Magic markers |
|
| 10 |
#%# capabilities=autoconf |
|
| 11 |
#%# family=auto |
|
| 1 |
#!/usr/bin/env python3 |
|
| 2 |
|
|
| 3 |
""" |
|
| 4 |
=head1 NAME |
|
| 5 |
|
|
| 6 |
|
|
| 7 |
keystone_stats - monitor status of Keystone |
|
| 8 |
|
|
| 9 |
=head1 CONFIGURATION |
|
| 10 |
|
|
| 11 |
|
|
| 12 |
Needs following minimal configuration in plugin-conf.d/keystone: |
|
| 13 |
|
|
| 14 |
[keystone_*] |
|
| 15 |
user keystone |
|
| 16 |
|
|
| 17 |
=head1 AUTHORS |
|
| 18 |
|
|
| 19 |
Copyright 2012 - Mehdi Abaakouk <sileht@sileht.net> |
|
| 20 |
|
|
| 21 |
|
|
| 22 |
=head1 MAGIC MARKERS |
|
| 23 |
|
|
| 24 |
#%# capabilities=autoconf |
|
| 25 |
#%# family=auto |
|
| 26 |
|
|
| 27 |
=cut |
|
| 28 |
""" |
|
| 12 | 29 |
|
| 13 | 30 |
import sys |
| 14 | 31 |
import traceback |
| ... | ... | |
| 23 | 40 |
else: |
| 24 | 41 |
successful_import = True |
| 25 | 42 |
|
| 43 |
|
|
| 26 | 44 |
stats = ['users', 'tenants'] |
| 27 | 45 |
|
| 46 |
|
|
| 28 | 47 |
def print_config(): |
| 29 |
global states |
|
| 30 |
print 'graph_title Keystone Stats' |
|
| 31 |
print 'graph_vlabel count' |
|
| 32 |
print 'graph_args --base 1000 --lower-limit 0' |
|
| 33 |
print 'graph_category auth' |
|
| 34 |
print 'graph_scale no' |
|
| 35 |
print 'graph_info This graph shows stats about keystone: ' + (', ').join(stats)
|
|
| 48 |
print('graph_title Keystone Stats')
|
|
| 49 |
print('graph_vlabel count')
|
|
| 50 |
print('graph_args --base 1000 --lower-limit 0')
|
|
| 51 |
print('graph_category auth')
|
|
| 52 |
print('graph_scale no')
|
|
| 53 |
print('graph_info This graph shows stats about keystone: ' + (', ').join(stats))
|
|
| 36 | 54 |
for field in stats: |
| 37 |
print '%s_enabled.label enabled %s' % (field, field)
|
|
| 38 |
print '%s_enabled.draw LINE2' % field
|
|
| 39 |
print '%s_enabled.info %s enabled' % (field, field)
|
|
| 40 |
print '%s_total.label total %s' % (field, field)
|
|
| 41 |
print '%s_total.draw LINE2' % field
|
|
| 42 |
print '%s_total.info %s total' % (field, field)
|
|
| 55 |
print('%s_enabled.label enabled %s' % (field, field))
|
|
| 56 |
print('%s_enabled.draw LINE2' % field)
|
|
| 57 |
print('%s_enabled.info %s enabled' % (field, field))
|
|
| 58 |
print('%s_total.label total %s' % (field, field))
|
|
| 59 |
print('%s_total.draw LINE2' % field)
|
|
| 60 |
print('%s_total.info %s total' % (field, field))
|
|
| 43 | 61 |
|
| 44 | 62 |
|
| 45 | 63 |
def get_status(): |
| ... | ... | |
| 60 | 78 |
# kvs and sql implement get_tenants() instead of get_all_tenants() |
| 61 | 79 |
# Whoo: None of backend implements the correct function |
| 62 | 80 |
tenants = [] |
| 63 |
for api_func in [ 'get_all_tenants', 'get_tenants']:
|
|
| 81 |
for api_func in ['get_all_tenants', 'get_tenants']: |
|
| 64 | 82 |
try: |
| 65 | 83 |
tenants = getattr(identity_api, api_func)(None) |
| 66 |
except exception.NotImplemented, NotImplementedError:
|
|
| 84 |
except (exception.NotImplemented, NotImplementedError):
|
|
| 67 | 85 |
pass |
| 68 | 86 |
|
| 69 |
|
|
| 70 | 87 |
for tenant in tenants: |
| 71 | 88 |
total['tenants'] += 1 |
| 72 | 89 |
if tenant['enabled']: |
| ... | ... | |
| 78 | 95 |
def print_values(): |
| 79 | 96 |
stats = get_status() |
| 80 | 97 |
for state in stats.keys(): |
| 81 |
for (field, value) in stats[state].iteritems(): |
|
| 82 |
print "%s_%s.value %s" % (field, state, value) |
|
| 98 |
for (field, value) in stats[state].items(): |
|
| 99 |
print("%s_%s.value %s" % (field, state, value))
|
|
| 100 |
|
|
| 83 | 101 |
|
| 84 | 102 |
def load_conf(): |
| 85 | 103 |
config.CONF(config_files=[utils.find_config('keystone.conf')])
|
| 86 | 104 |
|
| 105 |
|
|
| 87 | 106 |
if __name__ == '__main__': |
| 88 | 107 |
if len(sys.argv) > 1: |
| 89 | 108 |
if sys.argv[1] == "config": |
| 90 | 109 |
print_config() |
| 91 | 110 |
elif sys.argv[1] == "autoconf": |
| 92 | 111 |
if not successful_import: |
| 93 |
print 'no (failed import keystone module)'
|
|
| 112 |
print('no (failed import keystone module)')
|
|
| 94 | 113 |
sys.exit(0) |
| 95 | 114 |
try: |
| 96 | 115 |
load_conf() |
| 97 | 116 |
identity.Manager() |
| 98 |
except: |
|
| 99 |
print 'no (failed to connect keystone backend: %s'%traceback.format_exc()
|
|
| 117 |
except Exception:
|
|
| 118 |
print('no (failed to connect keystone backend: %s' % traceback.format_exc())
|
|
| 100 | 119 |
sys.exit(0) |
| 101 |
print 'yes' |
|
| 102 |
|
|
| 120 |
print('yes')
|
|
| 103 | 121 |
elif successful_import: |
| 104 | 122 |
load_conf() |
| 105 | 123 |
print_values() |
| 106 |
|
|
| t/test-exception-wrapper.expected-failures | ||
|---|---|---|
| 170 | 170 |
plugins/jvm/jstat__gccount |
| 171 | 171 |
plugins/jvm/jstat__gctime |
| 172 | 172 |
plugins/jvm/jstat__heap |
| 173 |
plugins/keystone/keystone_stats |
|
| 174 | 173 |
plugins/libvirt/kvm_cpu |
| 175 | 174 |
plugins/libvirt/kvm_io |
| 176 | 175 |
plugins/libvirt/kvm_mem |
Formats disponibles : Unified diff