##// END OF EJS Templates
feat(events): added context into events so we can track additional context of calling it
feat(events): added context into events so we can track additional context of calling it

File last commit:

r5608:6d33e504 default
r5623:2f80d511 default
Show More
system_info.py
893 lines | 27.8 KiB | text/x-python | PythonLexer
core: updated copyright to 2024
r5608 # Copyright (C) 2017-2024 RhodeCode GmbH
system-info: added missing license header.
r1552 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 import os
import sys
import time
import platform
processes: use resources library to fetch limits in better way.
r2674 import collections
system-info: optimized code based on linting
r4938 import psutil
sys-info: added helpers for faster loading of sys-info data
r4734 from functools import wraps
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 import pkg_resources
import logging
processes: use resources library to fetch limits in better way.
r2674 import resource
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
python3: fix import configparser
r4927 import configparser
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
tests: fixup the config stubs
r5145 from rc_license.models import LicenseModel
system-info: drop safe_unicode usage
r5028 from rhodecode.lib.str_utils import safe_str
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 log = logging.getLogger(__name__)
_NA = 'NOT AVAILABLE'
system-info: optimized code based on linting
r4938 _NA_FLOAT = 0.0
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
STATE_OK = 'ok'
STATE_ERR = 'error'
STATE_WARN = 'warning'
STATE_OK_DEFAULT = {'message': '', 'type': STATE_OK}
sys-info: added helpers for faster loading of sys-info data
r4734 registered_helpers = {}
def register_sysinfo(func):
"""
@register_helper
def db_check():
pass
db_check == registered_helpers['db_check']
"""
global registered_helpers
registered_helpers[func.__name__] = func
@wraps(func)
def _wrapper(*args, **kwargs):
return func(*args, **kwargs)
return _wrapper
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 # HELPERS
system-info: optimized code based on linting
r4938 def percentage(part: (int, float), whole: (int, float)):
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 whole = float(whole)
if whole > 0:
system-info: fix display of text in system inodes.
r1155 return round(100 * float(part) / whole, 1)
return 0.0
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
def get_storage_size(storage_path):
sizes = []
for file_ in os.listdir(storage_path):
storage_file = os.path.join(storage_path, file_)
if os.path.isfile(storage_file):
try:
sizes.append(os.path.getsize(storage_file))
except OSError:
vcs: expose SSL certificate path over the wire to the vcsserver....
r3337 log.exception('Failed to get size of storage file %s', storage_file)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 pass
return sum(sizes)
system-info: use safer resource.getrlimit becuase of #5501
r3184 def get_resource(resource_type):
try:
return resource.getrlimit(resource_type)
except Exception:
return 'NOT_SUPPORTED'
vcs: expose SSL certificate path over the wire to the vcsserver....
r3337 def get_cert_path(ini_path):
default = '/etc/ssl/certs/ca-certificates.crt'
control_ca_bundle = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(ini_path)))),
feat(system-info): properly report storage stats after diskcache removal
r5421 '/etc/ssl/certs/ca-certificates.crt')
vcs: expose SSL certificate path over the wire to the vcsserver....
r3337 if os.path.isfile(control_ca_bundle):
default = control_ca_bundle
return default
summary-snapshot: fix formatting of snapshot + code cleanup.
r3900
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 class SysInfoRes(object):
system-info: use safer resource.getrlimit becuase of #5501
r3184 def __init__(self, value, state=None, human_value=None):
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 self.value = value
system-info: use safer resource.getrlimit becuase of #5501
r3184 self.state = state or STATE_OK_DEFAULT
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 self.human_value = human_value or value
def __json__(self):
return {
'value': self.value,
'state': self.state,
'human_value': self.human_value,
}
sessions: added interface to show, and cleanup user auth sessions.
r1295 def get_value(self):
return self.__json__()
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def __str__(self):
modernize: python3 updates
r5096 return f'<SysInfoRes({self.__json__()})>'
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
class SysInfo(object):
def __init__(self, func_name, **kwargs):
system-info: refactor func_name to prevent refactor
r4984 self.function_name = func_name
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 self.value = _NA
self.state = None
self.kwargs = kwargs or {}
def __call__(self):
computed = self.compute(**self.kwargs)
if not isinstance(computed, SysInfoRes):
raise ValueError(
'computed value for {} is not instance of '
'{}, got {} instead'.format(
system-info: refactor func_name to prevent refactor
r4984 self.function_name, SysInfoRes, type(computed)))
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 return computed.__json__()
def __str__(self):
modernize: python3 updates
r5096 return f'<SysInfo({self.function_name})>'
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
def compute(self, **kwargs):
system-info: refactor func_name to prevent refactor
r4984 return self.function_name(**kwargs)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
# SysInfo functions
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def python_info():
system-info: optimized code based on linting
r4938 value = dict(version=f'{platform.python_version()}:{platform.python_implementation()}',
system-info: unified data structures for usage in API....
r1112 executable=sys.executable)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 return SysInfoRes(value=value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def py_modules():
packages: updated package details with location info.
r4348 mods = dict([(p.project_name, {'version': p.version, 'location': p.location})
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 for p in pkg_resources.working_set])
packages: updated package details with location info.
r4348
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 value = sorted(mods.items(), key=lambda k: k[0].lower())
return SysInfoRes(value=value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def platform_type():
system-info: drop safe_unicode usage
r5028 from rhodecode.lib.utils import generate_platform_uuid
system-info: added UUID placeholder for generating platform unique identifiers.
r1115
value = dict(
system-info: drop safe_unicode usage
r5028 name=safe_str(platform.platform()),
system-info: added UUID placeholder for generating platform unique identifiers.
r1115 uuid=generate_platform_uuid()
)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 return SysInfoRes(value=value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch default locale to the provided system info data.
r2914 def locale_info():
import locale
system-info: fixed calls to get locales on python3
r4982 def safe_get_locale(locale_name):
try:
locale.getlocale(locale_name)
except TypeError:
return f'FAILED_LOCALE_GET:{locale_name}'
system-info: fetch default locale to the provided system info data.
r2914 value = dict(
core: multiple fixes to unicode vs str usage...
r5065 locale_default=locale.getlocale(),
system-info: fixed calls to get locales on python3
r4982 locale_lc_all=safe_get_locale(locale.LC_ALL),
locale_lc_ctype=safe_get_locale(locale.LC_CTYPE),
system-info: fetch default locale to the provided system info data.
r2914 lang_env=os.environ.get('LANG'),
lc_all_env=os.environ.get('LC_ALL'),
local_archive_env=os.environ.get('LOCALE_ARCHIVE'),
)
system-info: fixed calls to get locales on python3
r4982 human_value = \
f"LANG: {value['lang_env']}, \
locale LC_ALL: {value['locale_lc_all']}, \
locale LC_CTYPE: {value['locale_lc_ctype']}, \
Default locales: {value['locale_default']}"
system-info: fetch default locale to the provided system info data.
r2914 return SysInfoRes(value=value, human_value=human_value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: added ulimit to system info.
r2673 def ulimit_info():
processes: use resources library to fetch limits in better way.
r2674 data = collections.OrderedDict([
system-info: use safer resource.getrlimit becuase of #5501
r3184 ('cpu time (seconds)', get_resource(resource.RLIMIT_CPU)),
('file size', get_resource(resource.RLIMIT_FSIZE)),
('stack size', get_resource(resource.RLIMIT_STACK)),
('core file size', get_resource(resource.RLIMIT_CORE)),
('address space size', get_resource(resource.RLIMIT_AS)),
('locked in mem size', get_resource(resource.RLIMIT_MEMLOCK)),
('heap size', get_resource(resource.RLIMIT_DATA)),
('rss size', get_resource(resource.RLIMIT_RSS)),
('number of processes', get_resource(resource.RLIMIT_NPROC)),
('open files', get_resource(resource.RLIMIT_NOFILE)),
processes: use resources library to fetch limits in better way.
r2674 ])
system-info: added ulimit to system info.
r2673
system-info: fixed iterators
r4983 text = ', '.join(f'{k}:{v}' for k, v in data.items())
system-info: added ulimit to system info.
r2673
value = {
processes: use resources library to fetch limits in better way.
r2674 'limits': data,
system-info: added ulimit to system info.
r2673 'text': text,
}
return SysInfoRes(value=value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def uptime():
from rhodecode.lib.helpers import age, time_to_datetime
system-info: fix translatio of uptime string.
r1462 from rhodecode.translation import TranslationString
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 value = dict(boot_time=0, uptime=0, text='')
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 state = STATE_OK_DEFAULT
boot_time = psutil.boot_time()
system-info: unified data structures for usage in API....
r1112 value['boot_time'] = boot_time
value['uptime'] = time.time() - boot_time
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: fix translatio of uptime string.
r1462 date_or_age = age(time_to_datetime(boot_time))
if isinstance(date_or_age, TranslationString):
date_or_age = date_or_age.interpolate()
system-info: unified data structures for usage in API....
r1112 human_value = value.copy()
human_value['boot_time'] = time_to_datetime(boot_time)
human_value['uptime'] = age(time_to_datetime(boot_time), show_suffix=False)
system-info: fix unicode problem on translation
r1308
modernize: python3 updates
r5096 human_value['text'] = f'Server started {date_or_age}'
system-info: unified data structures for usage in API....
r1112 return SysInfoRes(value=value, human_value=human_value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def memory():
from rhodecode.lib.helpers import format_byte_size_binary
system-info: use real memory usage based on new psutil api available from 4.0 release....
r1116 value = dict(available=0, used=0, used_real=0, cached=0, percent=0,
percent_used=0, free=0, inactive=0, active=0, shared=0,
total=0, buffers=0, text='')
system-info: unified data structures for usage in API....
r1112
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 state = STATE_OK_DEFAULT
system-info: unified data structures for usage in API....
r1112 value.update(dict(psutil.virtual_memory()._asdict()))
system-info: use real memory usage based on new psutil api available from 4.0 release....
r1116 value['used_real'] = value['total'] - value['available']
code: import fix/pep8
r5178 value['percent_used'] = psutil._common.usage_percent(value['used_real'], value['total'], 1)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 human_value = value.copy()
modernize: python3 updates
r5096 human_value['text'] = '{}/{}, {}% used'.format(
system-info: use real memory usage based on new psutil api available from 4.0 release....
r1116 format_byte_size_binary(value['used_real']),
system-info: unified data structures for usage in API....
r1112 format_byte_size_binary(value['total']),
modernize: python3 updates
r5096 value['percent_used'])
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: optimized code based on linting
r4938 keys = list(value.keys())[::]
system-info: unified data structures for usage in API....
r1112 keys.pop(keys.index('percent'))
keys.pop(keys.index('percent_used'))
keys.pop(keys.index('text'))
for k in keys:
human_value[k] = format_byte_size_binary(value[k])
if state['type'] == STATE_OK and value['percent_used'] > 90:
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 msg = 'Critical: your available RAM memory is very low.'
state = {'message': msg, 'type': STATE_ERR}
system-info: unified data structures for usage in API....
r1112 elif state['type'] == STATE_OK and value['percent_used'] > 70:
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 msg = 'Warning: your available RAM memory is running low.'
state = {'message': msg, 'type': STATE_WARN}
system-info: unified data structures for usage in API....
r1112 return SysInfoRes(value=value, state=state, human_value=human_value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def machine_load():
system-info: optimized code based on linting
r4938 value = {'1_min': _NA_FLOAT, '5_min': _NA_FLOAT, '15_min': _NA_FLOAT, 'text': ''}
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 state = STATE_OK_DEFAULT
# load averages
if hasattr(psutil.os, 'getloadavg'):
system-info: unified data structures for usage in API....
r1112 value.update(dict(
system-info: fixed iterators
r4983 list(zip(['1_min', '5_min', '15_min'], psutil.os.getloadavg()))
system-info: optimized code based on linting
r4938 ))
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 human_value = value.copy()
human_value['text'] = '1min: {}, 5min: {}, 15min: {}'.format(
value['1_min'], value['5_min'], value['15_min'])
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: optimized code based on linting
r4938 if state['type'] == STATE_OK and value['15_min'] > 5.0:
system-info: unified data structures for usage in API....
r1112 msg = 'Warning: your machine load is very high.'
state = {'message': msg, 'type': STATE_WARN}
return SysInfoRes(value=value, state=state, human_value=human_value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def cpu():
system-info: added more details about CPU.
r1464 value = {'cpu': 0, 'cpu_count': 0, 'cpu_usage': []}
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 state = STATE_OK_DEFAULT
system-info: unified data structures for usage in API....
r1112
system-info: added more details about CPU.
r1464 value['cpu'] = psutil.cpu_percent(0.5)
value['cpu_usage'] = psutil.cpu_percent(0.5, percpu=True)
value['cpu_count'] = psutil.cpu_count()
human_value = value.copy()
feat(system-info): properly report storage stats after diskcache removal
r5421 human_value['text'] = f'{value["cpu_count"]} cores at {value["cpu"]} %'
system-info: added more details about CPU.
r1464
system-info: unified data structures for usage in API....
r1112 return SysInfoRes(value=value, state=state, human_value=human_value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def storage():
from rhodecode.lib.helpers import format_byte_size_binary
feat(repo_path-config): moved main storage location path into ini file. Fixes: RCCE-61
r5356 from rhodecode.lib.utils import get_rhodecode_repo_store_path
path = get_rhodecode_repo_store_path()
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 value = dict(percent=0, used=0, total=0, path=path, text='')
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 state = STATE_OK_DEFAULT
try:
system-info: unified data structures for usage in API....
r1112 value.update(dict(psutil.disk_usage(path)._asdict()))
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 except Exception as e:
log.exception('Failed to fetch disk info')
state = {'message': str(e), 'type': STATE_ERR}
system-info: unified data structures for usage in API....
r1112 human_value = value.copy()
human_value['used'] = format_byte_size_binary(value['used'])
human_value['total'] = format_byte_size_binary(value['total'])
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 human_value['text'] = "{}/{}, {}% used".format(
system-info: unified data structures for usage in API....
r1112 format_byte_size_binary(value['used']),
format_byte_size_binary(value['total']),
value['percent'])
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 if state['type'] == STATE_OK and value['percent'] > 90:
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 msg = 'Critical: your disk space is very low.'
state = {'message': msg, 'type': STATE_ERR}
system-info: unified data structures for usage in API....
r1112 elif state['type'] == STATE_OK and value['percent'] > 70:
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 msg = 'Warning: your disk space is running low.'
state = {'message': msg, 'type': STATE_WARN}
system-info: unified data structures for usage in API....
r1112 return SysInfoRes(value=value, state=state, human_value=human_value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def storage_inodes():
feat(repo_path-config): moved main storage location path into ini file. Fixes: RCCE-61
r5356 from rhodecode.lib.utils import get_rhodecode_repo_store_path
path = get_rhodecode_repo_store_path()
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: optimized code based on linting
r4938 value = dict(percent=0.0, free=0, used=0, total=0, path=path, text='')
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 state = STATE_OK_DEFAULT
try:
i_stat = os.statvfs(path)
system-info: fixed reporting of inodes.
r1219 value['free'] = i_stat.f_ffree
value['used'] = i_stat.f_files-i_stat.f_favail
system-info: unified data structures for usage in API....
r1112 value['total'] = i_stat.f_files
system-info: fix display of text in system inodes.
r1155 value['percent'] = percentage(value['used'], value['total'])
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 except Exception as e:
log.exception('Failed to fetch disk inodes info')
state = {'message': str(e), 'type': STATE_ERR}
system-info: unified data structures for usage in API....
r1112 human_value = value.copy()
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 human_value['text'] = "{}/{}, {}% used".format(
system-info: unified data structures for usage in API....
r1112 value['used'], value['total'], value['percent'])
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 if state['type'] == STATE_OK and value['percent'] > 90:
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 msg = 'Critical: your disk free inodes are very low.'
state = {'message': msg, 'type': STATE_ERR}
system-info: unified data structures for usage in API....
r1112 elif state['type'] == STATE_OK and value['percent'] > 70:
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 msg = 'Warning: your disk free inodes are running low.'
state = {'message': msg, 'type': STATE_WARN}
system-info: fix display of text in system inodes.
r1155 return SysInfoRes(value=value, state=state, human_value=human_value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
feat(artifacts): new artifact storage engines allowing an s3 based uploads
r5516 def storage_artifacts():
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 import rhodecode
from rhodecode.lib.helpers import format_byte_size_binary
feat(archive-cache): implemented s3 based backend for filecaches
r5433 from rhodecode.lib.archive_cache import get_archival_cache_store
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
feat(artifacts): new artifact storage engines allowing an s3 based uploads
r5516 backend_type = rhodecode.ConfigGet().get_str('archive_cache.backend.type')
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420
feat(artifacts): new artifact storage engines allowing an s3 based uploads
r5516 value = dict(percent=0, used=0, total=0, items=0, path='', text='', type=backend_type)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 state = STATE_OK_DEFAULT
try:
feat(archive-cache): implemented s3 based backend for filecaches
r5433 d_cache = get_archival_cache_store(config=rhodecode.CONFIG)
feat(artifacts): new artifact storage engines allowing an s3 based uploads
r5516 backend_type = str(d_cache)
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420
feat(archive-cache): implemented s3 based backend for filecaches
r5433 total_files, total_size, _directory_stats = d_cache.get_statistics()
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 value.update({
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 'percent': 100,
feat(system-info): properly report storage stats after diskcache removal
r5421 'used': total_size,
'total': total_size,
feat(archive-cache): implemented s3 based backend for filecaches
r5433 'items': total_files,
feat(artifacts): new artifact storage engines allowing an s3 based uploads
r5516 'path': d_cache.storage_path,
'type': backend_type
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 })
except Exception as e:
log.exception('failed to fetch archive cache storage')
state = {'message': str(e), 'type': STATE_ERR}
system-info: unified data structures for usage in API....
r1112 human_value = value.copy()
human_value['used'] = format_byte_size_binary(value['used'])
human_value['total'] = format_byte_size_binary(value['total'])
feat(artifacts): new artifact storage engines allowing an s3 based uploads
r5516 human_value['text'] = f"{human_value['used']} ({value['items']} items)"
return SysInfoRes(value=value, state=state, human_value=human_value)
@register_sysinfo
def storage_archives():
import rhodecode
from rhodecode.lib.helpers import format_byte_size_binary
import rhodecode.apps.file_store.utils as store_utils
from rhodecode import CONFIG
backend_type = rhodecode.ConfigGet().get_str(store_utils.config_keys.backend_type)
value = dict(percent=0, used=0, total=0, items=0, path='', text='', type=backend_type)
state = STATE_OK_DEFAULT
try:
f_store = store_utils.get_filestore_backend(config=CONFIG)
backend_type = str(f_store)
total_files, total_size, _directory_stats = f_store.get_statistics()
value.update({
'percent': 100,
'used': total_size,
'total': total_size,
'items': total_files,
'path': f_store.storage_path,
'type': backend_type
})
except Exception as e:
log.exception('failed to fetch archive cache storage')
state = {'message': str(e), 'type': STATE_ERR}
human_value = value.copy()
human_value['used'] = format_byte_size_binary(value['used'])
human_value['total'] = format_byte_size_binary(value['total'])
human_value['text'] = f"{human_value['used']} ({value['items']} items)"
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 return SysInfoRes(value=value, state=state, human_value=human_value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def storage_gist():
from rhodecode.model.gist import GIST_STORE_LOC
feat(repo_path-config): moved main storage location path into ini file. Fixes: RCCE-61
r5356 from rhodecode.lib.utils import safe_str, get_rhodecode_repo_store_path
feat(archive-cache): implemented s3 based backend for filecaches
r5433 from rhodecode.lib.helpers import format_byte_size_binary, get_directory_statistics
feat(system-info): properly report storage stats after diskcache removal
r5421
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 path = safe_str(os.path.join(
feat(repo_path-config): moved main storage location path into ini file. Fixes: RCCE-61
r5356 get_rhodecode_repo_store_path(), GIST_STORE_LOC))
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
# gist storage
system-info: unified data structures for usage in API....
r1112 value = dict(percent=0, used=0, total=0, items=0, path=path, text='')
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 state = STATE_OK_DEFAULT
try:
feat(system-info): properly report storage stats after diskcache removal
r5421 total_files, total_size, _directory_stats = get_directory_statistics(path)
system-info: unified data structures for usage in API....
r1112 value.update({
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 'percent': 100,
feat(system-info): properly report storage stats after diskcache removal
r5421 'used': total_size,
'total': total_size,
'items': total_files
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 })
except Exception as e:
log.exception('failed to fetch gist storage items')
state = {'message': str(e), 'type': STATE_ERR}
system-info: unified data structures for usage in API....
r1112 human_value = value.copy()
human_value['used'] = format_byte_size_binary(value['used'])
human_value['total'] = format_byte_size_binary(value['total'])
human_value['text'] = "{} ({} items)".format(
human_value['used'], value['items'])
return SysInfoRes(value=value, state=state, human_value=human_value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: added info about temporary storage....
r1124 def storage_temp():
import tempfile
from rhodecode.lib.helpers import format_byte_size_binary
path = tempfile.gettempdir()
value = dict(percent=0, used=0, total=0, items=0, path=path, text='')
state = STATE_OK_DEFAULT
if not psutil:
return SysInfoRes(value=value, state=state)
try:
value.update(dict(psutil.disk_usage(path)._asdict()))
except Exception as e:
log.exception('Failed to fetch temp dir info')
state = {'message': str(e), 'type': STATE_ERR}
human_value = value.copy()
human_value['used'] = format_byte_size_binary(value['used'])
human_value['total'] = format_byte_size_binary(value['total'])
human_value['text'] = "{}/{}, {}% used".format(
format_byte_size_binary(value['used']),
format_byte_size_binary(value['total']),
value['percent'])
return SysInfoRes(value=value, state=state, human_value=human_value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: unified data structures for usage in API....
r1112 def search_info():
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 import rhodecode
system-info: unified data structures for usage in API....
r1112 from rhodecode.lib.index import searcher_from_config
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 backend = rhodecode.CONFIG.get('search.module', '')
location = rhodecode.CONFIG.get('search.location', '')
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 try:
system-info: unified data structures for usage in API....
r1112 searcher = searcher_from_config(rhodecode.CONFIG)
searcher = searcher.__class__.__name__
except Exception:
searcher = None
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 value = dict(
backend=backend, searcher=searcher, location=location, text='')
state = STATE_OK_DEFAULT
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 human_value = value.copy()
human_value['text'] = "backend:`{}`".format(human_value['backend'])
return SysInfoRes(value=value, state=state, human_value=human_value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def git_info():
from rhodecode.lib.vcs.backends import git
state = STATE_OK_DEFAULT
value = human_value = ''
try:
value = git.discover_git_version(raise_on_exc=True)
modernize: python3 updates
r5096 human_value = f'version reported from VCSServer: {value}'
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 except Exception as e:
state = {'message': str(e), 'type': STATE_ERR}
return SysInfoRes(value=value, state=state, human_value=human_value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def hg_info():
from rhodecode.lib.vcs.backends import hg
state = STATE_OK_DEFAULT
value = human_value = ''
try:
value = hg.discover_hg_version(raise_on_exc=True)
modernize: python3 updates
r5096 human_value = f'version reported from VCSServer: {value}'
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 except Exception as e:
state = {'message': str(e), 'type': STATE_ERR}
return SysInfoRes(value=value, state=state, human_value=human_value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def svn_info():
from rhodecode.lib.vcs.backends import svn
state = STATE_OK_DEFAULT
value = human_value = ''
try:
value = svn.discover_svn_version(raise_on_exc=True)
modernize: python3 updates
r5096 human_value = f'version reported from VCSServer: {value}'
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 except Exception as e:
state = {'message': str(e), 'type': STATE_ERR}
return SysInfoRes(value=value, state=state, human_value=human_value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def vcs_backends():
import rhodecode
system-info: fix reading backends from config....
r2314 value = rhodecode.CONFIG.get('vcs.backends')
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 human_value = 'Enabled backends in order: {}'.format(','.join(value))
return SysInfoRes(value=value, human_value=human_value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def vcs_server():
import rhodecode
system-info: expose workers of vcsserver in system info data.
r1465 from rhodecode.lib.vcs.backends import get_vcsserver_service_data
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
server_url = rhodecode.CONFIG.get('vcs.server')
enabled = rhodecode.CONFIG.get('vcs.server.enable')
system-info: indicate http mode is default when not set inside config.
r1182 protocol = rhodecode.CONFIG.get('vcs.server.protocol') or 'http'
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 state = STATE_OK_DEFAULT
version = None
system-info: expose workers of vcsserver in system info data.
r1465 workers = 0
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
try:
system-info: expose workers of vcsserver in system info data.
r1465 data = get_vcsserver_service_data()
if data and 'version' in data:
version = data['version']
if data and 'config' in data:
conf = data['config']
system-info: show better message when cannot fetch info about gunicorn workers
r1576 workers = conf.get('workers', 'NOT AVAILABLE')
system-info: expose workers of vcsserver in system info data.
r1465
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 connection = 'connected'
except Exception as e:
connection = 'failed'
state = {'message': str(e), 'type': STATE_ERR}
value = dict(
url=server_url,
enabled=enabled,
protocol=protocol,
connection=connection,
version=version,
text='',
)
system-info: unified data structures for usage in API....
r1112 human_value = value.copy()
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 human_value['text'] = \
system-info: expose workers of vcsserver in system info data.
r1465 '{url}@ver:{ver} via {mode} mode[workers:{workers}], connection:{conn}'.format(
url=server_url, ver=version, workers=workers, mode=protocol,
conn=connection)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 return SysInfoRes(value=value, state=state, human_value=human_value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
dan
system-info: expose data about vcsserver.
r3943 def vcs_server_config():
from rhodecode.lib.vcs.backends import get_vcsserver_service_data
state = STATE_OK_DEFAULT
value = {}
try:
data = get_vcsserver_service_data()
value = data['app_config']
except Exception as e:
state = {'message': str(e), 'type': STATE_ERR}
human_value = value.copy()
human_value['text'] = 'VCS Server config'
return SysInfoRes(value=value, state=state, human_value=human_value)
feat(system-info): expose rhodecode config for better visibility of set settings
r5552 @register_sysinfo
def rhodecode_server_config():
import rhodecode
state = STATE_OK_DEFAULT
config = rhodecode.CONFIG.copy()
secrets_lits = [
f'rhodecode_{LicenseModel.LICENSE_DB_KEY}',
'sqlalchemy.db1.url',
'channelstream.secret',
'beaker.session.secret',
'rhodecode.encrypted_values.secret',
'appenlight.api_key',
'smtp_password',
'file_store.objectstore.secret',
'archive_cache.objectstore.secret',
'app.service_api.token',
]
for k in secrets_lits:
if k in config:
config[k] = '**OBFUSCATED**'
value = human_value = config
return SysInfoRes(value=value, state=state, human_value=human_value)
dan
system-info: expose data about vcsserver.
r3943
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def rhodecode_app_info():
import rhodecode
system-info: add edition type into app info.
r1113 edition = rhodecode.CONFIG.get('rhodecode.edition')
system-info: unified data structures for usage in API....
r1112 value = dict(
rhodecode_version=rhodecode.__version__,
system-info: add edition type into app info.
r1113 rhodecode_lib_path=os.path.abspath(rhodecode.__file__),
text=''
system-info: unified data structures for usage in API....
r1112 )
system-info: add edition type into app info.
r1113 human_value = value.copy()
human_value['text'] = 'RhodeCode {edition}, version {ver}'.format(
edition=edition, ver=value['rhodecode_version']
)
return SysInfoRes(value=value, human_value=human_value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def rhodecode_config():
import rhodecode
path = rhodecode.CONFIG.get('__file__')
rhodecode_ini_safe = rhodecode.CONFIG.copy()
vcs: expose SSL certificate path over the wire to the vcsserver....
r3337 cert_path = get_cert_path(path)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: added info about workers and worker type.
r1463 try:
system-info: expose workers of vcsserver in system info data.
r1465 config = configparser.ConfigParser()
system-info: added info about workers and worker type.
r1463 config.read(path)
parsed_ini = config
if parsed_ini.has_section('server:main'):
parsed_ini = dict(parsed_ini.items('server:main'))
except Exception:
log.exception('Failed to read .ini file for display')
parsed_ini = {}
rhodecode_ini_safe['server:main'] = parsed_ini
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 blacklist = [
tests: fixup the config stubs
r5145 f'rhodecode_{LicenseModel.LICENSE_DB_KEY}',
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 'routes.map',
'sqlalchemy.db1.url',
'channelstream.secret',
'beaker.session.secret',
'rhodecode.encrypted_values.secret',
'rhodecode_auth_github_consumer_key',
'rhodecode_auth_github_consumer_secret',
'rhodecode_auth_google_consumer_key',
'rhodecode_auth_google_consumer_secret',
'rhodecode_auth_bitbucket_consumer_secret',
'rhodecode_auth_bitbucket_consumer_key',
'rhodecode_auth_twitter_consumer_secret',
'rhodecode_auth_twitter_consumer_key',
'rhodecode_auth_twitter_secret',
'rhodecode_auth_github_secret',
'rhodecode_auth_google_secret',
'rhodecode_auth_bitbucket_secret',
'appenlight.api_key',
('app_conf', 'sqlalchemy.db1.url')
]
for k in blacklist:
if isinstance(k, tuple):
section, key = k
if section in rhodecode_ini_safe:
rhodecode_ini_safe[section] = '**OBFUSCATED**'
else:
rhodecode_ini_safe.pop(k, None)
# TODO: maybe put some CONFIG checks here ?
system-info: expose the common certificate file path.
r1729 return SysInfoRes(value={'config': rhodecode_ini_safe,
'path': path, 'cert_path': cert_path})
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def database_info():
import rhodecode
from sqlalchemy.engine import url as engine_url
core: multiple fixes to unicode vs str usage...
r5065 from rhodecode.model import meta
from rhodecode.model.meta import Session
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 from rhodecode.model.db import DbMigrateVersion
state = STATE_OK_DEFAULT
db_migrate = DbMigrateVersion.query().filter(
DbMigrateVersion.repository_id == 'rhodecode_db_migrations').one()
db_url_obj = engine_url.make_url(rhodecode.CONFIG['sqlalchemy.db1.url'])
try:
core: multiple fixes to unicode vs str usage...
r5065 engine = meta.get_engine()
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 db_server_info = engine.dialect._get_server_version_info(
Session.connection(bind=engine))
db_version = '.'.join(map(str, db_server_info))
except Exception:
log.exception('failed to fetch db version')
db_version = 'UNKNOWN'
db_info = dict(
migrate_version=db_migrate.version,
type=db_url_obj.get_backend_name(),
version=db_version,
url=repr(db_url_obj)
)
system-info: detect database migration errors.
r1575 current_version = db_migrate.version
expected_version = rhodecode.__dbversion__
if state['type'] == STATE_OK and current_version != expected_version:
msg = 'Critical: database schema mismatch, ' \
'expected version {}, got {}. ' \
'Please run migrations on your database.'.format(
expected_version, current_version)
state = {'message': msg, 'type': STATE_ERR}
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 human_value = db_info.copy()
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 human_value['url'] = "{} @ migration version: {}".format(
db_info['url'], db_info['migrate_version'])
human_value['version'] = "{} {}".format(db_info['type'], db_info['version'])
return SysInfoRes(value=db_info, state=state, human_value=human_value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def server_info(environ):
import rhodecode
from rhodecode.lib.base import get_server_ip_addr, get_server_port
value = {
modernize: python3 updates
r5096 'server_ip': '{}:{}'.format(
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 get_server_ip_addr(environ, log_errors=False),
get_server_port(environ)
),
'server_id': rhodecode.CONFIG.get('instance_id'),
}
return SysInfoRes(value=value)
sys-info: added helpers for faster loading of sys-info data
r4734 @register_sysinfo
system-info: added usage info.
r1391 def usage_info():
code: import fix/pep8
r5178 from rhodecode.model.db import User, Repository, true
system-info: added usage info.
r1391 value = {
'users': User.query().count(),
code: import fix/pep8
r5178 'users_active': User.query().filter(User.active == true()).count(),
system-info: added usage info.
r1391 'repositories': Repository.query().count(),
'repository_types': {
'hg': Repository.query().filter(
Repository.repo_type == 'hg').count(),
'git': Repository.query().filter(
Repository.repo_type == 'git').count(),
'svn': Repository.query().filter(
Repository.repo_type == 'svn').count(),
},
}
return SysInfoRes(value=value)
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 def get_system_info(environ):
environ = environ or {}
return {
'rhodecode_app': SysInfo(rhodecode_app_info)(),
'rhodecode_config': SysInfo(rhodecode_config)(),
system-info: added usage info.
r1391 'rhodecode_usage': SysInfo(usage_info)(),
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 'python': SysInfo(python_info)(),
'py_modules': SysInfo(py_modules)(),
'platform': SysInfo(platform_type)(),
system-info: fetch default locale to the provided system info data.
r2914 'locale': SysInfo(locale_info)(),
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 'server': SysInfo(server_info, environ=environ)(),
'database': SysInfo(database_info)(),
system-info: added ulimit to system info.
r2673 'ulimit': SysInfo(ulimit_info)(),
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 'storage': SysInfo(storage)(),
'storage_inodes': SysInfo(storage_inodes)(),
'storage_archive': SysInfo(storage_archives)(),
feat(artifacts): new artifact storage engines allowing an s3 based uploads
r5516 'storage_artifacts': SysInfo(storage_artifacts)(),
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 'storage_gist': SysInfo(storage_gist)(),
system-info: added info about temporary storage....
r1124 'storage_temp': SysInfo(storage_temp)(),
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111
system-info: unified data structures for usage in API....
r1112 'search': SysInfo(search_info)(),
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 'uptime': SysInfo(uptime)(),
'load': SysInfo(machine_load)(),
'cpu': SysInfo(cpu)(),
'memory': SysInfo(memory)(),
'vcs_backends': SysInfo(vcs_backends)(),
'vcs_server': SysInfo(vcs_server)(),
dan
system-info: expose data about vcsserver.
r3943 'vcs_server_config': SysInfo(vcs_server_config)(),
feat(system-info): expose rhodecode config for better visibility of set settings
r5552 'rhodecode_server_config': SysInfo(rhodecode_server_config)(),
dan
system-info: expose data about vcsserver.
r3943
system-info: fetch vcs settings from vcsserver. Fixes #4276...
r1111 'git': SysInfo(git_info)(),
'hg': SysInfo(hg_info)(),
'svn': SysInfo(svn_info)(),
}
sys-info: added helpers for faster loading of sys-info data
r4734
def load_system_info(key):
"""
get_sys_info('vcs_server')
get_sys_info('database')
"""
return SysInfo(registered_helpers[key])()