<commit_before>from flask import Blueprint
from ipynbsrv.hostapi.http.responses import success_ok
import psutil


"""
Flask blueprint collecting the /health routes.
"""
blueprint = Blueprint('health', __name__, url_prefix='/health')


@blueprint.route('', methods=['GET'])
def get_health():
    """
    Return the node's health (report).

    The main application is querying this entry-point from time to time to determinate
    either the node is still up (and healthy) or if it has problems.

    TODO: return general health information (e.g. OK, out of memory), container backend (is running),
          diskspace etc.
    """
    return success_ok({
        'backends': {
            'container': {
                'status': "OK"
            }
        },
        'resources': {
            'cpu': {
                'count': psutil.cpu_count(),
                'usage': psutil.cpu_percent()
            },
            'disk': psutil.disk_usage('/').__dict__,
            'memory': psutil.virtual_memory().__dict__,
            'swap': psutil.swap_memory().__dict__
        }
    })
<commit_msg>get the container_backend's status from the backend itself<commit_after>from flask import Blueprint
from ipynbsrv.hostapi import config
from ipynbsrv.hostapi.http.responses import success_ok
import psutil


"""
Flask blueprint collecting the /health routes.
"""
blueprint = Blueprint('health', __name__, url_prefix='/health')


@blueprint.route('', methods=['GET'])
def get_health():
    """
    Return the node's health (report).

    The main application is querying this entry-point from time to time to determinate
    either the node is still up (and healthy) or if it has problems.

    TODO: return general health information (e.g. OK, out of memory), container backend (is running),
          diskspace etc.
    """
    return success_ok({
        'backends': {
            'container': {
                'status': config.container_backend.get_status()
            }
        },
        'resources': {
            'cpu': {
                'count': psutil.cpu_count(),
                'usage': psutil.cpu_percent()
            },
            'disk': psutil.disk_usage('/').__dict__,
            'memory': psutil.virtual_memory().__dict__,
            'swap': psutil.swap_memory().__dict__
        }
    })

{'fraction_non_alphanumeric': 0.11861471861471862, 'fraction_numerical': 0.0, 'mean_word_length': 2.3541364296081277, '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': '4141665', 'n_tokens_mistral': 648, 'n_tokens_neox': 636, 'n_words': 189}