-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgitlab_total_repo_size
executable file
·50 lines (43 loc) · 1.42 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
44
45
46
47
48
49
#!/usr/bin/env python
from lib import dirsize
from lib import get_gitlab_instance
import os
import sys
import glob
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)
if '@hashed' in namespaces:
repository_root = os.path.join(repository_root, '@hashed')
namespaces = os.listdir(repository_root)
for namespace in namespaces:
subdir = os.path.join(repository_root, namespace)
if os.path.isfile(subdir):
continue
repos = glob.glob(os.path.join(subdir, '*', '*.git'))
if not repos:
repos = os.listdir(subdir)
for repo in repos:
repo_path = os.path.join(subdir, 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))