##// 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 169 (_('Gist storage location'), val('storage_gist')['path'], state('storage_gist')),
170 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 173 (_('Archive cache storage location'), val('storage_archive')['path'], state('storage_archive')),
173 174 (_('Archive cache info'), val('storage_archive')['text'], state('storage_archive')),
174 175
@@ -15,6 +15,7 b''
15 15 # This program is dual-licensed. If you wish to learn more about the
16 16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18 import os
18 19
19 20
20 21 class ArchiveCacheLock(Exception):
@@ -28,3 +29,43 b' def archive_iterator(_reader, block_size'
28 29 if not data:
29 30 break
30 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 100 default = '/etc/ssl/certs/ca-certificates.crt'
101 101 control_ca_bundle = os.path.join(
102 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 104 if os.path.isfile(control_ca_bundle):
105 105 default = control_ca_bundle
106 106
@@ -323,7 +323,7 b' def cpu():'
323 323 value['cpu_count'] = psutil.cpu_count()
324 324
325 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 328 return SysInfoRes(value=value, state=state, human_value=human_value)
329 329
@@ -398,8 +398,8 b' def storage_inodes():'
398 398 @register_sysinfo
399 399 def storage_archives():
400 400 import rhodecode
401 from rhodecode.lib.utils import safe_str
402 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 404 storage_type = rhodecode.ConfigGet().get_str('archive_cache.backend.type')
405 405 storage_key = 'archive_cache.filesystem.store_dir'
@@ -408,29 +408,20 b' def storage_archives():'
408 408 f'{storage_key}=/path/to/cache option in the .ini file'
409 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 412 state = STATE_OK_DEFAULT
413 413 try:
414 414 if storage_type != 'filesystem':
415 415 # raise Exc to stop reporting on different type
416 416 raise ValueError('Storage type must be "filesystem"')
417 417
418 items_count = 0
419 used = 0
420 for root, dirs, files in os.walk(path):
421 if root == path:
422 items_count = len(dirs)
418 total_files, total_size, _directory_stats = get_directory_statistics(path)
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 420 value.update({
430 421 'percent': 100,
431 'used': used,
432 'total': used,
433 'items': items_count
422 'used': total_size,
423 'total': total_size,
424 'items': total_files
434 425 })
435 426
436 427 except Exception as e:
@@ -451,6 +442,8 b' def storage_gist():'
451 442 from rhodecode.model.gist import GIST_STORE_LOC
452 443 from rhodecode.lib.utils import safe_str, get_rhodecode_repo_store_path
453 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 447 path = safe_str(os.path.join(
455 448 get_rhodecode_repo_store_path(), GIST_STORE_LOC))
456 449
@@ -459,22 +452,12 b' def storage_gist():'
459 452 state = STATE_OK_DEFAULT
460 453
461 454 try:
462 items_count = 0
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
455 total_files, total_size, _directory_stats = get_directory_statistics(path)
473 456 value.update({
474 457 'percent': 100,
475 'used': used,
476 'total': used,
477 'items': items_count
458 'used': total_size,
459 'total': total_size,
460 'items': total_files
478 461 })
479 462 except Exception as e:
480 463 log.exception('failed to fetch gist storage items')
General Comments 0
You need to be logged in to leave comments. Login now