##// END OF EJS Templates
feat(system-info): properly report storage stats after diskcache removal
super-admin -
r5421:0968de67 default
parent child Browse files
Show More
@@ -169,6 +169,7 b' class AdminSystemInfoSettingsView(BaseAp'
169 (_('Gist storage location'), val('storage_gist')['path'], state('storage_gist')),
169 (_('Gist storage location'), val('storage_gist')['path'], state('storage_gist')),
170 (_('Gist storage info'), val('storage_gist')['text'], state('storage_gist')),
170 (_('Gist storage info'), val('storage_gist')['text'], state('storage_gist')),
171
171
172 (_('Archive cache storage type'), val('storage_archive')['type'], state('storage_archive')),
172 (_('Archive cache storage location'), val('storage_archive')['path'], state('storage_archive')),
173 (_('Archive cache storage location'), val('storage_archive')['path'], state('storage_archive')),
173 (_('Archive cache info'), val('storage_archive')['text'], state('storage_archive')),
174 (_('Archive cache info'), val('storage_archive')['text'], state('storage_archive')),
174
175
@@ -15,6 +15,7 b''
15 # This program is dual-licensed. If you wish to learn more about the
15 # This program is dual-licensed. If you wish to learn more about the
16 # RhodeCode Enterprise Edition, including its added features, Support services,
16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 # and proprietary license terms, please see https://rhodecode.com/licenses/
17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18 import os
18
19
19
20
20 class ArchiveCacheLock(Exception):
21 class ArchiveCacheLock(Exception):
@@ -28,3 +29,43 b' def archive_iterator(_reader, block_size'
28 if not data:
29 if not data:
29 break
30 break
30 yield data
31 yield data
32
33
34 def get_directory_statistics(start_path):
35 """
36 total_files, total_size, directory_stats = get_directory_statistics(start_path)
37
38 print(f"Directory statistics for: {start_path}\n")
39 print(f"Total files: {total_files}")
40 print(f"Total size: {format_size(total_size)}\n")
41
42 :param start_path:
43 :return:
44 """
45
46 total_files = 0
47 total_size = 0
48 directory_stats = {}
49
50 for dir_path, dir_names, file_names in os.walk(start_path):
51 dir_size = 0
52 file_count = len(file_names)
53
54 for file in file_names:
55 filepath = os.path.join(dir_path, file)
56 file_size = os.path.getsize(filepath)
57 dir_size += file_size
58
59 directory_stats[dir_path] = {'file_count': file_count, 'size': dir_size}
60 total_files += file_count
61 total_size += dir_size
62
63 return total_files, total_size, directory_stats
64
65
66 def format_size(size):
67 # Convert size in bytes to a human-readable format (e.g., KB, MB, GB)
68 for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
69 if size < 1024:
70 return f"{size:.2f} {unit}"
71 size /= 1024
@@ -100,7 +100,7 b' def get_cert_path(ini_path):'
100 default = '/etc/ssl/certs/ca-certificates.crt'
100 default = '/etc/ssl/certs/ca-certificates.crt'
101 control_ca_bundle = os.path.join(
101 control_ca_bundle = os.path.join(
102 os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(ini_path)))),
102 os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(ini_path)))),
103 '.rccontrol-profile/etc/ca-bundle.crt')
103 '/etc/ssl/certs/ca-certificates.crt')
104 if os.path.isfile(control_ca_bundle):
104 if os.path.isfile(control_ca_bundle):
105 default = control_ca_bundle
105 default = control_ca_bundle
106
106
@@ -323,7 +323,7 b' def cpu():'
323 value['cpu_count'] = psutil.cpu_count()
323 value['cpu_count'] = psutil.cpu_count()
324
324
325 human_value = value.copy()
325 human_value = value.copy()
326 human_value['text'] = '{} cores at {} %'.format(value['cpu_count'], value['cpu'])
326 human_value['text'] = f'{value["cpu_count"]} cores at {value["cpu"]} %'
327
327
328 return SysInfoRes(value=value, state=state, human_value=human_value)
328 return SysInfoRes(value=value, state=state, human_value=human_value)
329
329
@@ -398,8 +398,8 b' def storage_inodes():'
398 @register_sysinfo
398 @register_sysinfo
399 def storage_archives():
399 def storage_archives():
400 import rhodecode
400 import rhodecode
401 from rhodecode.lib.utils import safe_str
402 from rhodecode.lib.helpers import format_byte_size_binary
401 from rhodecode.lib.helpers import format_byte_size_binary
402 from rhodecode.lib.rc_cache.archive_cache.utils import get_directory_statistics
403
403
404 storage_type = rhodecode.ConfigGet().get_str('archive_cache.backend.type')
404 storage_type = rhodecode.ConfigGet().get_str('archive_cache.backend.type')
405 storage_key = 'archive_cache.filesystem.store_dir'
405 storage_key = 'archive_cache.filesystem.store_dir'
@@ -408,29 +408,20 b' def storage_archives():'
408 f'{storage_key}=/path/to/cache option in the .ini file'
408 f'{storage_key}=/path/to/cache option in the .ini file'
409 path = rhodecode.ConfigGet().get_str(storage_key, missing=default_msg)
409 path = rhodecode.ConfigGet().get_str(storage_key, missing=default_msg)
410
410
411 value = dict(percent=0, used=0, total=0, items=0, path=path, text='')
411 value = dict(percent=0, used=0, total=0, items=0, path=path, text='', type=storage_type)
412 state = STATE_OK_DEFAULT
412 state = STATE_OK_DEFAULT
413 try:
413 try:
414 if storage_type != 'filesystem':
414 if storage_type != 'filesystem':
415 # raise Exc to stop reporting on different type
415 # raise Exc to stop reporting on different type
416 raise ValueError('Storage type must be "filesystem"')
416 raise ValueError('Storage type must be "filesystem"')
417
417
418 items_count = 0
418 total_files, total_size, _directory_stats = get_directory_statistics(path)
419 used = 0
420 for root, dirs, files in os.walk(path):
421 if root == path:
422 items_count = len(dirs)
423
419
424 for f in files:
425 try:
426 used += os.path.getsize(os.path.join(root, f))
427 except OSError:
428 pass
429 value.update({
420 value.update({
430 'percent': 100,
421 'percent': 100,
431 'used': used,
422 'used': total_size,
432 'total': used,
423 'total': total_size,
433 'items': items_count
424 'items': total_files
434 })
425 })
435
426
436 except Exception as e:
427 except Exception as e:
@@ -451,6 +442,8 b' def storage_gist():'
451 from rhodecode.model.gist import GIST_STORE_LOC
442 from rhodecode.model.gist import GIST_STORE_LOC
452 from rhodecode.lib.utils import safe_str, get_rhodecode_repo_store_path
443 from rhodecode.lib.utils import safe_str, get_rhodecode_repo_store_path
453 from rhodecode.lib.helpers import format_byte_size_binary
444 from rhodecode.lib.helpers import format_byte_size_binary
445 from rhodecode.lib.rc_cache.archive_cache.utils import get_directory_statistics
446
454 path = safe_str(os.path.join(
447 path = safe_str(os.path.join(
455 get_rhodecode_repo_store_path(), GIST_STORE_LOC))
448 get_rhodecode_repo_store_path(), GIST_STORE_LOC))
456
449
@@ -459,22 +452,12 b' def storage_gist():'
459 state = STATE_OK_DEFAULT
452 state = STATE_OK_DEFAULT
460
453
461 try:
454 try:
462 items_count = 0
455 total_files, total_size, _directory_stats = get_directory_statistics(path)
463 used = 0
464 for root, dirs, files in os.walk(path):
465 if root == path:
466 items_count = len(dirs)
467
468 for f in files:
469 try:
470 used += os.path.getsize(os.path.join(root, f))
471 except OSError:
472 pass
473 value.update({
456 value.update({
474 'percent': 100,
457 'percent': 100,
475 'used': used,
458 'used': total_size,
476 'total': used,
459 'total': total_size,
477 'items': items_count
460 'items': total_files
478 })
461 })
479 except Exception as e:
462 except Exception as e:
480 log.exception('failed to fetch gist storage items')
463 log.exception('failed to fetch gist storage items')
General Comments 0
You need to be logged in to leave comments. Login now