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