-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkeystone_stats
executable file
·74 lines (61 loc) · 1.94 KB
/
keystone_stats
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
#!/usr/bin/env python
#
# Plugin to monitor status of Keystone
#
# Needs following minimal configuration in plugin-conf.d/keystone:
# [keystone_*]
# user keystone
#
# Magic markers
#%# capabilities=autoconf
#%# family=keystone
from keystone.common import config
import keystone.backends as db
import keystone.backends.api as db_api
import sys
stats = ['users', 'tenants']
def print_config():
global states
print 'graph_title Keystone Stats'
print 'graph_vlabel count'
print 'graph_args --base 1000 --lower-limit 0'
print 'graph_category keystone'
print 'graph_scale no'
print 'graph_info This graph shows stats about keystone: ' + (', ').join(stats)
for field in stats:
print '%s_enabled.label enabled %s' % (field, field)
print '%s_enabled.draw LINE2' % field
print '%s_enabled.info %s enabled' % (field, field)
print '%s_total.label total %s' % (field, field)
print '%s_total.draw LINE2' % field
print '%s_total.info %s total' % (field, field)
def get_status():
enabled = {}
total = {}
for k in stats:
enabled[k] = 0
total[k] = 0
for user in db_api.user.get_all():
total['users'] += 1
if user.enabled:
enabled['users'] += 1
for tenant in db_api.tenant.get_all():
total['tenants'] += 1
if tenant.enabled:
enabled['tenants'] += 1
return {'enabled': enabled, 'total': total}
def print_values():
stats = get_status()
for state in stats.keys():
for (field, value) in stats[state].iteritems():
print "%s_%s.value %s" % (field, state, value)
if __name__ == '__main__':
if len(sys.argv) > 1:
if sys.argv[1] == "config":
print_config()
elif sys.argv[1] == "autoconf":
print "yes"
else:
config_file, conf = config.load_paste_config('admin', {}, [])
db.configure_backends(conf.global_conf)
print_values()