Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
bf28f605
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,发现更多精彩内容 >>
提交
bf28f605
编写于
1月 10, 2013
作者:
N
Nicolas Hennion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add fct to define color/alert
上级
8eacbf4c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
184 addition
and
77 deletion
+184
-77
glances/conf/glances.conf
glances/conf/glances.conf
+12
-0
glances/glances.py
glances/glances.py
+172
-77
未找到文件。
glances/conf/glances.conf
浏览文件 @
bf28f605
...
...
@@ -60,3 +60,15 @@ critical=80
careful
=
50
warning
=
70
critical
=
90
[
process
]
# Limits values for CPU per process in %
# Defaults values if not defined: 50/70/90
cpu_careful
=
50
cpu_warning
=
70
cpu_critical
=
90
# Limits values for MEM per process in %
# Defaults values if not defined: 50/70/90
mem_careful
=
50
mem_warning
=
70
mem_critical
=
90
glances/glances.py
浏览文件 @
bf28f605
...
...
@@ -224,7 +224,9 @@ class glancesLimits:
'MEM'
:
[
50
,
70
,
90
],
'SWAP'
:
[
50
,
70
,
90
],
'TEMP'
:
[
60
,
70
,
80
],
'FS'
:
[
50
,
70
,
90
]}
'FS'
:
[
50
,
70
,
90
],
'PROCESS_CPU'
:
[
50
,
70
,
90
],
'PROCESS_MEM'
:
[
50
,
70
,
90
]}
def
__init__
(
self
,
conf_file
=
default_conf_file
):
# Open the configuration file
...
...
@@ -273,6 +275,14 @@ class glancesLimits:
self
.
__setLimits
(
config
,
'filesystem'
,
'FS'
,
'careful'
)
self
.
__setLimits
(
config
,
'filesystem'
,
'FS'
,
'warning'
)
self
.
__setLimits
(
config
,
'filesystem'
,
'FS'
,
'critical'
)
if
(
config
.
has_section
(
'process'
)):
# Process limits
self
.
__setLimits
(
config
,
'process'
,
'PROCESS_CPU'
,
'cpu_careful'
)
self
.
__setLimits
(
config
,
'process'
,
'PROCESS_CPU'
,
'cpu_warning'
)
self
.
__setLimits
(
config
,
'process'
,
'PROCESS_CPU'
,
'cpu_critical'
)
self
.
__setLimits
(
config
,
'process'
,
'PROCESS_MEM'
,
'mem_careful'
)
self
.
__setLimits
(
config
,
'process'
,
'PROCESS_MEM'
,
'mem_warning'
)
self
.
__setLimits
(
config
,
'process'
,
'PROCESS_MEM'
,
'mem_critical'
)
def
__setLimits
(
self
,
config
,
section
,
stat
,
alert
):
"""
...
...
@@ -366,6 +376,15 @@ class glancesLimits:
def
getFSCritical
(
self
):
return
self
.
getCritical
(
'FS'
)
def
getProcessCareful
(
self
,
stat
=
''
):
return
self
.
getCareful
(
'PROCESS_'
+
stat
.
upper
())
def
getProcessWarning
(
self
,
stat
=
''
):
return
self
.
getWarning
(
'PROCESS_'
+
stat
.
upper
())
def
getProcessCritical
(
self
,
stat
=
''
):
return
self
.
getWarning
(
'PROCESS_'
+
stat
.
upper
())
class
glancesLogs
:
"""
...
...
@@ -1422,37 +1441,6 @@ class glancesScreen:
return
"{0!s}"
.
format
(
val
)
def
__getAlert
(
self
,
current
=
0
,
max
=
100
):
# If current < CAREFUL of max then alert = OK
# If current > CAREFUL of max then alert = CAREFUL
# If current > WARNING of max then alert = WARNING
# If current > CRITICAL of max then alert = CRITICAL
try
:
variable
=
(
current
*
100
)
/
max
except
ZeroDivisionError
:
return
'DEFAULT'
if
variable
>
limits
.
getSTDCritical
():
return
'CRITICAL'
elif
variable
>
limits
.
getSTDWarning
():
return
'WARNING'
elif
variable
>
limits
.
getSTDCareful
():
return
'CAREFUL'
return
'OK'
def
__getColor
(
self
,
current
=
0
,
max
=
100
):
"""
Return colors for logged stats
"""
return
self
.
__colors_list
[
self
.
__getAlert
(
current
,
max
)]
def
__getColor2
(
self
,
current
=
0
,
max
=
100
):
"""
Return colors for non logged stats
"""
return
self
.
__colors_list2
[
self
.
__getAlert
(
current
,
max
)]
def
__getCpuAlert
(
self
,
current
=
0
,
max
=
100
,
stat
=
''
):
# If current < CAREFUL of max then alert = OK
# If current > CAREFUL of max then alert = CAREFUL
...
...
@@ -1496,6 +1484,9 @@ class glancesScreen:
def
__getLoadColor
(
self
,
current
=
0
,
core
=
1
):
return
self
.
__colors_list
[
self
.
__getLoadAlert
(
current
,
core
)]
def
__getLoadColor2
(
self
,
current
=
0
,
core
=
1
):
return
self
.
__colors_list2
[
self
.
__getLoadAlert
(
current
,
core
)]
def
__getMemAlert
(
self
,
current
=
0
,
max
=
100
):
# If current < CAREFUL of max then alert = OK
# If current > CAREFUL of max then alert = CAREFUL
...
...
@@ -1515,7 +1506,13 @@ class glancesScreen:
return
'OK'
def
__getSWAPAlert
(
self
,
current
=
0
,
max
=
100
):
def
__getMemColor
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__colors_list
[
self
.
__getMemAlert
(
current
,
max
)]
def
__getMemColor2
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__colors_list2
[
self
.
__getMemAlert
(
current
,
max
)]
def
__getSwapAlert
(
self
,
current
=
0
,
max
=
100
):
# If current < CAREFUL of max then alert = OK
# If current > CAREFUL of max then alert = CAREFUL
# If current > WARNING of max then alert = WARNING
...
...
@@ -1534,14 +1531,11 @@ class glancesScreen:
return
'OK'
def
__get
Mem
Color
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__
getColor
(
current
,
max
)
def
__get
Swap
Color
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__
colors_list
[
self
.
__getSwapAlert
(
current
,
max
)]
def
__getMemColor2
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__getColor2
(
current
,
max
)
def
__getNetColor
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__getColor2
(
current
,
max
)
def
__getSwapColor2
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__colors_list2
[
self
.
__getSwapAlert
(
current
,
max
)]
def
__getFsAlert
(
self
,
current
=
0
,
max
=
100
):
# If current < CAREFUL of max then alert = OK
...
...
@@ -1563,10 +1557,10 @@ class glancesScreen:
return
'OK'
def
__getFsColor
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__colors_list
2
[
self
.
__getFsAlert
(
current
,
max
)]
return
self
.
__colors_list
[
self
.
__getFsAlert
(
current
,
max
)]
def
__get
ProcessColor
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__
getColor2
(
current
,
max
)
def
__get
FsColor2
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__
colors_list2
[
self
.
__getFsAlert
(
current
,
max
)]
def
__getSensorsAlert
(
self
,
current
=
0
):
# Alert for Sensors (temperature in degre)
...
...
@@ -1586,10 +1580,47 @@ class glancesScreen:
def
__getSensorsColor
(
self
,
current
=
0
):
"""
Return color for Sensors temperature (non logged stats)
Return color for Sensors temperature
"""
return
self
.
__colors_list
[
self
.
__getSensorsAlert
(
current
)]
def
__getSensorsColor2
(
self
,
current
=
0
):
"""
Return color for Sensors temperature
"""
return
self
.
__colors_list2
[
self
.
__getSensorsAlert
(
current
)]
def
__getProcessAlert
(
self
,
current
=
0
,
max
=
100
,
stat
=
''
):
# If current < CAREFUL of max then alert = OK
# If current > CAREFUL of max then alert = CAREFUL
# If current > WARNING of max then alert = WARNING
# If current > CRITICAL of max then alert = CRITICAL
try
:
variable
=
(
current
*
100
)
/
max
except
ZeroDivisionError
:
return
'DEFAULT'
if
(
variable
>
limits
.
getProcessCritical
(
stat
=
stat
)):
return
'CRITICAL'
elif
(
variable
>
limits
.
getProcessWarning
(
stat
=
stat
)):
return
'WARNING'
elif
(
variable
>
limits
.
getProcessCareful
(
stat
=
stat
)):
return
'CAREFUL'
return
'OK'
def
__getProcessCpuColor
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__colors_list
[
self
.
__getProcessAlert
(
current
,
max
,
'CPU'
)]
def
__getProcessCpuColor2
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__colors_list2
[
self
.
__getProcessAlert
(
current
,
max
,
'CPU'
)]
def
__getProcessMemColor
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__colors_list
[
self
.
__getProcessAlert
(
current
,
max
,
'MEM'
)]
def
__getProcessMemColor2
(
self
,
current
=
0
,
max
=
100
):
return
self
.
__colors_list2
[
self
.
__getProcessAlert
(
current
,
max
,
'MEM'
)]
def
__catchKey
(
self
):
# Get key
self
.
pressedkey
=
self
.
term_window
.
getch
()
...
...
@@ -1845,20 +1876,18 @@ class glancesScreen:
y
=
1
# user
self
.
term_window
.
addnstr
(
self
.
cpu_y
+
y
,
self
.
cpu_x
,
_
(
"user:"
),
5
)
alert
=
self
.
__getCpuAlert
(
cpu
[
'user'
],
stat
=
'user'
)
self
.
term_window
.
addnstr
(
self
.
cpu_y
+
y
,
self
.
cpu_x
+
8
,
format
(
cpu
[
'user'
]
/
100
,
'>6.1%'
),
6
,
self
.
__
colors_list
[
alert
]
)
self
.
__
getCpuColor
(
cpu
[
'user'
],
stat
=
'user'
)
)
y
+=
1
# system
if
'system'
in
cpu
:
self
.
term_window
.
addnstr
(
self
.
cpu_y
+
y
,
self
.
cpu_x
,
_
(
"system:"
),
7
)
alert
=
self
.
__getCpuAlert
(
cpu
[
'system'
],
stat
=
'system'
)
self
.
term_window
.
addnstr
(
self
.
cpu_y
+
y
,
self
.
cpu_x
+
8
,
format
(
cpu
[
'system'
]
/
100
,
'>6.1%'
),
6
,
self
.
__
colors_list
[
alert
]
)
self
.
__
getCpuColor
(
cpu
[
'system'
],
stat
=
'system'
)
)
y
+=
1
# idle
...
...
@@ -1936,7 +1965,7 @@ class glancesScreen:
self
.
term_window
.
addnstr
(
self
.
load_y
+
2
,
self
.
load_x
+
offset_x
+
8
,
format
(
load
[
'min5'
],
'>5.2f'
),
5
,
self
.
__
colors_list
[
alert
]
)
self
.
__
getLoadColor
(
load
[
'min5'
],
core
)
)
# 15 min
self
.
term_window
.
addnstr
(
self
.
load_y
+
3
,
...
...
@@ -1946,7 +1975,7 @@ class glancesScreen:
self
.
term_window
.
addnstr
(
self
.
load_y
+
3
,
self
.
load_x
+
offset_x
+
8
,
format
(
load
[
'min15'
],
'>5.2f'
),
5
,
self
.
__
colors_list
[
alert
]
)
self
.
__
getLoadColor
(
load
[
'min15'
],
core
)
)
# return the x offset to display mem
return
offset_x
...
...
@@ -1989,7 +2018,7 @@ class glancesScreen:
self
.
term_window
.
addnstr
(
self
.
mem_y
+
2
,
self
.
mem_x
+
offset_x
+
7
,
format
(
self
.
__autoUnit
(
mem
[
'used'
]),
'>5'
),
5
,
self
.
__
colors_list
[
alert
]
)
self
.
__
getMemColor
(
mem
[
'used'
],
mem
[
'total'
])
)
# free
self
.
term_window
.
addnstr
(
self
.
mem_y
+
3
,
self
.
mem_x
+
offset_x
,
...
...
@@ -2071,7 +2100,7 @@ class glancesScreen:
format
(
self
.
__autoUnit
(
memswap
[
'total'
]),
'>5'
),
8
)
# used
alert
=
self
.
__getS
WAP
Alert
(
memswap
[
'used'
],
memswap
[
'total'
])
alert
=
self
.
__getS
wap
Alert
(
memswap
[
'used'
],
memswap
[
'total'
])
logs
.
add
(
alert
,
"MEM swap"
,
memswap
[
'used'
],
proclist
)
self
.
term_window
.
addnstr
(
self
.
mem_y
+
2
,
self
.
mem_x
+
offset_x
+
32
,
...
...
@@ -2079,7 +2108,7 @@ class glancesScreen:
self
.
term_window
.
addnstr
(
self
.
mem_y
+
2
,
self
.
mem_x
+
offset_x
+
39
,
format
(
self
.
__autoUnit
(
memswap
[
'used'
]),
'>5'
),
8
,
self
.
__
colors_list
[
alert
]
)
self
.
__
getSwapColor
(
memswap
[
'used'
],
memswap
[
'total'
])
)
# free
self
.
term_window
.
addnstr
(
self
.
mem_y
+
3
,
...
...
@@ -2260,18 +2289,16 @@ class glancesScreen:
self
.
fs_y
+
1
+
mounted
,
self
.
fs_x
,
fs
[
mounted
][
'mnt_point'
],
8
)
fs_usage
=
fs
[
mounted
][
'used'
]
fs_size
=
fs
[
mounted
][
'size'
]
# used
self
.
term_window
.
addnstr
(
self
.
fs_y
+
1
+
mounted
,
self
.
fs_x
+
9
,
format
(
self
.
__autoUnit
(
fs
_usage
),
'>6'
),
6
,
self
.
__getFsColor
(
fs_usage
,
fs_size
))
format
(
self
.
__autoUnit
(
fs
[
mounted
][
'used'
]
),
'>6'
),
6
,
self
.
__getFsColor
2
(
fs
[
mounted
][
'used'
],
fs
[
mounted
][
'size'
]
))
# total
self
.
term_window
.
addnstr
(
self
.
fs_y
+
1
+
mounted
,
self
.
fs_x
+
17
,
format
(
self
.
__autoUnit
(
fs
_size
),
'>6'
),
6
)
format
(
self
.
__autoUnit
(
fs
[
mounted
][
'size'
]
),
'>6'
),
6
)
return
mounted
+
3
return
0
...
...
@@ -2514,7 +2541,7 @@ class glancesScreen:
self
.
term_window
.
addnstr
(
self
.
process_y
+
3
+
processes
,
process_x
+
12
,
format
(
cpu_percent
,
'>5.1f'
),
5
,
self
.
__getProcessC
olor
(
cpu_percent
))
self
.
__getProcessC
puColor2
(
cpu_percent
))
else
:
self
.
term_window
.
addnstr
(
self
.
process_y
+
3
+
processes
,
process_x
,
"N/A"
,
8
)
...
...
@@ -2523,7 +2550,7 @@ class glancesScreen:
self
.
term_window
.
addnstr
(
self
.
process_y
+
3
+
processes
,
process_x
+
18
,
format
(
memory_percent
,
'>5.1f'
),
5
,
self
.
__getProcess
Color
(
memory_percent
))
self
.
__getProcess
MemColor2
(
memory_percent
))
# If screen space (X) is available then:
# PID
if
tag_pid
:
...
...
@@ -2670,31 +2697,49 @@ class glancesScreen:
width
=
8
limits_table_x
=
self
.
help_x
limits_table_y
=
self
.
help_y
+
2
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
,
_
(
"Limits > "
),
8
)
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
+
10
,
_
(
" OK "
),
8
,
self
.
default_color
)
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
+
18
,
_
(
"
CAREFUL "
),
8
,
self
.
ifCAREFUL
_color
)
_
(
"
OK "
),
8
,
self
.
default
_color
)
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
+
26
,
_
(
"
WARNING "
),
8
,
self
.
ifWARNING
_color
)
_
(
"
CAREFUL "
),
8
,
self
.
ifCAREFUL
_color
)
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
+
34
,
_
(
"WARNING "
),
8
,
self
.
ifWARNING_color
)
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
+
42
,
_
(
"CRITICAL"
),
8
,
self
.
ifCRITICAL_color
)
#~ limits_table_y += 1
#~ self.term_window.addnstr(
#~ limits_table_y, limits_table_x,
#~ "{0:16} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}".format(
#~ _("Default %"),
#~ '0',
#~ limits.getSTDCareful(),
#~ limits.getSTDWarning(),
#~ limits.getSTDCritical(),
#~ width=width), 79)
limits_table_y
+=
1
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
,
"{0:^
{width}
} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"
Default %
"
),
"{0:^
16
} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"
CPU user %
"
),
'0'
,
limits
.
get
STDCareful
(
),
limits
.
get
STDWarning
(
),
limits
.
get
STDCritical
(
),
limits
.
get
CPUCareful
(
stat
=
'user'
),
limits
.
get
CPUWarning
(
stat
=
'user'
),
limits
.
get
CPUCritical
(
stat
=
'user'
),
width
=
width
),
79
)
limits_table_y
+=
1
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
,
"{0:^{width}} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"IOwait % "
),
"{0:^16} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"CPU system % "
),
'0'
,
limits
.
getCPUCareful
(
stat
=
'system'
),
limits
.
getCPUWarning
(
stat
=
'system'
),
limits
.
getCPUCritical
(
stat
=
'system'
),
width
=
width
),
79
)
limits_table_y
+=
1
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
,
"{0:^16} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"CPU IOwait % "
),
'0'
,
limits
.
getCPUCareful
(
stat
=
'iowait'
),
limits
.
getCPUWarning
(
stat
=
'iowait'
),
...
...
@@ -2703,8 +2748,8 @@ class glancesScreen:
limits_table_y
+=
1
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
,
"{0:^
{width}
} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"Load "
),
"{0:^
16
} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"Load
"
),
'0'
,
limits
.
getLOADCareful
()
*
core
,
limits
.
getLOADWarning
()
*
core
,
...
...
@@ -2713,13 +2758,63 @@ class glancesScreen:
limits_table_y
+=
1
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
,
"{0:^{width}} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"Temp °C "
),
"{0:^16} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"RAM Memory % "
),
'0'
,
limits
.
getMEMCareful
(),
limits
.
getMEMWarning
(),
limits
.
getMEMCritical
(),
width
=
width
),
79
)
limits_table_y
+=
1
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
,
"{0:^16} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"Swap memory %"
),
'0'
,
limits
.
getSWAPCareful
(),
limits
.
getSWAPWarning
(),
limits
.
getSWAPCritical
(),
width
=
width
),
79
)
limits_table_y
+=
1
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
,
"{0:^16} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"Temp °C "
),
'0'
,
limits
.
getTEMPCareful
(),
limits
.
getTEMPWarning
(),
limits
.
getTEMPCritical
(),
width
=
width
),
79
)
limits_table_y
+=
1
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
,
"{0:^16} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"Filesystem % "
),
'0'
,
limits
.
getFSCareful
(),
limits
.
getFSWarning
(),
limits
.
getFSCritical
(),
width
=
width
),
79
)
limits_table_y
+=
1
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
,
"{0:^16} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"CPU Process %"
),
'0'
,
limits
.
getProcessCareful
(
stat
=
'CPU'
),
limits
.
getProcessWarning
(
stat
=
'CPU'
),
limits
.
getProcessCritical
(
stat
=
'CPU'
),
width
=
width
),
79
)
limits_table_y
+=
1
self
.
term_window
.
addnstr
(
limits_table_y
,
limits_table_x
,
"{0:^16} {1:^{width}}{2:^{width}}{3:^{width}}{4:^{width}}"
.
format
(
_
(
"MEM Process %"
),
'0'
,
limits
.
getProcessCareful
(
stat
=
'MEM'
),
limits
.
getProcessWarning
(
stat
=
'MEM'
),
limits
.
getProcessCritical
(
stat
=
'MEM'
),
width
=
width
),
79
)
# Key table (first column)
width
=
5
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录