Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
af7d3146
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 搜索 >>
提交
af7d3146
编写于
1月 15, 2015
作者:
N
Nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Some PEP8 enhancement
上级
2b1fd87d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
31 deletion
+51
-31
glances/plugins/glances_cpu.py
glances/plugins/glances_cpu.py
+25
-14
glances/plugins/glances_fs.py
glances/plugins/glances_fs.py
+15
-10
glances/plugins/glances_system.py
glances/plugins/glances_system.py
+11
-7
未找到文件。
glances/plugins/glances_cpu.py
浏览文件 @
af7d3146
...
...
@@ -32,9 +32,9 @@ snmp_oid = {'default': {'user': '1.3.6.1.4.1.2021.11.9.0',
'idle'
:
'1.3.6.1.4.1.2021.11.11.0'
},
'windows'
:
{
'percent'
:
'1.3.6.1.2.1.25.3.3.1.2'
},
'esxi'
:
{
'percent'
:
'1.3.6.1.2.1.25.3.3.1.2'
},
'netapp'
:
{
'system'
:
'1.3.6.1.4.1.789.1.2.1.3.0'
,
'idle'
:
'1.3.6.1.4.1.789.1.2.1.5.0'
,
'nb_log_core'
:
'1.3.6.1.4.1.789.1.2.1.6.0'
}}
'netapp'
:
{
'system'
:
'1.3.6.1.4.1.789.1.2.1.3.0'
,
'idle'
:
'1.3.6.1.4.1.789.1.2.1.5.0'
,
'nb_log_core'
:
'1.3.6.1.4.1.789.1.2.1.6.0'
}}
# Define the history items list
# - 'name' define the stat identifier
...
...
@@ -55,7 +55,8 @@ class Plugin(GlancesPlugin):
def
__init__
(
self
,
args
=
None
):
"""Init the CPU plugin."""
GlancesPlugin
.
__init__
(
self
,
args
=
args
,
items_history_list
=
items_history_list
)
GlancesPlugin
.
__init__
(
self
,
args
=
args
,
items_history_list
=
items_history_list
)
# We want to display the stat in the curse interface
self
.
display_curse
=
True
...
...
@@ -73,7 +74,8 @@ class Plugin(GlancesPlugin):
# Reset stats
self
.
reset
()
# Grab CPU stats using psutil's cpu_percent and cpu_times_percent methods
# Grab CPU stats using psutil's cpu_percent and cpu_times_percent
# methods
if
self
.
get_input
()
==
'local'
:
# Get all possible values for CPU stats: user, system, idle,
# nice (UNIX), iowait (Linux), irq (Linux, FreeBSD), steal (Linux 2.6.11+)
...
...
@@ -105,16 +107,19 @@ class Plugin(GlancesPlugin):
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'
]
=
self
.
stats
[
'idle'
]
/
self
.
stats
[
'nb_log_core'
]
self
.
stats
[
'idle'
]
=
100
-
self
.
stats
[
'idle'
]
self
.
stats
[
'total'
]
=
100
-
self
.
stats
[
'idle'
]
else
:
# Default behavor
try
:
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
self
.
get_short_system_name
()])
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
self
.
get_short_system_name
()])
except
KeyError
:
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
'default'
])
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
'default'
])
if
self
.
stats
[
'idle'
]
==
''
:
self
.
reset
()
...
...
@@ -140,7 +145,8 @@ class Plugin(GlancesPlugin):
return
ret
# Build the string message
# If user stat is not here, display only idle / total CPU usage (for exemple on Windows OS)
# 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
msg
=
'{0:8}'
.
format
(
_
(
"CPU"
))
...
...
@@ -148,7 +154,8 @@ class Plugin(GlancesPlugin):
# Total CPU usage
msg
=
'{0:>5}%'
.
format
(
self
.
stats
[
'total'
])
if
idle_tag
:
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert_log
(
self
.
stats
[
'total'
],
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
...
...
@@ -164,7 +171,8 @@ class Plugin(GlancesPlugin):
msg
=
'{0:8}'
.
format
(
_
(
"user:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>5}%'
.
format
(
self
.
stats
[
'user'
])
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
))
...
...
@@ -183,7 +191,8 @@ class Plugin(GlancesPlugin):
msg
=
'{0:8}'
.
format
(
_
(
"system:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0:>5}%'
.
format
(
self
.
stats
[
'system'
])
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
))
...
...
@@ -194,7 +203,8 @@ class Plugin(GlancesPlugin):
msg
=
' {0:8}'
.
format
(
_
(
"iowait:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
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
))
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
())
# Idle CPU
...
...
@@ -208,7 +218,8 @@ class Plugin(GlancesPlugin):
msg
=
' {0:8}'
.
format
(
_
(
"steal:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
msg
=
'{0:>5}%'
.
format
(
self
.
stats
[
'steal'
])
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert
(
self
.
stats
[
'steal'
],
header
=
"steal"
),
optional
=
True
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_alert
(
self
.
stats
[
'steal'
],
header
=
"steal"
),
optional
=
True
))
# Return the message with decoration
return
ret
glances/plugins/glances_fs.py
浏览文件 @
af7d3146
...
...
@@ -48,11 +48,11 @@ snmp_oid = {'default': {'mnt_point': '1.3.6.1.4.1.2021.9.1.2',
'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'
},
'netapp'
:
{
'mnt_point'
:
'1.3.6.1.4.1.789.1.5.4.1.2'
,
'device_name'
:
'1.3.6.1.4.1.789.1.5.4.1.10'
,
'size'
:
'1.3.6.1.4.1.789.1.5.4.1.3'
,
'used'
:
'1.3.6.1.4.1.789.1.5.4.1.4'
,
'percent'
:
'1.3.6.1.4.1.789.1.5.4.1.6'
}}
'netapp'
:
{
'mnt_point'
:
'1.3.6.1.4.1.789.1.5.4.1.2'
,
'device_name'
:
'1.3.6.1.4.1.789.1.5.4.1.10'
,
'size'
:
'1.3.6.1.4.1.789.1.5.4.1.3'
,
'used'
:
'1.3.6.1.4.1.789.1.5.4.1.4'
,
'percent'
:
'1.3.6.1.4.1.789.1.5.4.1.6'
}}
snmp_oid
[
'esxi'
]
=
snmp_oid
[
'windows'
]
# Define the history items list
...
...
@@ -70,7 +70,8 @@ class Plugin(GlancesPlugin):
def
__init__
(
self
,
args
=
None
):
"""Init the plugin."""
GlancesPlugin
.
__init__
(
self
,
args
=
args
,
items_history_list
=
items_history_list
)
GlancesPlugin
.
__init__
(
self
,
args
=
args
,
items_history_list
=
items_history_list
)
# We want to display the stat in the curse interface
self
.
display_curse
=
True
...
...
@@ -144,9 +145,12 @@ class Plugin(GlancesPlugin):
fs_current
=
{}
fs_current
[
'device_name'
]
=
''
fs_current
[
'mnt_point'
]
=
fs
.
partition
(
' '
)[
0
]
fs_current
[
'size'
]
=
int
(
fs_stat
[
fs
][
'size'
])
*
int
(
fs_stat
[
fs
][
'alloc_unit'
])
fs_current
[
'used'
]
=
int
(
fs_stat
[
fs
][
'used'
])
*
int
(
fs_stat
[
fs
][
'alloc_unit'
])
fs_current
[
'percent'
]
=
float
(
fs_current
[
'used'
]
*
100
/
fs_current
[
'size'
])
fs_current
[
'size'
]
=
int
(
fs_stat
[
fs
][
'size'
])
*
int
(
fs_stat
[
fs
][
'alloc_unit'
])
fs_current
[
'used'
]
=
int
(
fs_stat
[
fs
][
'used'
])
*
int
(
fs_stat
[
fs
][
'alloc_unit'
])
fs_current
[
'percent'
]
=
float
(
fs_current
[
'used'
]
*
100
/
fs_current
[
'size'
])
fs_current
[
'key'
]
=
self
.
get_key
()
self
.
stats
.
append
(
fs_current
)
else
:
...
...
@@ -202,7 +206,8 @@ class Plugin(GlancesPlugin):
mnt_point
=
i
[
'mnt_point'
][
-
fsname_max_width
+
1
:]
elif
len
(
i
[
'mnt_point'
])
+
len
(
i
[
'device_name'
].
split
(
'/'
)[
-
1
])
<=
fsname_max_width
-
3
:
# If possible concatenate mode info... Glances touch inside :)
mnt_point
=
i
[
'mnt_point'
]
+
' ('
+
i
[
'device_name'
].
split
(
'/'
)[
-
1
]
+
')'
mnt_point
=
i
[
'mnt_point'
]
+
\
' ('
+
i
[
'device_name'
].
split
(
'/'
)[
-
1
]
+
')'
elif
len
(
i
[
'mnt_point'
])
>
fsname_max_width
:
# Cut mount point name if it is too long
mnt_point
=
'_'
+
i
[
'mnt_point'
][
-
fsname_max_width
+
1
:]
...
...
glances/plugins/glances_system.py
浏览文件 @
af7d3146
...
...
@@ -30,13 +30,14 @@ from glances.plugins.glances_plugin import GlancesPlugin
# SNMP OID
snmp_oid
=
{
'default'
:
{
'hostname'
:
'1.3.6.1.2.1.1.5.0'
,
'system_name'
:
'1.3.6.1.2.1.1.1.0'
},
'netapp'
:
{
'hostname'
:
'1.3.6.1.2.1.1.5.0'
,
'system_name'
:
'1.3.6.1.2.1.1.1.0'
,
'platform'
:
'1.3.6.1.4.1.789.1.1.5.0'
}}
'netapp'
:
{
'hostname'
:
'1.3.6.1.2.1.1.5.0'
,
'system_name'
:
'1.3.6.1.2.1.1.1.0'
,
'platform'
:
'1.3.6.1.4.1.789.1.1.5.0'
}}
# SNMP to human read
# Dict (key: OS short name) of dict (reg exp OID to human)
# Windows: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832%28v=vs.85%29.aspx
# Windows:
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832%28v=vs.85%29.aspx
snmp_to_human
=
{
'windows'
:
{
'Windows Version 6.3'
:
'Windows 8.1 or Server 2012R2'
,
'Windows Version 6.2'
:
'Windows 8 or Server 2012'
,
'Windows Version 6.1'
:
'Windows 7 or Server 2008R2'
,
...
...
@@ -121,7 +122,8 @@ class Plugin(GlancesPlugin):
elif
self
.
stats
[
'os_name'
]
==
"Windows"
:
os_version
=
platform
.
win32_ver
()
self
.
stats
[
'os_version'
]
=
' '
.
join
(
os_version
[::
2
])
# if the python version is 32 bit perhaps the windows operating system is 64bit
# if the python version is 32 bit perhaps the windows operating
# system is 64bit
if
self
.
stats
[
'platform'
]
==
'32bit'
:
if
'PROCESSOR_ARCHITEW6432'
in
os
.
environ
:
self
.
stats
[
'platform'
]
=
'64bit'
...
...
@@ -131,13 +133,15 @@ class Plugin(GlancesPlugin):
if
self
.
stats
[
'os_name'
]
==
"Linux"
:
self
.
stats
[
'hr_name'
]
=
self
.
stats
[
'linux_distro'
]
else
:
self
.
stats
[
'hr_name'
]
=
'{0} {1}'
.
format
(
self
.
stats
[
'os_name'
],
self
.
stats
[
'os_version'
])
self
.
stats
[
'hr_name'
]
=
'{0} {1}'
.
format
(
self
.
stats
[
'os_name'
],
self
.
stats
[
'os_version'
])
self
.
stats
[
'hr_name'
]
+=
' ({0})'
.
format
(
self
.
stats
[
'platform'
])
elif
self
.
get_input
()
==
'snmp'
:
# Update stats using SNMP
try
:
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
self
.
get_short_system_name
()])
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
self
.
get_short_system_name
()])
except
KeyError
:
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
'default'
])
# Default behavor: display all the information
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录