Beispiel #1
0
def _get_ffmpeg_process_data(
        container: docker.models.containers.Container) -> (str, str):
    """
    returned pid, cpu usage
    """
    top = []
    empty_result = '', ''
    if container.status != 'running':
        return empty_result
    try:
        # [ (pid, cmd), (pid, cmd), .. ]
        top = container.top(ps_args='-eo pid,comm,pcpu')
    except docker.errors.APIError:
        logger.error("Error while trying get container top.\n" +
                     traceback.format_exc())
        return empty_result
    if not top or 'Processes' not in top:
        logger.warning(
            f"Warning. Top is empty  or format is wrong. container:'{container.name}', top: {top}"
        )
        return empty_result
    try:
        top = top['Processes']
        for pid, cmd, pcpu in top:
            if 'ffmpeg' in cmd:
                return pid, pcpu
        return empty_result
    except ValueError:
        logger.warning(
            f"Warning. Format of top is wrong.container:'{container.name}', top: {top}"
        )
        logger.warning(traceback.format_exc())
        return empty_result
Beispiel #2
0
def container_pid(c: docker.models.containers.Container) -> int:
    """
	returns PID of `c` according in the host namespace
	"""
    return int(c.top()["Processes"][0][1])