Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
fdebbce5
G
glances
项目概览
蜕变的菜鸟
/
glances
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glances
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fdebbce5
编写于
9月 09, 2015
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add IOR and W to the Curses interface
上级
1427274e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
102 addition
and
21 deletion
+102
-21
glances/plugins/glances_docker.py
glances/plugins/glances_docker.py
+102
-21
未找到文件。
glances/plugins/glances_docker.py
浏览文件 @
fdebbce5
...
...
@@ -225,6 +225,7 @@ class Plugin(GlancesPlugin):
container
[
'cpu'
]
=
self
.
get_docker_cpu
(
container
[
'Id'
],
self
.
thread_list
[
container
[
'Id'
]].
stats
)
container
[
'memory'
]
=
self
.
get_docker_memory
(
container
[
'Id'
],
self
.
thread_list
[
container
[
'Id'
]].
stats
)
container
[
'network'
]
=
self
.
get_docker_network
(
container
[
'Id'
],
self
.
thread_list
[
container
[
'Id'
]].
stats
)
container
[
'io'
]
=
self
.
get_docker_io
(
container
[
'Id'
],
self
.
thread_list
[
container
[
'Id'
]].
stats
)
elif
self
.
input_method
==
'snmp'
:
# Update stats using SNMP
...
...
@@ -308,13 +309,17 @@ class Plugin(GlancesPlugin):
Input: id is the full container id
Output: a dict {'time_since_update': 3000, 'rx': 10, 'tx': 65}.
with:
time_since_update: number of seconds elapsed between the latest grab
rx: Number of byte received
tx: Number of byte transmited
"""
# Init the returned dict
network_new
=
{}
# Read the rx/tx stats (in bytes)
try
:
net
io
counters
=
all_stats
[
"network"
]
netcounters
=
all_stats
[
"network"
]
except
KeyError
as
e
:
# all_stats do not have NETWORK information
logger
.
debug
(
"Can not grab NET usage for container {0} ({1})"
.
format
(
container_id
,
e
))
...
...
@@ -322,17 +327,17 @@ class Plugin(GlancesPlugin):
return
network_new
# Previous network interface stats are stored in the network_old variable
if
not
hasattr
(
self
,
'
netio
counters_old'
):
if
not
hasattr
(
self
,
'
inet
counters_old'
):
# First call, we init the network_old var
self
.
net
io
counters_old
=
{}
self
.
netcounters_old
=
{}
try
:
self
.
net
iocounters_old
[
container_id
]
=
netio
counters
self
.
net
counters_old
[
container_id
]
=
net
counters
except
(
IOError
,
UnboundLocalError
):
pass
if
container_id
not
in
self
.
net
io
counters_old
:
if
container_id
not
in
self
.
netcounters_old
:
try
:
self
.
net
iocounters_old
[
container_id
]
=
netio
counters
self
.
net
counters_old
[
container_id
]
=
net
counters
except
(
IOError
,
UnboundLocalError
):
pass
else
:
...
...
@@ -340,17 +345,79 @@ class Plugin(GlancesPlugin):
# XML/RPC API, which would otherwise be overly difficult work
# for users of the API
network_new
[
'time_since_update'
]
=
getTimeSinceLastUpdate
(
'docker_net_{0}'
.
format
(
container_id
))
network_new
[
'rx'
]
=
net
iocounters
[
"rx_bytes"
]
-
self
.
netio
counters_old
[
container_id
][
"rx_bytes"
]
network_new
[
'tx'
]
=
net
iocounters
[
"tx_bytes"
]
-
self
.
netio
counters_old
[
container_id
][
"tx_bytes"
]
network_new
[
'cumulative_rx'
]
=
net
io
counters
[
"rx_bytes"
]
network_new
[
'cumulative_tx'
]
=
net
io
counters
[
"tx_bytes"
]
network_new
[
'rx'
]
=
net
counters
[
"rx_bytes"
]
-
self
.
net
counters_old
[
container_id
][
"rx_bytes"
]
network_new
[
'tx'
]
=
net
counters
[
"tx_bytes"
]
-
self
.
net
counters_old
[
container_id
][
"tx_bytes"
]
network_new
[
'cumulative_rx'
]
=
netcounters
[
"rx_bytes"
]
network_new
[
'cumulative_tx'
]
=
netcounters
[
"tx_bytes"
]
# Save stats to compute next bitrate
self
.
net
iocounters_old
[
container_id
]
=
netio
counters
self
.
net
counters_old
[
container_id
]
=
net
counters
# Return the stats
return
network_new
def
get_docker_io
(
self
,
container_id
,
all_stats
):
"""Return the container IO usage using the Docker API (v1.0 or higher).
Input: id is the full container id
Output: a dict {'time_since_update': 3000, 'ior': 10, 'iow': 65}.
with:
time_since_update: number of seconds elapsed between the latest grab
ior: Number of byte readed
iow: Number of byte written
"""
# Init the returned dict
io_new
=
{}
# Read the ior/iow stats (in bytes)
try
:
iocounters
=
all_stats
[
"blkio_stats"
]
except
KeyError
as
e
:
# all_stats do not have io information
logger
.
debug
(
"Can not grab block IO usage for container {0} ({1})"
.
format
(
container_id
,
e
))
# No fallback available...
return
io_new
# Previous io interface stats are stored in the io_old variable
if
not
hasattr
(
self
,
'iocounters_old'
):
# First call, we init the io_old var
self
.
iocounters_old
=
{}
try
:
self
.
iocounters_old
[
container_id
]
=
iocounters
except
(
IOError
,
UnboundLocalError
):
pass
if
container_id
not
in
self
.
iocounters_old
:
try
:
self
.
iocounters_old
[
container_id
]
=
iocounters
except
(
IOError
,
UnboundLocalError
):
pass
else
:
# By storing time data we enable IoR/s and IoW/s calculations in the
# XML/RPC API, which would otherwise be overly difficult work
# for users of the API
try
:
# Read IOR and IOW value in the structure list of dict
ior
=
[
i
for
i
in
iocounters
[
'io_service_bytes_recursive'
]
if
i
[
'op'
]
==
'Read'
][
0
][
'value'
]
iow
=
[
i
for
i
in
iocounters
[
'io_service_bytes_recursive'
]
if
i
[
'op'
]
==
'Write'
][
0
][
'value'
]
ior_old
=
[
i
for
i
in
self
.
iocounters_old
[
container_id
][
'io_service_bytes_recursive'
]
if
i
[
'op'
]
==
'Read'
][
0
][
'value'
]
iow_old
=
[
i
for
i
in
self
.
iocounters_old
[
container_id
][
'io_service_bytes_recursive'
]
if
i
[
'op'
]
==
'Write'
][
0
][
'value'
]
except
(
IndexError
,
KeyError
)
as
e
:
# all_stats do not have io information
logger
.
debug
(
"Can not grab block IO usage for container {0} ({1})"
.
format
(
container_id
,
e
))
else
:
io_new
[
'time_since_update'
]
=
getTimeSinceLastUpdate
(
'docker_io_{0}'
.
format
(
container_id
))
io_new
[
'ior'
]
=
ior
-
ior_old
io_new
[
'iow'
]
=
iow
-
iow_old
io_new
[
'cumulative_ior'
]
=
ior
io_new
[
'cumulative_iow'
]
=
iow
# Save stats to compute next bitrate
self
.
iocounters_old
[
container_id
]
=
iocounters
# Return the stats
return
io_new
def
get_user_ticks
(
self
):
"""Return the user ticks by reading the environment variable."""
return
os
.
sysconf
(
os
.
sysconf_names
[
'SC_CLK_TCK'
])
...
...
@@ -376,9 +443,11 @@ class Plugin(GlancesPlugin):
ret
.
append
(
self
.
curse_new_line
())
# Header
ret
.
append
(
self
.
curse_new_line
())
msg
=
'{0:>14}'
.
format
(
'Id'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
' {0:20}'
.
format
(
'Name'
)
# msg = '{0:>14}'.format('Id')
# ret.append(self.curse_add_line(msg))
# Get the maximum containers name (cutted to 20 char max)
name_max_width
=
min
(
20
,
len
(
max
(
self
.
stats
[
'containers'
],
key
=
lambda
x
:
len
(
x
[
'name'
]))[
'name'
]))
msg
=
' {0:{width}}'
.
format
(
'Name'
,
width
=
name_max_width
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>26}'
.
format
(
'Status'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
...
...
@@ -386,6 +455,10 @@ class Plugin(GlancesPlugin):
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>7}'
.
format
(
'MEM'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>6}'
.
format
(
'IOR/s'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>6}'
.
format
(
'IOW/s'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>6}'
.
format
(
'Rx/s'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>6}'
.
format
(
'Tx/s'
)
...
...
@@ -396,15 +469,15 @@ class Plugin(GlancesPlugin):
for
container
in
self
.
stats
[
'containers'
]:
ret
.
append
(
self
.
curse_new_line
())
# Id
msg
=
'{0:>14}'
.
format
(
container
[
'Id'
][
0
:
12
])
ret
.
append
(
self
.
curse_add_line
(
msg
))
#
msg = '{0:>14}'.format(container['Id'][0:12])
#
ret.append(self.curse_add_line(msg))
# Name
name
=
container
[
'
Names'
][
0
]
if
len
(
name
)
>
20
:
name
=
'_'
+
name
[
-
19
:]
name
=
container
[
'
name'
]
if
len
(
name
)
>
name_max_width
:
name
=
'_'
+
name
[
-
name_max_width
+
1
:]
else
:
name
=
name
[:
20
]
msg
=
' {0:
20}'
.
format
(
name
)
name
=
name
[:
name_max_width
]
msg
=
' {0:
{width}}'
.
format
(
name
,
width
=
name_max_width
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
# Status
status
=
self
.
container_alert
(
container
[
'Status'
])
...
...
@@ -423,6 +496,14 @@ class Plugin(GlancesPlugin):
except
KeyError
:
msg
=
'{0:>7}'
.
format
(
'?'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
# IO R/W
for
r
in
[
'ior'
,
'iow'
]:
try
:
value
=
self
.
auto_unit
(
int
(
container
[
'io'
][
r
]
//
container
[
'io'
][
'time_since_update'
]
*
8
))
+
"b"
msg
=
'{0:>6}'
.
format
(
value
)
except
KeyError
:
msg
=
'{0:>6}'
.
format
(
'?'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
# NET RX/TX
for
r
in
[
'rx'
,
'tx'
]:
try
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录