Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
9dda132c
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 搜索 >>
提交
9dda132c
编写于
6月 26, 2014
作者:
N
Nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add CPU for WIndows OS
上级
5252eab9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
107 addition
and
54 deletion
+107
-54
glances/outputs/glances_curses.py
glances/outputs/glances_curses.py
+1
-1
glances/plugins/glances_cpu.py
glances/plugins/glances_cpu.py
+28
-9
glances/plugins/glances_fs.py
glances/plugins/glances_fs.py
+1
-2
glances/plugins/glances_mem.py
glances/plugins/glances_mem.py
+47
-26
glances/plugins/glances_plugin.py
glances/plugins/glances_plugin.py
+30
-16
未找到文件。
glances/outputs/glances_curses.py
浏览文件 @
9dda132c
...
...
@@ -379,7 +379,7 @@ class GlancesCurses(object):
if
plugin_stats
[
'line'
]
not
in
self
.
line_to_y
:
self
.
line_to_y
[
plugin_stats
[
'line'
]]
=
plugin_stats
[
'line'
]
display_y
=
self
.
line_to_y
[
plugin_stats
[
'line'
]]
# Display
x
=
display_x
y
=
display_y
...
...
glances/plugins/glances_cpu.py
浏览文件 @
9dda132c
...
...
@@ -29,7 +29,8 @@ import psutil
# percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0
snmp_oid
=
{
'default'
:
{
'user'
:
'1.3.6.1.4.1.2021.11.9.0'
,
'system'
:
'1.3.6.1.4.1.2021.11.10.0'
,
'idle'
:
'1.3.6.1.4.1.2021.11.11.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'
}}
class
Plugin
(
GlancesPlugin
):
...
...
@@ -90,15 +91,33 @@ class Plugin(GlancesPlugin):
self
.
stats
[
cpu
]
=
getattr
(
cputimespercent
,
cpu
)
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
()])
except
KeyError
:
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
'default'
])
if
self
.
stats
[
'user'
]
==
''
:
self
.
reset
()
return
self
.
stats
if
self
.
get_short_system_name
()
==
'windows'
:
# Windows
# You can find the CPU utilization of windows system by querying the oid
# Give also the number of core (number of element in the table)
# print snmp_oid[self.get_short_system_name()]
try
:
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
self
.
get_short_system_name
()],
bulk
=
True
)
except
KeyError
:
self
.
reset
()
# TODO: iter through CPU... startswith('percent')
self
.
stats
[
'idle'
]
=
self
.
stats
[
'percent.3'
]
else
:
# Default behavor
try
:
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'
])
if
self
.
stats
[
'idle'
]
==
''
:
self
.
reset
()
return
self
.
stats
# Convert SNMP stats to float
for
key
in
self
.
stats
.
iterkeys
():
self
.
stats
[
key
]
=
float
(
self
.
stats
[
key
])
...
...
glances/plugins/glances_fs.py
浏览文件 @
9dda132c
...
...
@@ -115,8 +115,7 @@ class Plugin(GlancesPlugin):
elif
self
.
get_input
()
==
'snmp'
:
# Update stats using SNMP
# SNMP bulk command to get all file system in one shot
# SNMP bulk command to get all file system in one shot
try
:
fs_stat
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
self
.
get_short_system_name
()],
bulk
=
True
)
...
...
glances/plugins/glances_mem.py
浏览文件 @
9dda132c
...
...
@@ -30,13 +30,16 @@ import psutil
# Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0
# Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0
# Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0
snmp_oid
=
{
'total'
:
'1.3.6.1.4.1.2021.4.5.0'
,
# 'used': '1.3.6.1.4.1.2021.4.6.0',
'free'
:
'1.3.6.1.4.1.2021.4.11.0'
,
'shared'
:
'1.3.6.1.4.1.2021.4.13.0'
,
'buffers'
:
'1.3.6.1.4.1.2021.4.14.0'
,
'cached'
:
'1.3.6.1.4.1.2021.4.15.0'
}
# Note: For Windows, stats are in the FS table
snmp_oid
=
{
'default'
:
{
'total'
:
'1.3.6.1.4.1.2021.4.5.0'
,
'free'
:
'1.3.6.1.4.1.2021.4.11.0'
,
'shared'
:
'1.3.6.1.4.1.2021.4.13.0'
,
'buffers'
:
'1.3.6.1.4.1.2021.4.14.0'
,
'cached'
:
'1.3.6.1.4.1.2021.4.15.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
):
...
...
@@ -88,7 +91,7 @@ class Plugin(GlancesPlugin):
# cached: (Linux, BSD): cache for various things.
# wired: (BSD, OSX): memory that is marked to always stay in RAM. It is never moved to disk.
# shared: (BSD): memory that may be simultaneously accessed by multiple processes.
self
.
stats
=
{}
self
.
reset
()
for
mem
in
[
'total'
,
'available'
,
'percent'
,
'used'
,
'free'
,
'active'
,
'inactive'
,
'buffers'
,
'cached'
,
'wired'
,
'shared'
]:
...
...
@@ -106,24 +109,42 @@ class Plugin(GlancesPlugin):
self
.
stats
[
'used'
]
=
self
.
stats
[
'total'
]
-
self
.
stats
[
'free'
]
elif
self
.
get_input
()
==
'snmp'
:
# Update stats using SNMP
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
# Use the 'free'/htop calculation
self
.
stats
[
'free'
]
=
self
.
stats
[
'free'
]
-
self
.
stats
[
'total'
]
+
(
self
.
stats
[
'buffers'
]
+
self
.
stats
[
'cached'
])
# 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
)
if
self
.
get_short_system_name
()
==
'windows'
:
# Mem stats for Windows OS are stored in the FS table
try
:
fs_stat
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
self
.
get_short_system_name
()],
bulk
=
True
)
except
KeyError
:
self
.
reset
()
else
:
for
fs
in
fs_stat
:
# Memory stats are grabed in the same OID table (ignore it)
if
fs
==
'Virtual Memory'
:
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
[
'percent'
]
=
float
(
self
.
stats
[
'used'
]
*
100
/
self
.
stats
[
'total'
])
self
.
stats
[
'free'
]
=
self
.
stats
[
'total'
]
-
self
.
stats
[
'used'
]
break
else
:
# Default behavor for others OS
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
[
'default'
])
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
# Use the 'free'/htop calculation
self
.
stats
[
'free'
]
=
self
.
stats
[
'free'
]
-
self
.
stats
[
'total'
]
+
(
self
.
stats
[
'buffers'
]
+
self
.
stats
[
'cached'
])
# 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
...
...
glances/plugins/glances_plugin.py
浏览文件 @
9dda132c
...
...
@@ -105,22 +105,36 @@ class GlancesPlugin(object):
# Bulk request
snmpresult
=
clientsnmp
.
getbulk_by_oid
(
0
,
10
,
*
snmp_oid
.
values
())
# Build the internal dict with the SNMP result
# key is the first item in the snmp_oid
index
=
1
for
item
in
snmpresult
:
item_stats
=
{}
item_key
=
None
for
key
in
snmp_oid
.
iterkeys
():
oid
=
snmp_oid
[
key
]
+
'.'
+
str
(
index
)
if
oid
in
item
:
if
item_key
is
None
:
item_key
=
item
[
oid
]
else
:
item_stats
[
key
]
=
item
[
oid
]
if
item_stats
!=
{}:
ret
[
item_key
]
=
item_stats
index
+=
1
if
len
(
snmp_oid
)
==
1
:
# Bulk command for only one OID
# Note: key is the item indexed but the OID result
for
item
in
snmpresult
:
if
item
.
keys
()[
0
].
startswith
(
snmp_oid
.
values
()[
0
]):
ret
[
snmp_oid
.
keys
()[
0
]
+
item
.
keys
()[
0
].
split
(
snmp_oid
.
values
()[
0
])[
1
]]
=
item
.
values
()[
0
]
else
:
# Build the internal dict with the SNMP result
# Note: key is the first item in the snmp_oid
index
=
1
for
item
in
snmpresult
:
item_stats
=
{}
item_key
=
None
for
key
in
snmp_oid
.
iterkeys
():
oid
=
snmp_oid
[
key
]
+
'.'
+
str
(
index
)
if
oid
in
item
:
if
item_key
is
None
:
item_key
=
item
[
oid
]
else
:
item_stats
[
key
]
=
item
[
oid
]
if
item_stats
!=
{}:
ret
[
item_key
]
=
item_stats
index
+=
1
# if '1.3.6.1.2.1.25.3.3.1.2' in snmp_oid.values():
# # if '1.3.6.1.2.1.25.2.3.1.3' in snmp_oid.values():
# print snmp_oid
# print snmpresult
# print ret
else
:
# Simple get request
snmpresult
=
clientsnmp
.
get_by_oid
(
*
snmp_oid
.
values
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录