forked from MatthiasLohr/munin-plugins-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitlab_total_repo_size
executable file
·44 lines (37 loc) · 1.19 KB
/
gitlab_total_repo_size
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
#!/usr/bin/env python
from lib import dirsize
from lib import get_gitlab_instance
import os
import sys
gitlab = get_gitlab_instance()
repository_root = gitlab.get_repository_dir()
if len(sys.argv) >= 2 and sys.argv[1] == 'config':
print('graph_title GitLab Repository Disk Usage')
print('graph_vlabel Repository Disk Usage')
print('graph_args -l 0 --base 1024')
print('graph_category gitlab')
print('repo_size.label Repositories')
print('repo_size.draw AREA')
print('wiki_size.label Wikis')
print('wiki_size.draw STACK')
sys.exit(0)
repo_size = 0
wiki_size = 0
try:
namespaces = os.listdir(repository_root)
for namespace in namespaces:
subdir = repository_root + os.sep + namespace
if os.path.isfile(subdir):
continue
repos = os.listdir(subdir)
for repo in repos:
repo_path = subdir + os.sep + repo
if repo.endswith('.wiki.git'):
wiki_size += dirsize(repo_path)
elif repo.endswith('.git'):
repo_size += dirsize(repo_path)
except OSError as e:
print(e)
sys.exit(1)
print('repo_size.value ' + str(repo_size))
print('wiki_size.value ' + str(wiki_size))