Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
4bcac1cb
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 搜索 >>
提交
4bcac1cb
编写于
3月 11, 2014
作者:
N
Nicolas Hennion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor System and Cpu plugins for PsUtil 2.0
上级
80051c81
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
70 deletion
+44
-70
glances/plugins/glances_cpu.py
glances/plugins/glances_cpu.py
+38
-69
glances/plugins/glances_system.py
glances/plugins/glances_system.py
+6
-1
未找到文件。
glances/plugins/glances_cpu.py
浏览文件 @
4bcac1cb
...
...
@@ -17,13 +17,17 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Glances CPU plugin
"""
# Import system libs
# Check for PSUtil already done in the glances_core script
from
psutil
import
cpu_times
,
cpu_times_percent
import
time
# from ..plugins.glances_plugin import GlancesPlugin
from
glances_plugin
import
GlancesPlugin
from
glances
.plugins.glances
_plugin
import
GlancesPlugin
class
Plugin
(
GlancesPlugin
):
...
...
@@ -45,88 +49,53 @@ class Plugin(GlancesPlugin):
# Enter -1 to diplay bottom
self
.
line_curse
=
1
# Init stats
self
.
first_call
=
True
self
.
stats
=
{}
def
update
(
self
):
"""
Update CPU stats
"""
# Grab CPU using the PSUtil cpu_times_percent method (PSUtil 0.7 or higher)
try
:
cputimespercent
=
cpu_times_percent
(
interval
=
0
,
percpu
=
False
)
except
:
return
self
.
update_deprecated
()
self
.
stats
=
{}
# Grab CPU using the PSUtil cpu_times_percent method
# !!! the first time this function is called with interval = 0.0 or None
# !!! it will return a meaningless 0.0 value which you are supposed to ignore
cputimespercent
=
cpu_times_percent
(
interval
=
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)
# 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)
cpu_stats
=
{}
for
cpu
in
[
'user'
,
'system'
,
'idle'
,
'nice'
,
'iowait'
,
'irq'
,
'softirq'
,
'steal'
]:
'iowait'
,
'irq'
,
'softirq'
,
'steal'
,
'guest'
,
'guest_nice'
]:
if
hasattr
(
cputimespercent
,
cpu
):
self
.
stats
[
cpu
]
=
getattr
(
cputimespercent
,
cpu
)
return
self
.
stats
cpu_stats
[
cpu
]
=
getattr
(
cputimespercent
,
cpu
)
def
update_deprecated
(
self
):
"""
Update CPU stats
Only used if cpu_times_percent failed
"""
# Grab CPU using the PSUtil cpu_times method
cputime
=
cpu_times
(
percpu
=
False
)
cputime_total
=
cputime
.
user
+
cputime
.
system
+
cputime
.
idle
# Only available on some OS
if
hasattr
(
cputime
,
'nice'
):
cputime_total
+=
cputime
.
nice
if
hasattr
(
cputime
,
'iowait'
):
cputime_total
+=
cputime
.
iowait
if
hasattr
(
cputime
,
'irq'
):
cputime_total
+=
cputime
.
irq
if
hasattr
(
cputime
,
'softirq'
):
cputime_total
+=
cputime
.
softirq
if
hasattr
(
cputime
,
'steal'
):
cputime_total
+=
cputime
.
steal
if
not
hasattr
(
self
,
'cputime_old'
):
self
.
cputime_old
=
cputime
self
.
cputime_total_old
=
cputime_total
self
.
stats
=
{}
else
:
self
.
cputime_new
=
cputime
self
.
cputime_total_new
=
cputime_total
try
:
percent
=
100
/
(
self
.
cputime_total_new
-
self
.
cputime_total_old
)
self
.
stats
=
{
'user'
:
(
self
.
cputime_new
.
user
-
self
.
cputime_old
.
user
)
*
percent
,
'system'
:
(
self
.
cputime_new
.
system
-
self
.
cputime_old
.
system
)
*
percent
,
'idle'
:
(
self
.
cputime_new
.
idle
-
self
.
cputime_old
.
idle
)
*
percent
}
if
hasattr
(
self
.
cputime_new
,
'nice'
):
self
.
stats
[
'nice'
]
=
(
self
.
cputime_new
.
nice
-
self
.
cputime_old
.
nice
)
*
percent
if
hasattr
(
self
.
cputime_new
,
'iowait'
):
self
.
stats
[
'iowait'
]
=
(
self
.
cputime_new
.
iowait
-
self
.
cputime_old
.
iowait
)
*
percent
if
hasattr
(
self
.
cputime_new
,
'irq'
):
self
.
stats
[
'irq'
]
=
(
self
.
cputime_new
.
irq
-
self
.
cputime_old
.
irq
)
*
percent
if
hasattr
(
self
.
cputime_new
,
'softirq'
):
self
.
stats
[
'softirq'
]
=
(
self
.
cputime_new
.
softirq
-
self
.
cputime_old
.
softirq
)
*
percent
if
hasattr
(
self
.
cputime_new
,
'steal'
):
self
.
stats
[
'steal'
]
=
(
self
.
cputime_new
.
steal
-
self
.
cputime_old
.
steal
)
*
percent
self
.
cputime_old
=
self
.
cputime_new
self
.
cputime_total_old
=
self
.
cputime_total_new
except
Exception
:
self
.
stats
=
{}
# Set the global variable to the new stats
self
.
stats
=
cpu_stats
return
self
.
stats
def
msg_curse
(
self
,
args
=
None
):
"""
Return the
dic
t to display in the curse interface
Return the
lis
t to display in the curse interface
"""
# Only process if stats exist...
if
(
self
.
stats
==
{}):
return
[]
# Init the return message
ret
=
[]
...
...
glances/plugins/glances_system.py
浏览文件 @
4bcac1cb
...
...
@@ -17,13 +17,16 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Glances system plugin
"""
# Import system libs
import
os
import
platform
# from ..plugins.glances_plugin import GlancesPlugin
from
glances_plugin
import
GlancesPlugin
from
glances
.plugins.glances
_plugin
import
GlancesPlugin
class
Plugin
(
GlancesPlugin
):
...
...
@@ -48,6 +51,7 @@ class Plugin(GlancesPlugin):
def
update
(
self
):
"""
Update the host/system info
Return the stats (dict)
"""
self
.
stats
=
{}
self
.
stats
[
'os_name'
]
=
platform
.
system
()
...
...
@@ -70,6 +74,7 @@ class Plugin(GlancesPlugin):
self
.
stats
[
'os_version'
]
=
' '
.
join
(
os_version
[::
2
])
else
:
self
.
stats
[
'os_version'
]
=
""
return
self
.
stats
def
msg_curse
(
self
,
args
=
None
):
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录