Commit c11d158f by zhangwei

增加try异常处理

parent a498c5d6
......@@ -38,9 +38,15 @@ def check_container_info(container_name, container_item):
mem_limit = new_result['memory_stats']['limit']
result = round(float(mem_usage) / float(mem_limit) * 100.0, 2)
elif container_item == "eth0_rx_byte":
result = new_result['networks']['eth0']['rx_bytes'] - old_result['networks']['eth0']['rx_bytes']
try:
result = new_result['networks']['eth0']['rx_bytes'] - old_result['networks']['eth0']['rx_bytes']
except KeyError:
result = 0
elif container_item == "eth0_tx_byte":
result = new_result['networks']['eth0']['tx_bytes'] - old_result['networks']['eth0']['tx_bytes']
try:
result = new_result['networks']['eth0']['tx_bytes'] - old_result['networks']['eth0']['tx_bytes']
except KeyError:
result = 0
elif container_item == "blk_io_read":
r_list = new_result['blkio_stats']['io_service_bytes_recursive']
for r_dict in r_list:
......@@ -61,8 +67,8 @@ def check_container_info(container_name, container_item):
if __name__ == "__main__":
docker_client = docker.Client(base_url='unix://var/run/docker.sock', version='1.23')
docker_client = docker.Client(base_url='unix://var/run/docker.sock')
container_name = sys.argv[1]
container_item = sys.argv[2]
global result
#global result
print check_container_info(container_name, container_item)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment