# HG changeset patch # User Marcin Kuzminski # Date 2018-04-02 17:29:51 # Node ID c19b5f3260965cb53123705a86bc91753b481981 # Parent 4b2a46a3a04c84ad864640de36e3e9bc455622af processes: use resources library to fetch limits in better way. diff --git a/rhodecode/lib/system_info.py b/rhodecode/lib/system_info.py --- a/rhodecode/lib/system_info.py +++ b/rhodecode/lib/system_info.py @@ -23,9 +23,10 @@ import os import sys import time import platform -import subprocess32 +import collections import pkg_resources import logging +import resource from pyramid.compat import configparser @@ -142,23 +143,23 @@ def platform_type(): def ulimit_info(): - data = {} + data = collections.OrderedDict([ + ('cpu time (seconds)', resource.getrlimit(resource.RLIMIT_CPU)), + ('file size', resource.getrlimit(resource.RLIMIT_FSIZE)), + ('stack size', resource.getrlimit(resource.RLIMIT_STACK)), + ('core file size', resource.getrlimit(resource.RLIMIT_CORE)), + ('address space size', resource.getrlimit(resource.RLIMIT_AS)), + ('locked in mem size', resource.getrlimit(resource.RLIMIT_MEMLOCK)), + ('heap size', resource.getrlimit(resource.RLIMIT_DATA)), + ('rss size', resource.getrlimit(resource.RLIMIT_RSS)), + ('number of processes', resource.getrlimit(resource.RLIMIT_NPROC)), + ('open files', resource.getrlimit(resource.RLIMIT_NOFILE)), + ]) - text = 'ulimit -a unavailable' - try: - result = subprocess32.check_output( - ['ulimit -a'], timeout=10, stderr=subprocess32.STDOUT, - shell=True) - - for line in result.splitlines(): - key, val = line.split(' ', 1) - data[key.strip()] = val.strip() - text = ', '.join('{}:{}'.format(k,v) for k,v in data.items()) - except Exception: - log.exception('ulimit check problem') + text = ', '.join('{}:{}'.format(k,v) for k,v in data.items()) value = { - 'ulimit': data, + 'limits': data, 'text': text, } return SysInfoRes(value=value)