Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
22d5e4c9
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 搜索 >>
提交
22d5e4c9
编写于
2月 22, 2014
作者:
N
Nicolas Hennion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor limits for process list
上级
de47a892
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
111 addition
and
71 deletion
+111
-71
conf/glances-monitor.conf
conf/glances-monitor.conf
+7
-4
glances/core/glances_config.py
glances/core/glances_config.py
+13
-0
glances/plugins/glances_cpu.py
glances/plugins/glances_cpu.py
+38
-20
glances/plugins/glances_plugin.py
glances/plugins/glances_plugin.py
+51
-45
glances/plugins/glances_processlist.py
glances/plugins/glances_processlist.py
+2
-2
未找到文件。
conf/glances-monitor.conf
浏览文件 @
22d5e4c9
...
...
@@ -62,14 +62,17 @@ careful=45
warning
=
52
critical
=
60
[
process
]
# Limit values for CPU per process in %
[
processlist
]
# Limit values for CPU/MEM per process in %
# Default values if not defined: 50/70/90
#careful=50
#warning=70
#critical=90
# Limit values for MEM per process in %
# Default values if not defined: 50/70/90
cpu_careful
=
50
cpu_warning
=
70
cpu_critical
=
90
# Limit values for MEM per process in %
# Default values if not defined: 50/70/90
mem_careful
=
50
mem_warning
=
70
mem_critical
=
90
...
...
glances/core/glances_config.py
浏览文件 @
22d5e4c9
...
...
@@ -50,6 +50,7 @@ class Config:
self
.
parser
=
RawConfigParser
()
self
.
load
()
def
load
(
self
):
"""
Load a config file from the list of paths, if it exists
...
...
@@ -68,12 +69,14 @@ class Config:
sys
.
exit
(
1
)
break
def
get_config_path
(
self
):
"""
Return the readed configuration file path
"""
return
self
.
config_path
def
get_paths_list
(
self
):
"""
Get a list of config file paths, taking into account of the OS,
...
...
@@ -123,12 +126,21 @@ class Config:
return
paths
def
items
(
self
,
section
):
"""
Return the items list of a section
"""
return
self
.
parser
.
items
(
section
)
def
has_section
(
self
,
section
):
"""
Return info about the existence of a section
"""
return
self
.
parser
.
has_section
(
section
)
def
get_option
(
self
,
section
,
option
):
"""
Get the float value of an option, if it exists
...
...
@@ -140,6 +152,7 @@ class Config:
else
:
return
value
def
get_raw_option
(
self
,
section
,
option
):
"""
Get the raw value of an option, if it exists
...
...
glances/plugins/glances_cpu.py
浏览文件 @
22d5e4c9
...
...
@@ -20,7 +20,7 @@
# Import system libs
# Check for PSUtil already done in the glances_core script
from
psutil
import
cpu_times
from
psutil
import
cpu_times
,
cpu_times_percent
# from ..plugins.glances_plugin import GlancesPlugin
from
glances_plugin
import
GlancesPlugin
...
...
@@ -50,6 +50,24 @@ class Plugin(GlancesPlugin):
Update CPU stats
"""
# Grab CPU using the PSUtil cpu_times_percent method (PSUtil 0.7 or higher)
cputimespercent
=
cpu_times_percent
(
interval
=
0
,
percpu
=
False
)
self
.
stats
=
{}
for
cpu
in
[
'user'
,
'system'
,
'idle'
,
'nice'
,
'iowait'
,
'irq'
,
'softirq'
,
'steal'
]:
if
hasattr
(
cputimespercent
,
cpu
):
self
.
stats
[
cpu
]
=
getattr
(
cputimespercent
,
cpu
)
return
self
.
stats
def
update_deprecated
(
self
):
"""
!!! Not used anymore...
Update CPU stats
"""
# Grab CPU using the PSUtil cpu_times method
cputime
=
cpu_times
(
percpu
=
False
)
cputime_total
=
cputime
.
user
+
cputime
.
system
+
cputime
.
idle
...
...
@@ -133,20 +151,6 @@ class Plugin(GlancesPlugin):
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
"{0}"
.
format
(
format
(
self
.
stats
[
'user'
]
/
100
,
'>6.1%'
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'user'
])))
# Nice CPU
if
(
'nice'
in
self
.
stats
):
msg
=
" {0:7} {1}"
.
format
(
_
(
"nice:"
),
format
(
self
.
stats
[
'nice'
]
/
100
,
'>6.1%'
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
# New line
ret
.
append
(
self
.
curse_new_line
())
# System CPU
if
(
'system'
in
self
.
stats
):
msg
=
"{0:8}"
.
format
(
_
(
"system:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
"{0}"
.
format
(
format
(
self
.
stats
[
'system'
]
/
100
,
'>6.1%'
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'system'
])))
# IOWait CPU
if
(
'iowait'
in
self
.
stats
):
msg
=
" {0:8}"
.
format
(
_
(
"iowait:"
))
...
...
@@ -155,18 +159,32 @@ class Plugin(GlancesPlugin):
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'iowait'
]),
optional
=
True
))
# New line
ret
.
append
(
self
.
curse_new_line
())
# Idles CPU
if
(
'idle'
in
self
.
stats
):
msg
=
"{0:7} {1}"
.
format
(
_
(
"idle:"
),
format
(
self
.
stats
[
'idle'
]
/
100
,
'>6.1%'
))
# System CPU
if
(
'system'
in
self
.
stats
):
msg
=
"{0:8}"
.
format
(
_
(
"system:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
"{0}"
.
format
(
format
(
self
.
stats
[
'system'
]
/
100
,
'>6.1%'
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'system'
])))
# IRQ CPU
if
(
'irq'
in
self
.
stats
):
msg
=
" {0:7} {1}"
.
format
(
_
(
"irq:"
),
format
(
self
.
stats
[
'irq'
]
/
100
,
'>6.1%'
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
# New line
ret
.
append
(
self
.
curse_new_line
())
# Nice CPU
if
(
'nice'
in
self
.
stats
):
msg
=
"{0:7} {1}"
.
format
(
_
(
"nice:"
),
format
(
self
.
stats
[
'nice'
]
/
100
,
'>6.1%'
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
# Idles CPU
if
(
'idle'
in
self
.
stats
):
msg
=
" {0:7} {1}"
.
format
(
_
(
"idle:"
),
format
(
self
.
stats
[
'idle'
]
/
100
,
'>6.1%'
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
# Return the message with decoration
return
ret
glances/plugins/glances_plugin.py
浏览文件 @
22d5e4c9
...
...
@@ -60,16 +60,11 @@ class GlancesPlugin(object):
"""
if
(
config
.
has_section
(
self
.
plugin_name
)):
# print ">>> Load limits for %s" % self.plugin_name
# Read LOAD limits
for
s
in
[
'careful'
,
'warning'
,
'critical'
]:
try
:
value
=
config
.
get_option
(
self
.
plugin_name
,
s
)
except
:
pass
else
:
self
.
limits
[
self
.
plugin_name
+
'_'
+
s
]
=
value
# print ">>> %s = %s" % (self.plugin_name + '_' + s, value)
# print "Load limits for %s" % self.plugin_name
for
s
,
v
in
config
.
items
(
self
.
plugin_name
):
# Read limits
# print "\t%s = %s" % (self.plugin_name + '_' + s, v)
self
.
limits
[
self
.
plugin_name
+
'_'
+
s
]
=
config
.
get_option
(
self
.
plugin_name
,
s
)
def
__repr__
(
self
):
...
...
@@ -97,7 +92,7 @@ class GlancesPlugin(object):
return
self
.
limits
def
get_alert
(
self
,
current
=
0
,
min
=
0
,
max
=
100
):
def
get_alert
(
self
,
current
=
0
,
min
=
0
,
max
=
100
,
header
=
""
,
log
=
False
):
# Return the alert status relative to a current value
# Use this function for minor stat
# If current < CAREFUL of max then alert = OK
...
...
@@ -105,53 +100,64 @@ class GlancesPlugin(object):
# If current > WARNING of max then alert = WARNING
# If current > CRITICAL of max then alert = CRITICAL
# stat is USER, SYSTEM, IOWAIT or STEAL
#
# If defined 'header' is added between the plugin name and the status
# Only usefull for stats with several alert status
#
# If log=True than return the logged status
# Compute the %
try
:
value
=
(
current
*
100
)
/
max
except
ZeroDivisionError
:
return
'DEFAULT'
if
(
value
>
self
.
get_limit_critical
()):
return
'CRITICAL'
elif
(
value
>
self
.
get_limit_warning
()):
return
'WARNING'
elif
(
value
>
self
.
get_limit_careful
()):
return
'CAREFUL'
# If log is enable than add _LOG to the return string
if
(
log
):
log_str
=
"_LOG"
else
:
log_str
=
""
return
'OK'
# if (self.plugin_name == "processlist"):
# print "*"*300
# print self.limits
# sys.exit(0)
# Manage limits
if
(
value
>
self
.
get_limit_critical
(
header
=
header
)):
return
'CRITICAL'
+
log_str
elif
(
value
>
self
.
get_limit_warning
(
header
=
header
)):
return
'WARNING'
+
log_str
elif
(
value
>
self
.
get_limit_careful
(
header
=
header
)):
return
'CAREFUL'
+
log_str
# Default is ok
return
'OK'
+
log_str
def
get_alert_log
(
self
,
current
=
0
,
min
=
0
,
max
=
100
):
# Return the alert status relative to a current value
# Use this function for major stat
# If current < CAREFUL of max then alert = OK_LOG
# If current > CAREFUL of max then alert = CAREFUL_LOG
# If current > WARNING of max then alert = WARNING_LOG
# If current > CRITICAL of max then alert = CRITICAL_LOG
# stat is USER, SYSTEM, IOWAIT or STEAL
try
:
value
=
(
current
*
100
)
/
max
except
ZeroDivisionError
:
return
'DEFAULT'
if
(
value
>
self
.
get_limit_critical
()):
return
'CRITICAL_LOG'
elif
(
value
>
self
.
get_limit_warning
()):
return
'WARNING_LOG'
elif
(
value
>
self
.
get_limit_careful
()):
return
'CAREFUL_LOG'
def
get_alert_log
(
self
,
current
=
0
,
min
=
0
,
max
=
100
,
header
=
""
):
return
self
.
get_alert
(
current
,
min
,
max
,
header
,
log
=
True
)
return
'OK_LOG'
def
get_limit_critical
(
self
,
header
=
""
):
if
(
header
==
""
):
return
self
.
limits
[
self
.
plugin_name
+
'_'
+
'critical'
]
else
:
return
self
.
limits
[
self
.
plugin_name
+
'_'
+
header
+
'_'
+
'critical'
]
def
get_limit_critical
(
self
):
return
self
.
limits
[
self
.
plugin_name
+
'_'
+
'critical'
]
def
get_limit_warning
(
self
,
header
=
""
):
if
(
header
==
""
):
return
self
.
limits
[
self
.
plugin_name
+
'_'
+
'warning'
]
else
:
return
self
.
limits
[
self
.
plugin_name
+
'_'
+
header
+
'_'
+
'warning'
]
def
get_limit_warning
(
self
):
return
self
.
limits
[
self
.
plugin_name
+
'_'
+
'warning'
]
def
get_limit_careful
(
self
):
return
self
.
limits
[
self
.
plugin_name
+
'_'
+
'careful'
]
def
get_limit_careful
(
self
,
header
=
""
):
if
(
header
==
""
):
return
self
.
limits
[
self
.
plugin_name
+
'_'
+
'careful'
]
else
:
return
self
.
limits
[
self
.
plugin_name
+
'_'
+
header
+
'_'
+
'careful'
]
def
msg_curse
(
self
,
args
):
...
...
@@ -201,8 +207,8 @@ class GlancesPlugin(object):
OK_LOG: Value is OK and logged
CAREFUL: Value is CAREFUL and non logged
CAREFUL_LOG: Value is CAREFUL and logged
WAR
I
NING: Value is WARINING and non logged
WAR
I
NING_LOG: Value is WARINING and logged
WARNING: Value is WARINING and non logged
WARNING_LOG: Value is WARINING and logged
CRITICAL: Value is CRITICAL and non logged
CRITICAL_LOG: Value is CRITICAL and logged
optional: True if the stat is optional (display only if space is available)
...
...
glances/plugins/glances_processlist.py
浏览文件 @
22d5e4c9
...
...
@@ -103,10 +103,10 @@ class Plugin(GlancesPlugin):
ret
.
append
(
self
.
curse_add_line
(
msg
))
# CPU
msg
=
"{0:>6}"
.
format
(
format
(
p
[
'cpu_percent'
],
'>5.1f'
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert
(
p
[
'cpu_percent'
],
header
=
"cpu"
)
))
# MEM
msg
=
"{0:>6}"
.
format
(
format
(
p
[
'memory_percent'
],
'>5.1f'
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert
(
p
[
'memory_percent'
],
header
=
"mem"
)
))
# VMS
msg
=
"{0:>6}"
.
format
(
self
.
auto_unit
(
p
[
'memory_info'
][
1
],
low_precision
=
False
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录