##// END OF EJS Templates
sys-info: added helpers for faster loading of sys-info data
super-admin -
r4734:ee91c6f6 stable
parent child Browse files
Show More
@@ -24,6 +24,8 b' import sys'
24 24 import time
25 25 import platform
26 26 import collections
27 from functools import wraps
28
27 29 import pkg_resources
28 30 import logging
29 31 import resource
@@ -51,6 +53,26 b" STATE_WARN = 'warning'"
51 53 STATE_OK_DEFAULT = {'message': '', 'type': STATE_OK}
52 54
53 55
56 registered_helpers = {}
57
58
59 def register_sysinfo(func):
60 """
61 @register_helper
62 def db_check():
63 pass
64
65 db_check == registered_helpers['db_check']
66 """
67 global registered_helpers
68 registered_helpers[func.__name__] = func
69
70 @wraps(func)
71 def _wrapper(*args, **kwargs):
72 return func(*args, **kwargs)
73 return _wrapper
74
75
54 76 # HELPERS
55 77 def percentage(part, whole):
56 78 whole = float(whole)
@@ -136,12 +158,14 b' class SysInfo(object):'
136 158
137 159
138 160 # SysInfo functions
161 @register_sysinfo
139 162 def python_info():
140 163 value = dict(version=' '.join(platform._sys_version()),
141 164 executable=sys.executable)
142 165 return SysInfoRes(value=value)
143 166
144 167
168 @register_sysinfo
145 169 def py_modules():
146 170 mods = dict([(p.project_name, {'version': p.version, 'location': p.location})
147 171 for p in pkg_resources.working_set])
@@ -150,6 +174,7 b' def py_modules():'
150 174 return SysInfoRes(value=value)
151 175
152 176
177 @register_sysinfo
153 178 def platform_type():
154 179 from rhodecode.lib.utils import safe_unicode, generate_platform_uuid
155 180
@@ -160,6 +185,7 b' def platform_type():'
160 185 return SysInfoRes(value=value)
161 186
162 187
188 @register_sysinfo
163 189 def locale_info():
164 190 import locale
165 191
@@ -175,6 +201,7 b' def locale_info():'
175 201 return SysInfoRes(value=value, human_value=human_value)
176 202
177 203
204 @register_sysinfo
178 205 def ulimit_info():
179 206 data = collections.OrderedDict([
180 207 ('cpu time (seconds)', get_resource(resource.RLIMIT_CPU)),
@@ -198,6 +225,7 b' def ulimit_info():'
198 225 return SysInfoRes(value=value)
199 226
200 227
228 @register_sysinfo
201 229 def uptime():
202 230 from rhodecode.lib.helpers import age, time_to_datetime
203 231 from rhodecode.translation import TranslationString
@@ -223,6 +251,7 b' def uptime():'
223 251 return SysInfoRes(value=value, human_value=human_value)
224 252
225 253
254 @register_sysinfo
226 255 def memory():
227 256 from rhodecode.lib.helpers import format_byte_size_binary
228 257 value = dict(available=0, used=0, used_real=0, cached=0, percent=0,
@@ -262,6 +291,7 b' def memory():'
262 291 return SysInfoRes(value=value, state=state, human_value=human_value)
263 292
264 293
294 @register_sysinfo
265 295 def machine_load():
266 296 value = {'1_min': _NA, '5_min': _NA, '15_min': _NA, 'text': ''}
267 297 state = STATE_OK_DEFAULT
@@ -284,6 +314,7 b' def machine_load():'
284 314 return SysInfoRes(value=value, state=state, human_value=human_value)
285 315
286 316
317 @register_sysinfo
287 318 def cpu():
288 319 value = {'cpu': 0, 'cpu_count': 0, 'cpu_usage': []}
289 320 state = STATE_OK_DEFAULT
@@ -302,6 +333,7 b' def cpu():'
302 333 return SysInfoRes(value=value, state=state, human_value=human_value)
303 334
304 335
336 @register_sysinfo
305 337 def storage():
306 338 from rhodecode.lib.helpers import format_byte_size_binary
307 339 from rhodecode.model.settings import VcsSettingsModel
@@ -337,6 +369,7 b' def storage():'
337 369 return SysInfoRes(value=value, state=state, human_value=human_value)
338 370
339 371
372 @register_sysinfo
340 373 def storage_inodes():
341 374 from rhodecode.model.settings import VcsSettingsModel
342 375 path = VcsSettingsModel().get_repos_location()
@@ -371,6 +404,7 b' def storage_inodes():'
371 404 return SysInfoRes(value=value, state=state, human_value=human_value)
372 405
373 406
407 @register_sysinfo
374 408 def storage_archives():
375 409 import rhodecode
376 410 from rhodecode.lib.utils import safe_str
@@ -414,6 +448,7 b' def storage_archives():'
414 448 return SysInfoRes(value=value, state=state, human_value=human_value)
415 449
416 450
451 @register_sysinfo
417 452 def storage_gist():
418 453 from rhodecode.model.gist import GIST_STORE_LOC
419 454 from rhodecode.model.settings import VcsSettingsModel
@@ -457,6 +492,7 b' def storage_gist():'
457 492 return SysInfoRes(value=value, state=state, human_value=human_value)
458 493
459 494
495 @register_sysinfo
460 496 def storage_temp():
461 497 import tempfile
462 498 from rhodecode.lib.helpers import format_byte_size_binary
@@ -485,6 +521,7 b' def storage_temp():'
485 521 return SysInfoRes(value=value, state=state, human_value=human_value)
486 522
487 523
524 @register_sysinfo
488 525 def search_info():
489 526 import rhodecode
490 527 from rhodecode.lib.index import searcher_from_config
@@ -508,6 +545,7 b' def search_info():'
508 545 return SysInfoRes(value=value, state=state, human_value=human_value)
509 546
510 547
548 @register_sysinfo
511 549 def git_info():
512 550 from rhodecode.lib.vcs.backends import git
513 551 state = STATE_OK_DEFAULT
@@ -521,6 +559,7 b' def git_info():'
521 559 return SysInfoRes(value=value, state=state, human_value=human_value)
522 560
523 561
562 @register_sysinfo
524 563 def hg_info():
525 564 from rhodecode.lib.vcs.backends import hg
526 565 state = STATE_OK_DEFAULT
@@ -533,6 +572,7 b' def hg_info():'
533 572 return SysInfoRes(value=value, state=state, human_value=human_value)
534 573
535 574
575 @register_sysinfo
536 576 def svn_info():
537 577 from rhodecode.lib.vcs.backends import svn
538 578 state = STATE_OK_DEFAULT
@@ -545,6 +585,7 b' def svn_info():'
545 585 return SysInfoRes(value=value, state=state, human_value=human_value)
546 586
547 587
588 @register_sysinfo
548 589 def vcs_backends():
549 590 import rhodecode
550 591 value = rhodecode.CONFIG.get('vcs.backends')
@@ -552,6 +593,7 b' def vcs_backends():'
552 593 return SysInfoRes(value=value, human_value=human_value)
553 594
554 595
596 @register_sysinfo
555 597 def vcs_server():
556 598 import rhodecode
557 599 from rhodecode.lib.vcs.backends import get_vcsserver_service_data
@@ -595,6 +637,7 b' def vcs_server():'
595 637 return SysInfoRes(value=value, state=state, human_value=human_value)
596 638
597 639
640 @register_sysinfo
598 641 def vcs_server_config():
599 642 from rhodecode.lib.vcs.backends import get_vcsserver_service_data
600 643 state = STATE_OK_DEFAULT
@@ -612,6 +655,7 b' def vcs_server_config():'
612 655 return SysInfoRes(value=value, state=state, human_value=human_value)
613 656
614 657
658 @register_sysinfo
615 659 def rhodecode_app_info():
616 660 import rhodecode
617 661 edition = rhodecode.CONFIG.get('rhodecode.edition')
@@ -628,6 +672,7 b' def rhodecode_app_info():'
628 672 return SysInfoRes(value=value, human_value=human_value)
629 673
630 674
675 @register_sysinfo
631 676 def rhodecode_config():
632 677 import rhodecode
633 678 path = rhodecode.CONFIG.get('__file__')
@@ -683,6 +728,7 b' def rhodecode_config():'
683 728 'path': path, 'cert_path': cert_path})
684 729
685 730
731 @register_sysinfo
686 732 def database_info():
687 733 import rhodecode
688 734 from sqlalchemy.engine import url as engine_url
@@ -727,6 +773,7 b' def database_info():'
727 773 return SysInfoRes(value=db_info, state=state, human_value=human_value)
728 774
729 775
776 @register_sysinfo
730 777 def server_info(environ):
731 778 import rhodecode
732 779 from rhodecode.lib.base import get_server_ip_addr, get_server_port
@@ -741,6 +788,7 b' def server_info(environ):'
741 788 return SysInfoRes(value=value)
742 789
743 790
791 @register_sysinfo
744 792 def usage_info():
745 793 from rhodecode.model.db import User, Repository
746 794 value = {
@@ -795,3 +843,11 b' def get_system_info(environ):'
795 843 'hg': SysInfo(hg_info)(),
796 844 'svn': SysInfo(svn_info)(),
797 845 }
846
847
848 def load_system_info(key):
849 """
850 get_sys_info('vcs_server')
851 get_sys_info('database')
852 """
853 return SysInfo(registered_helpers[key])()
General Comments 0
You need to be logged in to leave comments. Login now