Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
fddca794
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,发现更多精彩内容 >>
提交
fddca794
编写于
3月 23, 2014
作者:
N
Nicolas Hennion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correct automatic sort
上级
6554c875
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
73 addition
and
45 deletion
+73
-45
glances/core/glances_globals.py
glances/core/glances_globals.py
+4
-8
glances/core/glances_logs.py
glances/core/glances_logs.py
+51
-33
glances/core/glances_processes.py
glances/core/glances_processes.py
+14
-0
glances/plugins/glances_processcount.py
glances/plugins/glances_processcount.py
+2
-2
glances/plugins/glances_processlist.py
glances/plugins/glances_processlist.py
+2
-2
未找到文件。
glances/core/glances_globals.py
浏览文件 @
fddca794
...
...
@@ -79,14 +79,10 @@ gettext.install(gettext_domain, locale_dir)
# Instances shared between all Glances's scripts
#===============================================
# The global instance for the configuration file
# from ..core.glances_config import Config as glancesConfig
# glances_config = glancesConfig()
# Processcount and processlist plugins
from
..core.glances_processes
import
glancesProcesses
# glances_processes for processcount and processlist plugins
from
glances.core.glances_processes
import
glancesProcesses
glances_processes
=
glancesProcesses
()
# Default auto process sort is 'cpu_percent'
process_auto_by
=
'cpu_percent'
# The global instance for the logs
from
.
.core.glances_logs
import
glancesLogs
from
glances
.core.glances_logs
import
glancesLogs
glances_logs
=
glancesLogs
()
glances/core/glances_logs.py
浏览文件 @
fddca794
...
...
@@ -23,7 +23,7 @@ import time
from
datetime
import
datetime
# Import Glances libs
from
glances.core.glances_globals
import
process_auto_by
from
glances.core.glances_globals
import
glances_processes
class
glancesLogs
:
...
...
@@ -55,24 +55,18 @@ class glancesLogs:
# Init the logs list
self
.
logs_list
=
[]
# Automaticaly define the sort to apply on the processes list
self
.
sort_process_by
=
'none'
def
get
(
self
):
"""
Return the logs list (RAW)
"""
return
self
.
logs_list
def
len
(
self
):
"""
Return the number of item in the log list
"""
return
self
.
logs_list
.
__len__
()
def
__itemexist__
(
self
,
item_type
):
"""
An item exist in the list if:
...
...
@@ -86,33 +80,52 @@ class glancesLogs:
return
i
return
-
1
def
add
(
self
,
item_state
,
item_type
,
item_value
,
proc_list
=
[],
proc_desc
=
""
):
def
set_process_sort
(
self
,
item_type
):
"""
If item is a 'new one':
Add the new item at the beginning of the logs list
Else:
Update the existing item
Define the process auto sort key from the alert type
"""
# Add Top process sort depending on alert type
process_auto_by
=
'cpu_percent'
# Process sort depending on alert type
if
(
item_type
.
startswith
(
"MEM"
)):
# Sort TOP process by memory_percent
process_auto_by
=
'memory_percent'
elif
(
item_type
.
startswith
(
"CPU
IO
"
)):
elif
(
item_type
.
startswith
(
"CPU
_IOWAIT
"
)):
# Sort TOP process by io_counters (only for Linux OS)
process_auto_by
=
'io_counters'
elif
(
item_type
.
startswith
(
"MON"
)):
# !!! Never in v2 because MON are not logged...
# Do no sort process for monitored prcesses list
self
.
sort_process_by
=
'none'
else
:
# Default sort is...
process_auto_by
=
'cpu_percent'
glances_processes
.
setsortkey
(
process_auto_by
)
return
process_auto_by
def
reset_process_sort
(
self
):
"""
Reset the process_auto_by variable
"""
# Default sort is...
process_auto_by
=
'cpu_percent'
glances_processes
.
setsortkey
(
process_auto_by
)
return
process_auto_by
def
add
(
self
,
item_state
,
item_type
,
item_value
,
proc_list
=
[],
proc_desc
=
""
):
"""
If item is a 'new one':
Add the new item at the beginning of the logs list
Else:
Update the existing item
"""
# Add or update the log
item_index
=
self
.
__itemexist__
(
item_type
)
if
(
item_index
<
0
):
# Item did not exist, add if WARNING or CRITICAL
if
((
item_state
==
"WARNING"
)
or
(
item_state
==
"CRITICAL"
)):
# Define the automatic process sort key
self
.
set_process_sort
(
item_type
)
# Create the new log item
# Time is stored in Epoch format
# Epoch -> DMYHMS = datetime.fromtimestamp(epoch)
item
=
[]
...
...
@@ -126,23 +139,27 @@ class glancesLogs:
item
.
append
(
item_value
)
# MIN
item
.
append
(
item_value
)
# SUM
item
.
append
(
1
)
# COUNT
# Process list is sorted automaticaly
# Process list is sorted automaticaly
# Overwrite the user choise
topprocess
=
sorted
(
proc_list
,
key
=
lambda
process
:
process
[
process_auto_by
],
reverse
=
True
)
item
.
append
(
topprocess
[
0
:
3
])
# TOP 3 PROCESS LIST
# topprocess = sorted(proc_list, key=lambda process: process[process_auto_by],
# reverse=True)
# item.append(topprocess[0:3]) # TOP 3 PROCESS LIST
item
.
append
([])
# TOP 3 PROCESS LIST
item
.
append
(
proc_desc
)
# MONITORED PROCESSES DESC
# Add the item to the list
self
.
logs_list
.
insert
(
0
,
item
)
if
self
.
len
()
>
self
.
logs_max
:
self
.
logs_list
.
pop
()
else
:
# Item exist, update
if
((
item_state
==
"OK"
)
or
(
item_state
==
"CAREFUL"
)):
# Reset the automatic process sort key
self
.
reset_process_sort
()
# Close the item
self
.
logs_list
[
item_index
][
1
]
=
time
.
mktime
(
datetime
.
now
().
timetuple
())
# TOP PROCESS LIST
self
.
logs_list
[
item_index
][
9
]
=
[]
else
:
# Update the item
# State
...
...
@@ -160,18 +177,19 @@ class glancesLogs:
self
.
logs_list
[
item_index
][
8
]
+=
1
self
.
logs_list
[
item_index
][
5
]
=
(
self
.
logs_list
[
item_index
][
7
]
/
self
.
logs_list
[
item_index
][
8
])
# Process list is sorted automaticaly
# Overwrite the user choise
topprocess
=
sorted
(
proc_list
,
key
=
lambda
process
:
process
[
process_auto_by
],
reverse
=
True
)
# TOP PROCESS LIST
self
.
logs_list
[
item_index
][
9
]
=
topprocess
[
0
:
3
]
# # Process list is sorted automaticaly
# # Overwrite the user choise
# topprocess = sorted(proc_list, key=lambda process: process[process_auto_by],
# reverse=True)
# # TOP PROCESS LIST
# self.logs_list[item_index][9] = topprocess[0:3]
self
.
logs_list
[
item_index
][
9
]
=
[]
# MONITORED PROCESSES DESC
self
.
logs_list
[
item_index
][
10
]
=
proc_desc
return
self
.
len
()
def
clean
(
self
,
critical
=
False
):
"""
Clean the log list by deleting finished item
...
...
glances/core/glances_processes.py
浏览文件 @
fddca794
...
...
@@ -47,6 +47,7 @@ class glancesProcesses:
# value = [ read_bytes_old, write_bytes_old ]
self
.
io_old
=
{}
# Init
self
.
processsort
=
'cpu_percent'
self
.
processlist
=
[]
self
.
processcount
=
{
'total'
:
0
,
'running'
:
0
,
'sleeping'
:
0
,
'thread'
:
0
}
...
...
@@ -193,6 +194,19 @@ class glancesProcesses:
"""
return
self
.
processlist
def
getsortkey
(
self
):
"""
Return the current sort key for automatic sort
"""
return
self
.
processsort
def
setsortkey
(
self
,
sortedby
):
"""
Return the current sort key for automatic sort
"""
self
.
processsort
=
sortedby
return
self
.
processsort
def
getsortlist
(
self
,
sortedby
=
None
):
"""
Return the processlist
...
...
glances/plugins/glances_processcount.py
浏览文件 @
fddca794
...
...
@@ -20,7 +20,7 @@
# Import Glances libs
from
glances.plugins.glances_plugin
import
GlancesPlugin
from
glances.core.glances_globals
import
glances_processes
,
process_auto_by
from
glances.core.glances_globals
import
glances_processes
class
Plugin
(
GlancesPlugin
):
...
...
@@ -95,7 +95,7 @@ class Plugin(GlancesPlugin):
if
(
args
.
process_sorted_by
==
'auto'
):
msg
=
"{0}"
.
format
(
_
(
"sorted automatically"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
" {0} {1}"
.
format
(
_
(
"by"
),
process_auto_by
)
msg
=
" {0} {1}"
.
format
(
_
(
"by"
),
glances_processes
.
getsortkey
()
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
else
:
msg
=
"{0} {1}"
.
format
(
_
(
"sorted by"
),
args
.
process_sorted_by
)
...
...
glances/plugins/glances_processlist.py
浏览文件 @
fddca794
...
...
@@ -23,7 +23,7 @@ from datetime import timedelta
# Import Glances libs
from
glances.plugins.glances_plugin
import
GlancesPlugin
from
glances.core.glances_globals
import
glances_processes
,
process_auto_by
from
glances.core.glances_globals
import
glances_processes
class
Plugin
(
GlancesPlugin
):
...
...
@@ -69,7 +69,7 @@ class Plugin(GlancesPlugin):
# Compute the sort key
if
(
args
.
process_sorted_by
==
'auto'
):
process_sort_key
=
process_auto_by
process_sort_key
=
glances_processes
.
getsortkey
()
else
:
process_sort_key
=
args
.
process_sorted_by
sort_style
=
'BOLD'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录