forked from MatthiasLohr/munin-plugins-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitlab_users
executable file
·42 lines (34 loc) · 1.21 KB
/
gitlab_users
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
#!/usr/bin/env python
from lib import get_gitlab_instance
import sys
SHOW_CONFIG = len(sys.argv) >= 2 and sys.argv[1] == 'config'
USER_STATES = ('active', 'blocked', ) # sorted and iterable
if SHOW_CONFIG:
print('graph_title GitLab users')
print('graph_vlabel users')
print('graph_args -l 0')
print('graph_category gitlab')
print('graph_order {0}'.format(' '.join(USER_STATES)))
for user_state in USER_STATES:
print('{0}.draw AREASTACK'.format(user_state))
print('{0}.label {0} user count'.format(user_state))
else:
gitlab = get_gitlab_instance()
db = gitlab.get_db_connection()
# python <2.7 compat, no {user_state: 0 for user_state in USER_STATES}
states = dict([(user_state, 0) for user_state in USER_STATES])
try:
cursor = db.cursor()
cursor.execute(
'SELECT state, COUNT(id) AS amount '
'FROM users '
'GROUP BY state '
'ORDER BY state ASC'
)
for row in cursor.fetchall():
states.update({row[0]: row[1]})
cursor.close()
finally:
db.close()
for user_state, user_amount in states.items():
print('{0}.value {1:d}'.format(user_state, user_amount))