Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
0e7685ff
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 搜索 >>
提交
0e7685ff
编写于
6月 27, 2014
作者:
N
Nicolas Hennion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MEMSWAP + CPU ok on Windows SNMP fallback mode
上级
9dda132c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
76 addition
and
31 deletion
+76
-31
glances/plugins/glances_cpu.py
glances/plugins/glances_cpu.py
+34
-11
glances/plugins/glances_mem.py
glances/plugins/glances_mem.py
+3
-3
glances/plugins/glances_memswap.py
glances/plugins/glances_memswap.py
+39
-17
未找到文件。
glances/plugins/glances_cpu.py
浏览文件 @
0e7685ff
...
@@ -98,13 +98,21 @@ class Plugin(GlancesPlugin):
...
@@ -98,13 +98,21 @@ class Plugin(GlancesPlugin):
# Give also the number of core (number of element in the table)
# Give also the number of core (number of element in the table)
# print snmp_oid[self.get_short_system_name()]
# print snmp_oid[self.get_short_system_name()]
try
:
try
:
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
self
.
get_short_system_name
()],
cpu_
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
self
.
get_short_system_name
()],
bulk
=
True
)
bulk
=
True
)
except
KeyError
:
except
KeyError
:
self
.
reset
()
self
.
reset
()
# TODO: iter through CPU... startswith('percent')
# Iter through CPU and compute the idle CPU stats
self
.
stats
[
'idle'
]
=
self
.
stats
[
'percent.3'
]
self
.
stats
[
'nb_log_core'
]
=
0
self
.
stats
[
'idle'
]
=
0
for
c
in
cpu_stats
:
if
c
.
startswith
(
'percent'
):
self
.
stats
[
'idle'
]
+=
float
(
cpu_stats
[
'percent.3'
])
self
.
stats
[
'nb_log_core'
]
+=
1
if
self
.
stats
[
'nb_log_core'
]
>
0
:
self
.
stats
[
'idle'
]
=
self
.
stats
[
'idle'
]
/
self
.
stats
[
'nb_log_core'
]
self
.
stats
[
'idle'
]
=
100
-
self
.
stats
[
'idle'
]
else
:
else
:
# Default behavor
# Default behavor
...
@@ -117,9 +125,9 @@ class Plugin(GlancesPlugin):
...
@@ -117,9 +125,9 @@ class Plugin(GlancesPlugin):
self
.
reset
()
self
.
reset
()
return
self
.
stats
return
self
.
stats
# Convert SNMP stats to float
# Convert SNMP stats to float
for
key
in
self
.
stats
.
iterkeys
():
for
key
in
self
.
stats
.
iterkeys
():
self
.
stats
[
key
]
=
float
(
self
.
stats
[
key
])
self
.
stats
[
key
]
=
float
(
self
.
stats
[
key
])
return
self
.
stats
return
self
.
stats
...
@@ -133,12 +141,17 @@ class Plugin(GlancesPlugin):
...
@@ -133,12 +141,17 @@ class Plugin(GlancesPlugin):
return
ret
return
ret
# Build the string message
# Build the string message
# If user stat is not here, display only idle / total CPU usage (for exemple on Windows OS)
idle_tag
=
'user'
not
in
self
.
stats
# Header
# Header
msg
=
'{0:8}'
.
format
(
_
(
"CPU"
))
msg
=
'{0:8}'
.
format
(
_
(
"CPU"
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
"TITLE"
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
"TITLE"
))
# Total CPU usage
# Total CPU usage
msg
=
'{0:>6.1%}'
.
format
((
100
-
self
.
stats
[
'idle'
])
/
100
)
msg
=
'{0:>6.1%}'
.
format
((
100
-
self
.
stats
[
'idle'
])
/
100
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
if
idle_tag
:
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
((
100
-
self
.
stats
[
'idle'
])
/
100
,
header
=
"system"
)))
else
:
ret
.
append
(
self
.
curse_add_line
(
msg
))
# Nice CPU
# Nice CPU
if
'nice'
in
self
.
stats
:
if
'nice'
in
self
.
stats
:
msg
=
' {0:8}'
.
format
(
_
(
"nice:"
))
msg
=
' {0:8}'
.
format
(
_
(
"nice:"
))
...
@@ -152,7 +165,12 @@ class Plugin(GlancesPlugin):
...
@@ -152,7 +165,12 @@ class Plugin(GlancesPlugin):
msg
=
'{0:8}'
.
format
(
_
(
"user:"
))
msg
=
'{0:8}'
.
format
(
_
(
"user:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>6.1%}'
.
format
(
self
.
stats
[
'user'
]
/
100
)
msg
=
'{0:>6.1%}'
.
format
(
self
.
stats
[
'user'
]
/
100
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'user'
],
header
=
"user"
)))
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'user'
],
header
=
"user"
)))
elif
'idle'
in
self
.
stats
:
msg
=
'{0:8}'
.
format
(
_
(
"idle:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>6.1%}'
.
format
(
self
.
stats
[
'idle'
]
/
100
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
# IRQ CPU
# IRQ CPU
if
'irq'
in
self
.
stats
:
if
'irq'
in
self
.
stats
:
msg
=
' {0:8}'
.
format
(
_
(
"irq:"
))
msg
=
' {0:8}'
.
format
(
_
(
"irq:"
))
...
@@ -162,11 +180,16 @@ class Plugin(GlancesPlugin):
...
@@ -162,11 +180,16 @@ class Plugin(GlancesPlugin):
# New line
# New line
ret
.
append
(
self
.
curse_new_line
())
ret
.
append
(
self
.
curse_new_line
())
# System CPU
# System CPU
if
'system'
in
self
.
stats
:
if
'system'
in
self
.
stats
and
not
idle_tag
:
msg
=
'{0:8}'
.
format
(
_
(
"system:"
))
msg
=
'{0:8}'
.
format
(
_
(
"system:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>6.1%}'
.
format
(
self
.
stats
[
'system'
]
/
100
)
msg
=
'{0:>6.1%}'
.
format
(
self
.
stats
[
'system'
]
/
100
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'system'
],
header
=
"system"
)))
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'system'
],
header
=
"system"
)))
else
:
msg
=
'{0:8}'
.
format
(
_
(
"core:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>6}'
.
format
(
self
.
stats
[
'nb_log_core'
])
ret
.
append
(
self
.
curse_add_line
(
msg
))
# IOWait CPU
# IOWait CPU
if
'iowait'
in
self
.
stats
:
if
'iowait'
in
self
.
stats
:
msg
=
' {0:8}'
.
format
(
_
(
"iowait:"
))
msg
=
' {0:8}'
.
format
(
_
(
"iowait:"
))
...
@@ -176,7 +199,7 @@ class Plugin(GlancesPlugin):
...
@@ -176,7 +199,7 @@ class Plugin(GlancesPlugin):
# New line
# New line
ret
.
append
(
self
.
curse_new_line
())
ret
.
append
(
self
.
curse_new_line
())
# Idle CPU
# Idle CPU
if
'idle'
in
self
.
stats
:
if
'idle'
in
self
.
stats
and
not
idle_tag
:
msg
=
'{0:8}'
.
format
(
_
(
"idle:"
))
msg
=
'{0:8}'
.
format
(
_
(
"idle:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>6.1%}'
.
format
(
self
.
stats
[
'idle'
]
/
100
)
msg
=
'{0:>6.1%}'
.
format
(
self
.
stats
[
'idle'
]
/
100
)
...
...
glances/plugins/glances_mem.py
浏览文件 @
0e7685ff
...
@@ -117,9 +117,9 @@ class Plugin(GlancesPlugin):
...
@@ -117,9 +117,9 @@ class Plugin(GlancesPlugin):
except
KeyError
:
except
KeyError
:
self
.
reset
()
self
.
reset
()
else
:
else
:
for
fs
in
fs_stat
:
for
fs
in
fs_stat
:
#
Memory stats are grabed in the same OID table (ignore it)
#
The Physical Memory gives statistics on RAM usage and availability.
if
fs
==
'
Virtu
al Memory'
:
if
fs
==
'
Physic
al Memory'
:
self
.
stats
[
'total'
]
=
int
(
fs_stat
[
fs
][
'size'
])
*
int
(
fs_stat
[
fs
][
'alloc_unit'
])
self
.
stats
[
'total'
]
=
int
(
fs_stat
[
fs
][
'size'
])
*
int
(
fs_stat
[
fs
][
'alloc_unit'
])
self
.
stats
[
'used'
]
=
int
(
fs_stat
[
fs
][
'used'
])
*
int
(
fs_stat
[
fs
][
'alloc_unit'
])
self
.
stats
[
'used'
]
=
int
(
fs_stat
[
fs
][
'used'
])
*
int
(
fs_stat
[
fs
][
'alloc_unit'
])
self
.
stats
[
'percent'
]
=
float
(
self
.
stats
[
'used'
]
*
100
/
self
.
stats
[
'total'
])
self
.
stats
[
'percent'
]
=
float
(
self
.
stats
[
'used'
]
*
100
/
self
.
stats
[
'total'
])
...
...
glances/plugins/glances_memswap.py
浏览文件 @
0e7685ff
...
@@ -26,8 +26,12 @@ import psutil
...
@@ -26,8 +26,12 @@ import psutil
# SNMP OID
# SNMP OID
# Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
# Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
# Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
# Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
snmp_oid
=
{
'total'
:
'1.3.6.1.4.1.2021.4.3.0'
,
snmp_oid
=
{
'default'
:
{
'total'
:
'1.3.6.1.4.1.2021.4.3.0'
,
'free'
:
'1.3.6.1.4.1.2021.4.4.0'
}
'free'
:
'1.3.6.1.4.1.2021.4.4.0'
},
'windows'
:
{
'mnt_point'
:
'1.3.6.1.2.1.25.2.3.1.3'
,
'alloc_unit'
:
'1.3.6.1.2.1.25.2.3.1.4'
,
'size'
:
'1.3.6.1.2.1.25.2.3.1.5'
,
'used'
:
'1.3.6.1.2.1.25.2.3.1.6'
}}
class
Plugin
(
GlancesPlugin
):
class
Plugin
(
GlancesPlugin
):
...
@@ -80,21 +84,39 @@ class Plugin(GlancesPlugin):
...
@@ -80,21 +84,39 @@ class Plugin(GlancesPlugin):
self
.
stats
[
swap
]
=
getattr
(
sm_stats
,
swap
)
self
.
stats
[
swap
]
=
getattr
(
sm_stats
,
swap
)
elif
self
.
get_input
()
==
'snmp'
:
elif
self
.
get_input
()
==
'snmp'
:
# Update stats using SNMP
# Update stats using SNMP
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
)
if
self
.
get_short_system_name
()
==
'windows'
:
# Mem stats for Windows OS are stored in the FS table
if
self
.
stats
[
'total'
]
==
''
:
try
:
self
.
reset
()
fs_stat
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
self
.
get_short_system_name
()],
return
self
.
stats
bulk
=
True
)
except
KeyError
:
for
key
in
self
.
stats
.
iterkeys
():
self
.
reset
()
if
self
.
stats
[
key
]
!=
''
:
else
:
self
.
stats
[
key
]
=
float
(
self
.
stats
[
key
])
*
1024
for
fs
in
fs_stat
:
# The virtual memory concept is used by the operating system to extend (virtually) the physical
# used=total-free
# memory and thus to run more programs by swapping unused memory zone (page) to a disk file.
self
.
stats
[
'used'
]
=
self
.
stats
[
'total'
]
-
self
.
stats
[
'free'
]
if
fs
==
'Virtual Memory'
:
self
.
stats
[
'total'
]
=
int
(
fs_stat
[
fs
][
'size'
])
*
int
(
fs_stat
[
fs
][
'alloc_unit'
])
# percent: the percentage usage calculated as (total - available) / total * 100.
self
.
stats
[
'used'
]
=
int
(
fs_stat
[
fs
][
'used'
])
*
int
(
fs_stat
[
fs
][
'alloc_unit'
])
self
.
stats
[
'percent'
]
=
float
((
self
.
stats
[
'total'
]
-
self
.
stats
[
'free'
])
/
self
.
stats
[
'total'
]
*
100
)
self
.
stats
[
'percent'
]
=
float
(
self
.
stats
[
'used'
]
*
100
/
self
.
stats
[
'total'
])
self
.
stats
[
'free'
]
=
self
.
stats
[
'total'
]
-
self
.
stats
[
'used'
]
break
else
:
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
)
if
self
.
stats
[
'total'
]
==
''
:
self
.
reset
()
return
self
.
stats
for
key
in
self
.
stats
.
iterkeys
():
if
self
.
stats
[
key
]
!=
''
:
self
.
stats
[
key
]
=
float
(
self
.
stats
[
key
])
*
1024
# used=total-free
self
.
stats
[
'used'
]
=
self
.
stats
[
'total'
]
-
self
.
stats
[
'free'
]
# percent: the percentage usage calculated as (total - available) / total * 100.
self
.
stats
[
'percent'
]
=
float
((
self
.
stats
[
'total'
]
-
self
.
stats
[
'free'
])
/
self
.
stats
[
'total'
]
*
100
)
return
self
.
stats
return
self
.
stats
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录