# HG changeset patch # User Marcin Kuzminski # Date 2016-10-18 12:49:45 # Node ID f516f8a446d40110bcb30732cc66bf18cd50fe63 # Parent f6ed72f08cb6f1a8f935eb672a7bd9be4d6ed741 system-info: expose inode limits and usage. Fixes #4282 diff --git a/rhodecode/api/tests/test_get_server_info.py b/rhodecode/api/tests/test_get_server_info.py --- a/rhodecode/api/tests/test_get_server_info.py +++ b/rhodecode/api/tests/test_get_server_info.py @@ -46,6 +46,7 @@ class TestGetServerInfo(object): expected['load'] = resp['result']['load'] expected['cpu'] = resp['result']['cpu'] expected['disk'] = resp['result']['disk'] + expected['disk_inodes'] = resp['result']['disk_inodes'] expected['server_ip'] = '127.0.0.1:80' assert_ok(id_, expected, given=response.body) @@ -60,6 +61,7 @@ class TestGetServerInfo(object): expected['load'] = resp['result']['load'] expected['cpu'] = resp['result']['cpu'] expected['disk'] = resp['result']['disk'] + expected['disk_inodes'] = resp['result']['disk_inodes'] expected['server_ip'] = '127.0.0.1:80' assert_ok(id_, expected, given=response.body) diff --git a/rhodecode/model/scm.py b/rhodecode/model/scm.py --- a/rhodecode/model/scm.py +++ b/rhodecode/model/scm.py @@ -891,6 +891,9 @@ class ScmModel(BaseModel): from rhodecode.lib.vcs.backends.git import discover_git_version from rhodecode.model.gist import GIST_STORE_LOC + def percentage(part, whole): + return 100 * float(part) / float(whole) + try: # cygwin cannot have yet psutil support. import psutil @@ -904,6 +907,7 @@ class ScmModel(BaseModel): _boot_time = _NA _cpu = _NA _disk = dict(percent=0, used=0, total=0, error='') + _disk_inodes = dict(percent=0, free=0, used=0, total=0, error='') _load = {'1_min': _NA, '5_min': _NA, '15_min': _NA} model = VcsSettingsModel() @@ -920,6 +924,19 @@ class ScmModel(BaseModel): log.exception('Failed to fetch disk info') _disk = {'percent': 0, 'used': 0, 'total': 0, 'error': str(e)} + # disk inodes usage + try: + i_stat = os.statvfs(storage_path) + + _disk_inodes['used'] = i_stat.f_ffree + _disk_inodes['free'] = i_stat.f_favail + _disk_inodes['total'] = i_stat.f_files + _disk_inodes['percent'] = percentage( + _disk_inodes['used'], _disk_inodes['total']) + except Exception as e: + log.exception('Failed to fetch disk inodes info') + _disk_inodes['error'] = str(e) + # memory _memory = dict(psutil.virtual_memory()._asdict()) _memory['percent2'] = psutil._common.usage_percent( @@ -1068,6 +1085,7 @@ class ScmModel(BaseModel): 'cpu': _cpu, 'memory': _memory, 'disk': _disk, + 'disk_inodes': _disk_inodes, 'disk_archive': _disk_archive, 'disk_gist': _disk_gist, 'disk_index': _disk_index, diff --git a/rhodecode/templates/admin/settings/settings_system.html b/rhodecode/templates/admin/settings/settings_system.html --- a/rhodecode/templates/admin/settings/settings_system.html +++ b/rhodecode/templates/admin/settings/settings_system.html @@ -11,6 +11,7 @@ (_('Uptime'), c.uptime_age, ''), (_('Storage location'), c.storage, ''), (_('Storage disk space'), "%s/%s, %s%% used%s" % (h.format_byte_size_binary(c.disk['used']), h.format_byte_size_binary(c.disk['total']),(c.disk['percent']), ' %s' % c.disk['error'] if 'error' in c.disk else ''), ''), + (_('Storage file limit (inodes)'), "%s/%s, %.1f%% used%s" % (c.disk_inodes['used'], c.disk_inodes['total'],(c.disk_inodes['percent']), ' %s' % c.disk_inodes['error'] if 'error' in c.disk_inodes else ''), ''), (_('Search index storage'), c.index_storage, ''), (_('Search index size'), "%s %s" % (h.format_byte_size_binary(c.disk_index['used']), ' %s' % c.disk_index['error'] if 'error' in c.disk_index else ''), ''),