# coding=utf-8
import os
import commands
import re
from pyExcelerator import * def execute(cmd):
status, output = commands.getstatusoutput(cmd)
if status != 0:
raise Exception('status is %s, output is %s' % (status, output))
return output def get_docker_name():
infos = execute("docker ps |awk '{print $1, $NF}'").split('\n')
regex = re.compile('\s+')
id_name = {}
for info in infos:
docker_id, docker_name = regex.split(info)
id_name[docker_id] = docker_name
return id_name def get_docker_mem():
regex = re.compile('\s+')
ret = execute('docker stats --no-stream').split('\n')
result_name = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'docker_res.xlsx')
id_name = get_docker_name()
w = Workbook()
ws = w.add_sheet('node_1_data')
ws.write(0, 0, 'docker_id')
ws.write(0, 1, 'docker_name')
ws.write(0, 2, 'mem(MB)')
index = 1
for docker in ret:
info = regex.split(docker)
docker_id = info[0]
mem = info[2]
unit = info[3]
if unit.startswith('G'):
mem = float(mem) * 1024
if unit.startswith('K'):
mem = float(mem) / 1024
try:
mem = float(mem)
except:
pass
name = id_name[docker_id]
ws.write(index, 0, docker_id)
ws.write(index, 1, name)
ws.write(index, 2, mem)
index += 1
w.save(result_name) if __name__ == '__main__':
get_docker_mem()

最新文章

  1. Linux find命令的用法实践
  2. 最近在做外贸网站的时候,需要大量的字体来充实页面,就学习了怎么引用Google Fonts
  3. Lucene.net站内搜索—5、搜索引擎第一版实现
  4. 【转】使用Sublime + PlantUML高效地画图
  5. Google OKR 目标管理体系学习
  6. ubuntu的命令day1
  7. JavaWeb项目开发案例精粹-第2章投票系统-006view层
  8. SharePoint 学习记事(三)
  9. 原型模式(Prototype Pattern)
  10. LINQ之路(2):LINQ to SQL本质
  11. vmware中Ubuntu不能全屏展示的问题
  12. Mego开发文档 - 索引
  13. Linux 中磁盘阵列RAID10配置
  14. Java程序第二次作业
  15. Mongo学习笔记
  16. nginx 内置变量
  17. cordova文件传输系统插件使用:cordova-plugin-file-transfer
  18. android kotlin Gradle DSL method not found: '1.2.51()'错误,be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
  19. 中大 9095. Islands
  20. SQL-结构化查询语言(2)

热门文章

  1. 【转】Django框架请求生命周期
  2. AT2370 Piling Up
  3. 如何快速优雅的解决:ORA-02290: 违反检查约束条件 异常问题
  4. Python List 列表list()方法
  5. 北风设计模式课程---单一职责原则(Single Responsibility Principle)
  6. 【运维相关】MongoDB那些坑
  7. Tomcat/weblogic session失效时间的几种设置方法
  8. C#之委托(一)
  9. 解决gson解析long自动转为科学计数的问题
  10. 【FICO系列】SAP FICO 基本概念