Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
50fb9c70
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 搜索 >>
提交
50fb9c70
编写于
9月 08, 2018
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sort docker stats #1276
上级
2caac380
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
10 deletion
+28
-10
NEWS
NEWS
+1
-0
glances/plugins/glances_docker.py
glances/plugins/glances_docker.py
+20
-4
glances/processes.py
glances/processes.py
+7
-6
未找到文件。
NEWS
浏览文件 @
50fb9c70
...
...
@@ -8,6 +8,7 @@ Version 3.1
Enhancements and new features:
* Feature request: HDD S.M.A.R.T. reports (thanks to @tnibert) #1288
* Sort docker stats #1276
Bugs corrected:
...
...
glances/plugins/glances_docker.py
浏览文件 @
50fb9c70
...
...
@@ -23,10 +23,11 @@ import os
import
threading
import
time
from
glances.compat
import
iterkeys
,
itervalues
,
nativestr
from
glances.logger
import
logger
from
glances.compat
import
iterkeys
,
itervalues
,
nativestr
from
glances.timer
import
getTimeSinceLastUpdate
from
glances.plugins.glances_plugin
import
GlancesPlugin
from
glances.processes
import
sort_stats
as
sort_stats_processes
,
weighted
,
glances_processes
# Docker-py library (optional and Linux-only)
# https://github.com/docker/docker-py
...
...
@@ -206,7 +207,7 @@ class Plugin(GlancesPlugin):
# Export name (first name in the Names list, without the /)
container_stats
[
'name'
]
=
nativestr
(
container
.
name
)
# Export global Names (used by the WebUI)
container_stats
[
'Names'
]
=
[
nativestr
(
container
.
name
)]
container_stats
[
'Names'
]
=
[
nativestr
(
container
.
name
)]
# Container Id
container_stats
[
'Id'
]
=
container
.
id
# Container Image
...
...
@@ -245,8 +246,10 @@ class Plugin(GlancesPlugin):
# Not available
pass
# Update the stats
self
.
stats
=
stats
# Sort and update the stats
self
.
stats
=
sort_stats
(
stats
)
logger
.
info
(
'Docker stats (sorted): {}'
.
format
(
self
.
stats
))
return
self
.
stats
...
...
@@ -676,3 +679,16 @@ class ThreadDockerGrabber(threading.Thread):
def
stopped
(
self
):
"""Return True is the thread is stopped."""
return
self
.
_stopper
.
isSet
()
def
sort_stats
(
stats
):
# Sort Docker stats using the same function than processes
sortedby
=
'cpu_percent'
sortedby_secondary
=
'memory_usage'
if
glances_processes
.
sort_key
.
startswith
(
'memory'
):
sortedby
=
'memory_usage'
sortedby_secondary
=
'cpu_percent'
sort_stats_processes
(
stats
[
'containers'
],
sortedby
=
sortedby
,
sortedby_secondary
=
sortedby_secondary
)
return
stats
glances/processes.py
浏览文件 @
50fb9c70
...
...
@@ -375,17 +375,17 @@ def weighted(value):
return
-
float
(
'inf'
)
if
value
is
None
else
value
def
sort_stats
(
stats
,
sortedby
=
None
,
reverse
=
True
):
def
sort_stats
(
stats
,
sortedby
=
'cpu_percent'
,
sortedby_secondary
=
'memory_percent'
,
reverse
=
True
,):
"""Return the stats (dict) sorted by (sortedby).
Reverse the sort if reverse is True.
"""
sortedby_secondary
=
'cpu_percent'
if
sortedby
is
None
:
if
sortedby
is
None
and
sortedby_secondary
is
None
:
# No need to sort...
return
stats
elif
sortedby
is
'cpu_percent'
:
sortedby_secondary
=
'memory_percent'
if
sortedby
==
'io_counters'
:
# Specific case for io_counters
...
...
@@ -398,7 +398,7 @@ def sort_stats(stats, sortedby=None, reverse=True):
reverse
=
reverse
)
except
Exception
:
stats
.
sort
(
key
=
lambda
x
:
(
weighted
(
x
[
'cpu_percent'
]),
weighted
(
x
[
'memory_percent'
])),
weighted
(
x
[
sortedby_secondary
])),
reverse
=
reverse
)
else
:
# Others sorts
...
...
@@ -407,6 +407,7 @@ def sort_stats(stats, sortedby=None, reverse=True):
weighted
(
x
[
sortedby_secondary
])),
reverse
=
reverse
)
except
(
KeyError
,
TypeError
):
# Fallback to name
stats
.
sort
(
key
=
lambda
x
:
x
[
'name'
]
if
x
[
'name'
]
is
not
None
else
'~'
,
reverse
=
False
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录