<commit_before>import os
import json
import psutil
from notebook.utils import url_path_join
from notebook.base.handlers import IPythonHandler

def get_metrics():
    cur_process = psutil.Process()
    all_processes = [cur_process] + cur_process.children(recursive=True)
    rss = sum([p.memory_info().rss for p in all_processes])
    return {
        'rss': rss,
        'limits': {
            'memory': int(os.environ.get('MEM_LIMIT', None))
        }
    }


class MetricsHandler(IPythonHandler):
    def get(self):
        self.finish(json.dumps(get_metrics()))


def setup_handlers(web_app):
    route_pattern = url_path_join(web_app.settings['base_url'], '/metrics')
    web_app.add_handlers('.*', [(route_pattern, MetricsHandler)])<commit_msg>Handle case of memory limit not set.<commit_after>import os
import json
import psutil
from notebook.utils import url_path_join
from notebook.base.handlers import IPythonHandler

def get_metrics():
    cur_process = psutil.Process()
    all_processes = [cur_process] + cur_process.children(recursive=True)
    rss = sum([p.memory_info().rss for p in all_processes])
    mem_limit = os.environ.get('MEM_LIMIT', None)
    if mem_limit is not None:
        mem_limit = int(mem_limit)
    return {
        'rss': rss,
        'limits': {
            'memory': mem_limit
        }
    }


class MetricsHandler(IPythonHandler):
    def get(self):
        self.finish(json.dumps(get_metrics()))


def setup_handlers(web_app):
    route_pattern = url_path_join(web_app.settings['base_url'], '/metrics')
    web_app.add_handlers('.*', [(route_pattern, MetricsHandler)])
{'fraction_non_alphanumeric': 0.12057178371659416, 'fraction_numerical': 0.0, 'mean_word_length': 3.777448071216617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2089585', 'n_tokens_mistral': 528, 'n_tokens_neox': 523, 'n_words': 108}