Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
f069d810
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 搜索 >>
提交
f069d810
编写于
2月 13, 2015
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve PEP8 (S1721)
上级
6b131205
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
35 addition
and
27 deletion
+35
-27
glances/core/glances_client_browser.py
glances/core/glances_client_browser.py
+1
-1
glances/core/glances_logs.py
glances/core/glances_logs.py
+1
-1
glances/core/glances_processes.py
glances/core/glances_processes.py
+29
-21
glances/core/glances_webserver.py
glances/core/glances_webserver.py
+1
-1
glances/plugins/glances_processlist.py
glances/plugins/glances_processlist.py
+3
-3
未找到文件。
glances/core/glances_client_browser.py
浏览文件 @
f069d810
...
...
@@ -84,7 +84,7 @@ class GlancesClientBrowser(object):
# Do not retreive stats for statics server
# Why ? Because for each offline servers, the timeout will be reached
# So ? The curse interface freezes
if
(
v
[
'type'
]
==
'STATIC'
and
v
[
'status'
]
in
[
'UNKNOWN'
,
'SNMP'
,
'OFFLINE'
])
:
if
v
[
'type'
]
==
'STATIC'
and
v
[
'status'
]
in
[
'UNKNOWN'
,
'SNMP'
,
'OFFLINE'
]
:
continue
# Select the connection mode (with or without password)
...
...
glances/core/glances_logs.py
浏览文件 @
f069d810
...
...
@@ -195,7 +195,7 @@ class GlancesLogs(object):
"""
# Create a new clean list
clean_logs_list
=
[]
while
(
self
.
len
()
>
0
)
:
while
self
.
len
()
>
0
:
item
=
self
.
logs_list
.
pop
()
if
item
[
1
]
<
0
or
(
not
critical
and
item
[
2
].
startswith
(
"CRITICAL"
)):
clean_logs_list
.
insert
(
0
,
item
)
...
...
glances/core/glances_processes.py
浏览文件 @
f069d810
...
...
@@ -36,7 +36,8 @@ def is_kernel_thread(proc):
""" Return True if proc is a kernel thread, False instead. """
try
:
return
os
.
getpgid
(
proc
.
pid
)
==
0
except
OSError
:
# Python >= 3.3 raises ProcessLookupError, which inherits OSError
# Python >= 3.3 raises ProcessLookupError, which inherits OSError
except
OSError
:
# return False is process is dead
return
False
...
...
@@ -69,7 +70,8 @@ class ProcessTreeNode(object):
if
current_node
.
is_root
:
lines
.
append
(
indent_str
)
else
:
lines
.
append
(
"%s[%s]"
%
(
indent_str
,
current_node
.
process
.
name
()))
lines
.
append
(
"%s[%s]"
%
(
indent_str
,
current_node
.
process
.
name
()))
indent_str
=
" "
*
(
len
(
lines
[
-
1
])
-
1
)
children_nodes_to_print
=
collections
.
deque
()
for
child
in
current_node
.
children
:
...
...
@@ -77,14 +79,15 @@ class ProcessTreeNode(object):
tree_char
=
"└─"
else
:
tree_char
=
"├─"
children_nodes_to_print
.
appendleft
((
indent_str
+
tree_char
,
child
))
children_nodes_to_print
.
appendleft
(
(
indent_str
+
tree_char
,
child
))
if
children_nodes_to_print
:
nodes_to_print
.
append
(
children_nodes_to_print
)
return
"
\n
"
.
join
(
lines
)
def
set_sorting
(
self
,
key
,
reverse
):
""" Set sorting key or func for user with __iter__ (affects the whole tree from this node). """
if
(
self
.
sort_key
!=
key
)
or
(
self
.
reverse_sorting
!=
reverse
)
:
if
self
.
sort_key
!=
key
or
self
.
reverse_sorting
!=
reverse
:
nodes_to_flag_unsorted
=
collections
.
deque
([
self
])
while
nodes_to_flag_unsorted
:
current_node
=
nodes_to_flag_unsorted
.
pop
()
...
...
@@ -134,7 +137,8 @@ class ProcessTreeNode(object):
if
not
self
.
children_sorted
:
# optimization to avoid sorting twice (once when limiting the maximum processes to grab stats for,
# and once before displaying)
self
.
children
.
sort
(
key
=
self
.
__class__
.
get_weight
,
reverse
=
self
.
reverse_sorting
)
self
.
children
.
sort
(
key
=
self
.
__class__
.
get_weight
,
reverse
=
self
.
reverse_sorting
)
self
.
children_sorted
=
True
for
child
in
self
.
children
:
for
n
in
iter
(
child
):
...
...
@@ -151,10 +155,11 @@ class ProcessTreeNode(object):
if
not
self
.
children_sorted
:
# optimization to avoid sorting twice (once when limiting the maximum processes to grab stats for,
# and once before displaying)
self
.
children
.
sort
(
key
=
self
.
__class__
.
get_weight
,
reverse
=
self
.
reverse_sorting
)
self
.
children
.
sort
(
key
=
self
.
__class__
.
get_weight
,
reverse
=
self
.
reverse_sorting
)
self
.
children_sorted
=
True
for
child
in
self
.
children
:
if
(
not
exclude_incomplete_stats
)
or
(
"time_since_update"
in
child
.
stats
)
:
if
not
exclude_incomplete_stats
or
"time_since_update"
in
child
.
stats
:
yield
child
def
find_process
(
self
,
process
):
...
...
@@ -162,7 +167,7 @@ class ProcessTreeNode(object):
nodes_to_search
=
collections
.
deque
([
self
])
while
nodes_to_search
:
current_node
=
nodes_to_search
.
pop
()
if
(
not
current_node
.
is_root
)
and
(
current_node
.
process
.
pid
==
process
.
pid
)
:
if
not
current_node
.
is_root
and
current_node
.
process
.
pid
==
process
.
pid
:
return
current_node
nodes_to_search
.
extend
(
current_node
.
children
)
...
...
@@ -192,13 +197,16 @@ class ProcessTreeNode(object):
# parent is not in tree, add this node later
nodes_to_add_last
.
append
(
new_node
)
# next pass(es): add nodes to their parents if it could not be done in previous pass
# next pass(es): add nodes to their parents if it could not be done in
# previous pass
while
nodes_to_add_last
:
node_to_add
=
nodes_to_add_last
.
popleft
()
# pop from left and append to right to avoid infinite loop
# pop from left and append to right to avoid infinite loop
node_to_add
=
nodes_to_add_last
.
popleft
()
try
:
parent_process
=
node_to_add
.
process
.
parent
()
except
psutil
.
NoSuchProcess
:
# parent is dead, consider no parent, add this node at the top level
# parent is dead, consider no parent, add this node at the top
# level
tree_root
.
children
.
append
(
node_to_add
)
else
:
if
parent_process
is
None
:
...
...
@@ -300,9 +308,11 @@ class GlancesProcesses(object):
if
value
is
not
None
:
try
:
self
.
process_filter_re
=
re
.
compile
(
value
)
logger
.
debug
(
"Process filter regex compilation OK: {0}"
.
format
(
self
.
get_process_filter
()))
logger
.
debug
(
"Process filter regex compilation OK: {0}"
.
format
(
self
.
get_process_filter
()))
except
Exception
:
logger
.
error
(
"Cannot compile process filter regex: {0}"
.
format
(
value
))
logger
.
error
(
"Cannot compile process filter regex: {0}"
.
format
(
value
))
self
.
process_filter_re
=
None
else
:
self
.
process_filter_re
=
None
...
...
@@ -545,8 +555,7 @@ class GlancesProcesses(object):
processdict
=
{}
for
proc
in
psutil
.
process_iter
():
# Ignore kernel threads if needed
if
(
self
.
no_kernel_threads
and
(
not
is_windows
)
and
is_kernel_thread
(
proc
)):
if
self
.
no_kernel_threads
and
not
is_windows
and
is_kernel_thread
(
proc
):
continue
# If self.get_max_processes() is None: Only retreive mandatory stats
...
...
@@ -562,10 +571,8 @@ class GlancesProcesses(object):
# ignore the 'idle' process on Windows and *BSD
# ignore the 'kernel_task' process on OS X
# waiting for upstream patch from psutil
if
(
is_bsd
and
processdict
[
proc
][
'name'
]
==
'idle'
or
is_windows
and
processdict
[
proc
][
'name'
]
==
'System Idle Process'
or
is_mac
and
processdict
[
proc
][
'name'
]
==
'kernel_task'
):
continue
if
is_bsd
and
processdict
[
proc
][
'name'
]
==
'idle'
or
is_windows
and
processdict
[
proc
][
'name'
]
==
'System Idle Process'
or
is_mac
and
processdict
[
proc
][
'name'
]
==
'kernel_task'
:
continue
# Update processcount (global statistics)
try
:
self
.
processcount
[
str
(
proc
.
status
())]
+=
1
...
...
@@ -592,7 +599,7 @@ class GlancesProcesses(object):
for
i
,
node
in
enumerate
(
self
.
process_tree
):
# Only retreive stats for visible processes (get_max_processes)
if
(
self
.
get_max_processes
()
is
not
None
)
and
(
i
>=
self
.
get_max_processes
()
):
if
self
.
get_max_processes
()
is
not
None
and
i
>=
self
.
get_max_processes
(
):
break
# add standard stats
...
...
@@ -616,7 +623,8 @@ class GlancesProcesses(object):
processiter
=
sorted
(
processdict
.
items
(),
key
=
lambda
x
:
x
[
1
][
self
.
getsortkey
()],
reverse
=
True
)
except
(
KeyError
,
TypeError
)
as
e
:
logger
.
error
(
"Cannot sort process list by %s (%s)"
%
(
self
.
getsortkey
(),
e
))
logger
.
error
(
"Cannot sort process list by %s (%s)"
%
(
self
.
getsortkey
(),
e
))
logger
.
error
(
"%s"
%
str
(
processdict
.
items
()[
0
]))
# Fallback to all process (issue #423)
processloop
=
processdict
.
items
()
...
...
glances/core/glances_webserver.py
浏览文件 @
f069d810
...
...
@@ -34,7 +34,7 @@ class GlancesWebServer(object):
# Init stats
self
.
stats
=
GlancesStats
(
config
)
if
(
not
is_windows
)
and
args
.
no_kernel_threads
:
if
not
is_windows
and
args
.
no_kernel_threads
:
# Ignore kernel threads in process list
glances_processes
.
disable_kernel_threads
()
...
...
glances/plugins/glances_processlist.py
浏览文件 @
f069d810
...
...
@@ -77,13 +77,13 @@ class Plugin(GlancesPlugin):
""" Get curses data to display for a process tree. """
ret
=
[]
node_count
=
0
if
(
not
node
.
is_root
)
and
((
max_node_count
is
None
)
or
(
max_node_count
>
0
)):
if
not
node
.
is_root
and
((
max_node_count
is
None
)
or
(
max_node_count
>
0
)):
node_data
=
self
.
get_process_curses_data
(
node
.
stats
,
False
,
args
)
node_count
+=
1
ret
.
extend
(
node_data
)
for
child
in
node
.
iter_children
():
# stop if we have enough nodes to display
if
(
max_node_count
is
not
None
)
and
(
node_count
>=
max_node_count
)
:
if
max_node_count
is
not
None
and
node_count
>=
max_node_count
:
break
if
max_node_count
is
None
:
...
...
@@ -109,7 +109,7 @@ class Plugin(GlancesPlugin):
# find process command indices in messages
pos
=
[]
for
i
,
m
in
enumerate
(
child_data
):
if
(
m
[
"msg"
]
==
"
\n
"
)
and
(
m
is
not
child_data
[
-
1
])
:
if
m
[
"msg"
]
==
"
\n
"
and
m
is
not
child_data
[
-
1
]
:
# new line pos + 12
# TODO find a way to get rid of hardcoded 12 value
pos
.
append
(
i
+
12
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录