如何使用python docker获取容器统计信息

2024-04-18 22:23:17 发布

您现在位置:Python中文网/ 问答频道 /正文

在运行容器后,我试图在python代码中获取docker容器的统计信息,如下所示。我指的是python docker SDkhttps://docker-py.readthedocs.io/en/stable/index.html来运行并获取容器的详细信息

container = docker_client.containers.run(image = image,entrypoint = entrypoint,detach=True,tty=False,volumes = {FILE_PATH+input_file:{'bind': '/src/input.txt', 'mode': 'rw'}})
container.wait()
data = container.stats(stream=False)

正在获取的统计数据没有内存,其他细节也很少。以下是详细的统计数据

{
  'read': '0001-01-01T00:00:00Z',
  'preread': '2020-04-21T10:07:54.773647854Z',
  'pids_stats': {

  },
  'blkio_stats': {
    'io_service_bytes_recursive': None,
    'io_serviced_recursive': None,
    'io_queue_recursive': None,
    'io_service_time_recursive': None,
    'io_wait_time_recursive': None,
    'io_merged_recursive': None,
    'io_time_recursive': None,
    'sectors_recursive': None
  },
  'num_procs': 0,
  'storage_stats': {

  },
  'cpu_stats': {
    'cpu_usage': {
      'total_usage': 0,
      'usage_in_kernelmode': 0,
      'usage_in_usermode': 0
    },
    'throttling_data': {
      'periods': 0,
      'throttled_periods': 0,
      'throttled_time': 0
    }
  },
  'precpu_stats': {
    'cpu_usage': {
      'total_usage': 208804435,
      'percpu_usage': [
        2260663,
        0,
        0,
        7976886,
        0,
        2549616,
        178168661,
        1717192,
        117608,
        0,
        1011534,
        3305192,
        0,
        11372783,
        0,
        324300
      ],
      'usage_in_kernelmode': 20000000,
      'usage_in_usermode': 160000000
    },
    'system_cpu_usage': 98001601690000000,
    'online_cpus': 16,
    'throttling_data': {
      'periods': 0,
      'throttled_periods': 0,
      'throttled_time': 0
    }
  },
  'memory_stats': {

  },
  'name': '/quizzical_mcclintock',
  'id': '4bb79d8468f2f91a91022b4a7086744a6b3cdefab2a98f7efa178c9aff7ed246'
}

如何使用python docker SDK正确获取所有统计信息


Tags: dockeriniononedatatimecontainerstats