Я могу получить использование сетевого ресурса контейнера docker через поле networks
в docker SDK для python в Ubuntu. Однако, поскольку проекту необходимо было перенести его в centos, было обнаружено, что он не удалось получить networks
контейнера.
docker sdk для python версии
docker==4.1.0
centos
версия хоста
# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.5.1804 (Core)
Release: 7.5.1804
Codename: Core
сентос docker версия
# docker version
Client:
Version: 17.12.1-ce
API version: 1.35
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:15:20 2018
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.1-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:17:54 2018
OS/Arch: linux/amd64
Experimental: false
docker версия
# docker version
Client:
Version: 17.12.1-ce
API version: 1.35
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:15:20 2018
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.1-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:17:54 2018
OS/Arch: linux/amd64
Experimental: false
python код
docker sdk for python
import docker
client = docker.from_env()
stats = container.stats(stream=False)
print(stats)
print(str(list(stats['networks'].values())[0]['rx_bytes']))
стандартный вывод
{'read': '2020-03-30T13:22:01.786097801Z', 'preread': '2020-03-30T13:22:00.786132317Z',
'pids_stats': {'current': 10}, 'blkio_stats': {'io_service_bytes_recursive': [], 'io_serviced_recursive': [],
'io_queue_recursive': [], 'io_service_time_recursive': [], 'io_wait_time_recursive': [],
'io_merged_recursive': [], 'io_time_recursive': [], 'sectors_recursive': []}, 'num_procs': 0, 'storage_stats':
{}, 'cpu_stats': {'cpu_usage': {'total_usage': 1364516186, 'percpu_usage': [65757133, 62557842,
66162812, 382085241, 167700841, 436523454, 119855237, 63873626], 'usage_in_kernelmode':
400000000, 'usage_in_usermode': 850000000}, 'system_cpu_usage': 2370139470000000,
'online_cpus': 8, 'throttling_data': {'periods': 0, 'throttled_periods': 0, 'throttled_time': 0}},
'precpu_stats': {'cpu_usage': {'total_usage': 1364424315, 'percpu_usage': [65665262, 62557842,
66162812, 382085241, 167700841, 436523454, 119855237, 63873626], 'usage_in_kernelmode':
400000000, 'usage_in_usermode': 850000000}, 'system_cpu_usage': 2370131490000000,
'online_cpus': 8, 'throttling_data': {'periods': 0, 'throttled_periods': 0, 'throttled_time': 0}},
'memory_stats': {'usage': 75448320, 'max_usage': 76050432, 'stats': {'active_anon': 75448320,
'active_file': 0, 'cache': 0, 'dirty': 0, 'hierarchical_memory_limit': 9223372036854771712,
'hierarchical_memsw_limit': 9223372036854771712, 'inactive_anon': 0, 'inactive_file': 0, 'mapped_file':
0, 'pgfault': 28619, 'pgmajfault': 0, 'pgpgin': 20295, 'pgpgout': 8518, 'rss': 75448320, 'rss_huge':
27262976, 'total_active_anon': 75448320, 'total_active_file': 0, 'total_cache': 0, 'total_dirty': 0,
'total_inactive_anon': 0, 'total_inactive_file': 0, 'total_mapped_file': 0, 'total_pgfault': 28619,
'total_pgmajfault': 0, 'total_pgpgin': 20295, 'total_pgpgout': 8518, 'total_rss': 75448320,
'total_rss_huge': 27262976, 'total_unevictable': 0, 'total_writeback': 0, 'unevictable': 0, 'writeback': 0},
'limit': 66312925184}, 'name': '/xxxxx', 'id': 'xxxxx'}
ERROR:collect_data:'networks'
Но когда я запускаю его в Ubuntu
Ubuntu
версия Ubuntu
# lsb_release -a
LSB Version: core-9.20170808ubuntu1-noarch:security-9.20170808ubuntu1-noarch
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic
docker версия
# docker version
Client:
Version: 18.09.7
API version: 1.39
Go version: go1.10.1
Git commit: 2d0083d
Built: Fri Aug 16 14:20:06 2019
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.09.7
API version: 1.39 (minimum version 1.12)
Go version: go1.10.1
Git commit: 2d0083d
Built: Wed Aug 14 19:41:23 2019
OS/Arch: linux/amd64
Experimental: false
python код
docker sdk for python
import docker
client = docker.from_env()
stats = container.stats(stream=False)
print(stats)
print(str(list(stats['networks'].values())[0]['rx_bytes']))
стандартный вывод
{'read': '2020-03-30T13:07:01.094199037Z', 'preread': '2020-03-30T13:07:00.093103158Z',
'pids_stats': {'current': 7}, 'blkio_stats': {'io_service_bytes_recursive': [{'major': 252, 'minor': 0, 'op':
'Read', 'value': 0}, {'major': 252, 'minor': 0, 'op': 'Write', 'value': 385507328}, {'major': 252, 'minor': 0,
'op': 'Sync', 'value': 241664}, {'major': 252, 'minor': 0, 'op': 'Async', 'value': 385265664}, {'major': 252,
'minor': 0, 'op': 'Total', 'value': 385507328}], 'io_serviced_recursive': [{'major': 252, 'minor': 0, 'op':
'Read', 'value': 0}, {'major': 252, 'minor': 0, 'op': 'Write', 'value': 11678}, {'major': 252, 'minor': 0, 'op':
'Sync', 'value': 1334}, {'major': 252, 'minor': 0, 'op': 'Async', 'value': 10344}, {'major': 252, 'minor': 0,
'op': 'Total', 'value': 11678}], 'io_queue_recursive': [], 'io_service_time_recursive': [],
'io_wait_time_recursive': [], 'io_merged_recursive': [], 'io_time_recursive': [], 'sectors_recursive': []},
'num_procs': 0, 'storage_stats': {}, 'cpu_stats': {'cpu_usage': {'total_usage': 9756934763,
'percpu_usage': [666952634, 478812429, 671823468, 485544816, 614203641, 552001733,
581142364, 532484924, 575376052, 553035730, 577174864, 534464066, 666433643, 896704712,
649666882, 721112805], 'usage_in_kernelmode': 5720000000, 'usage_in_usermode': 3040000000},
'system_cpu_usage': 135329085230000000, 'online_cpus': 16, 'throttling_data': {'periods': 0,
'throttled_periods': 0, 'throttled_time': 0}}, 'precpu_stats': {'cpu_usage': {'total_usage': 9756934763,
'percpu_usage': [666952634, 478812429, 671823468, 485544816, 614203641, 552001733,
581142364, 532484924, 575376052, 553035730, 577174864, 534464066, 666433643, 896704712,
649666882, 721112805], 'usage_in_kernelmode': 5720000000, 'usage_in_usermode': 3040000000},
'system_cpu_usage': 135329069510000000, 'online_cpus': 16, 'throttling_data': {'periods': 0,
'throttled_periods': 0, 'throttled_time': 0}}, 'memory_stats': {'usage': 80257024, 'max_usage':
82989056, 'stats': {'active_anon': 6430720, 'active_file': 9003008, 'cache': 62849024, 'dirty': 0,
'hierarchical_memory_limit': 9223372036854771712, 'hierarchical_memsw_limit': 0, 'inactive_anon':
9228288, 'inactive_file': 41926656, 'mapped_file': 11341824, 'pgfault': 1095805, 'pgmajfault': 0,
'pgpgin': 635702, 'pgpgout': 619445, 'rss': 3739648, 'rss_huge': 0, 'total_active_anon': 6430720,
'total_active_file': 9003008, 'total_cache': 62849024, 'total_dirty': 0, 'total_inactive_anon': 9228288,
'total_inactive_file': 41926656, 'total_mapped_file': 11341824, 'total_pgfault': 1095805,
'total_pgmajfault': 0, 'total_pgpgin': 635702, 'total_pgpgout': 619445, 'total_rss': 3739648,
'total_rss_huge': 0, 'total_unevictable': 0, 'total_writeback': 0, 'unevictable': 0, 'writeback': 0}, 'limit':65419714560},'name':'/xxxx','id':'xxxx',
'networks': {'eth0':{'rx_bytes': 4950, 'rx_packets': 115, 'rx_errors': 0, 'rx_dropped': 0, 'tx_bytes': 0, 'tx_packets': 0, 'tx_errors': 0, 'tx_dropped': 0}}}
4950
вопрос
Это потому, что docker SDK for python4.1
на centos7.5
и docker 17.12
не поддерживает получение networks
параметр