Docker http api 没有 percpu_usage 了??

已解决,current_stats 直接输入 container stats 返回的数据即可

# 计算 CPU 占用

previous_cpu = 0
previous_system = 0

def calculate_cpu_percent(previous_cpu, previous_system, current_stats):
    cpu_percent = 0.0
    cpu_delta = float(current_stats['cpu_stats']['cpu_usage']['total_usage']) - float(previous_cpu)
    system_delta = float(current_stats['cpu_stats']['system_cpu_usage']) - float(previous_system)
    online_cpus = float(current_stats['cpu_stats']['online_cpus'])

    if online_cpus == 0.0:
        online_cpus = len(current_stats['cpu_stats']['cpu_usage'].get('percpu_usage', []))
    if system_delta > 0.0 and cpu_delta > 0.0:
        cpu_percent = (cpu_delta / system_delta) * online_cpus * 100.0
    return cpu_percent