Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
9f020ab1
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 搜索 >>
提交
9f020ab1
编写于
12月 13, 2014
作者:
A
Alessio Sergi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
glances_cpu.py: simplify
上级
88115d71
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
36 deletion
+24
-36
glances/plugins/glances_cpu.py
glances/plugins/glances_cpu.py
+24
-36
未找到文件。
glances/plugins/glances_cpu.py
浏览文件 @
9f020ab1
...
...
@@ -43,10 +43,11 @@ items_history_list = [{'name': 'user', 'color': '#00FF00', 'y_unit': '%'},
class
Plugin
(
GlancesPlugin
):
"""
Glances' CPU plugin.
stats is a dict
"""Glances CPU plugin.
'stats' is a dictionary that contains the system-wide CPU utilization as a
percentage.
"""
def
__init__
(
self
,
args
=
None
):
...
...
@@ -57,7 +58,6 @@ class Plugin(GlancesPlugin):
self
.
display_curse
=
True
# Init stats
self
.
first_call
=
True
self
.
reset
()
def
reset
(
self
):
...
...
@@ -70,32 +70,20 @@ class Plugin(GlancesPlugin):
# Reset stats
self
.
reset
()
# Grab CPU stats using psutil's cpu_percent and cpu_times_percent methods
if
self
.
get_input
()
==
'local'
:
# Update stats using the standard system lib
# Grab CPU using the PSUtil cpu_times_percent method
cputimespercent
=
psutil
.
cpu_times_percent
(
interval
=
0.0
,
percpu
=
False
)
# Get all possible value for CPU stats
# user
# system
# idle
# nice (UNIX)
# iowait (Linux)
# irq (Linux, FreeBSD)
# softirq (Linux)
# steal (Linux >= 2.6.11)
# Get all possible values for CPU stats: user, system, idle,
# nice (UNIX), iowait (Linux), irq (Linux, FreeBSD), steal (Linux 2.6.11+)
# The following stats are returned by the API but not displayed in the UI:
#
guest (Linux >= 2.6.24
)
# guest_nice (Linux >= 3.2
.0)
for
cpu
in
[
'user'
,
'system'
,
'idle'
,
'nice'
,
'iowait'
,
'irq'
,
'softirq'
,
'steal
'
,
'guest'
,
'guest_nice'
]:
if
hasattr
(
cpu
timespercent
,
cpu
):
self
.
stats
[
cpu
]
=
getattr
(
cputimespercent
,
cpu
)
#
softirq (Linux), guest (Linux 2.6.24+), guest_nice (Linux 3.2.0+
)
self
.
stats
[
'total'
]
=
psutil
.
cpu_percent
(
interval
=
0
.0
)
cpu_times_percent
=
psutil
.
cpu_times_percent
(
interval
=
0.0
)
for
stat
in
[
'user'
,
'system'
,
'idle'
,
'nice'
,
'iowait
'
,
'irq'
,
'softirq'
,
'steal'
,
'guest'
,
'guest_nice'
]:
if
hasattr
(
cpu
_times_percent
,
stat
):
self
.
stats
[
stat
]
=
getattr
(
cpu_times_percent
,
stat
)
elif
self
.
get_input
()
==
'snmp'
:
# Update stats using SNMP
if
self
.
get_short_system_name
()
in
(
'windows'
,
'esxi'
):
# Windows or VMWare ESXi
# You can find the CPU utilization of windows system by querying the oid
...
...
@@ -153,16 +141,16 @@ class Plugin(GlancesPlugin):
msg
=
'{0:8}'
.
format
(
_
(
"CPU"
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
"TITLE"
))
# Total CPU usage
msg
=
'{0:>
6.1%}'
.
format
((
100
-
self
.
stats
[
'idle'
])
/
100
)
msg
=
'{0:>
5}%'
.
format
(
self
.
stats
[
'total'
]
)
if
idle_tag
:
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
(
100
-
self
.
stats
[
'idle'
])
/
100
,
header
=
"system"
)
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'total'
]),
header
=
"system"
))
else
:
ret
.
append
(
self
.
curse_add_line
(
msg
))
# Nice CPU
if
'nice'
in
self
.
stats
:
msg
=
' {0:8}'
.
format
(
_
(
"nice:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
msg
=
'{0:>
6.1%}'
.
format
(
self
.
stats
[
'nice'
]
/
100
)
msg
=
'{0:>
5}%'
.
format
(
self
.
stats
[
'nice'
]
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
# New line
ret
.
append
(
self
.
curse_new_line
())
...
...
@@ -170,18 +158,18 @@ class Plugin(GlancesPlugin):
if
'user'
in
self
.
stats
:
msg
=
'{0:8}'
.
format
(
_
(
"user:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>
6.1%}'
.
format
(
self
.
stats
[
'user'
]
/
100
)
msg
=
'{0:>
5}%'
.
format
(
self
.
stats
[
'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
)
msg
=
'{0:>
5}%'
.
format
(
self
.
stats
[
'idle'
]
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
# IRQ CPU
if
'irq'
in
self
.
stats
:
msg
=
' {0:8}'
.
format
(
_
(
"irq:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
msg
=
'{0:>
6.1%}'
.
format
(
self
.
stats
[
'irq'
]
/
100
)
msg
=
'{0:>
5}%'
.
format
(
self
.
stats
[
'irq'
]
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
# New line
ret
.
append
(
self
.
curse_new_line
())
...
...
@@ -189,7 +177,7 @@ class Plugin(GlancesPlugin):
if
'system'
in
self
.
stats
and
not
idle_tag
:
msg
=
'{0:8}'
.
format
(
_
(
"system:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>
6.1%}'
.
format
(
self
.
stats
[
'system'
]
/
100
)
msg
=
'{0:>
5}%'
.
format
(
self
.
stats
[
'system'
]
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'system'
],
header
=
"system"
)))
else
:
msg
=
'{0:8}'
.
format
(
_
(
"core:"
))
...
...
@@ -200,7 +188,7 @@ class Plugin(GlancesPlugin):
if
'iowait'
in
self
.
stats
:
msg
=
' {0:8}'
.
format
(
_
(
"iowait:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
msg
=
'{0:>
6.1%}'
.
format
(
self
.
stats
[
'iowait'
]
/
100
)
msg
=
'{0:>
5}%'
.
format
(
self
.
stats
[
'iowait'
]
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'iowait'
],
header
=
"iowait"
),
optional
=
True
))
# New line
ret
.
append
(
self
.
curse_new_line
())
...
...
@@ -208,13 +196,13 @@ class Plugin(GlancesPlugin):
if
'idle'
in
self
.
stats
and
not
idle_tag
:
msg
=
'{0:8}'
.
format
(
_
(
"idle:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>
6.1%}'
.
format
(
self
.
stats
[
'idle'
]
/
100
)
msg
=
'{0:>
5}%'
.
format
(
self
.
stats
[
'idle'
]
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
# Steal CPU usage
if
'steal'
in
self
.
stats
:
msg
=
' {0:8}'
.
format
(
_
(
"steal:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
msg
=
'{0:>
6.1%}'
.
format
(
self
.
stats
[
'steal'
]
/
100
)
msg
=
'{0:>
5}%'
.
format
(
self
.
stats
[
'steal'
]
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert
(
self
.
stats
[
'steal'
],
header
=
"steal"
),
optional
=
True
))
# Return the message with decoration
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录