Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
d68c991a
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,发现更多精彩内容 >>
提交
d68c991a
编写于
5月 03, 2014
作者:
N
Nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SNMP input: Uptime and CPU
上级
66525c6e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
96 addition
and
40 deletion
+96
-40
glances/core/glances_client.py
glances/core/glances_client.py
+5
-7
glances/plugins/glances_cpu.py
glances/plugins/glances_cpu.py
+56
-27
glances/plugins/glances_system.py
glances/plugins/glances_system.py
+1
-0
glances/plugins/glances_uptime.py
glances/plugins/glances_uptime.py
+34
-6
未找到文件。
glances/core/glances_client.py
浏览文件 @
d68c991a
...
...
@@ -122,18 +122,16 @@ class GlancesClient():
# Test if SNMP is available on the server side
clientsnmp
=
GlancesSNMPClient
()
try
:
# !!! Simple request with system name
# !!! Had to have a standard method to check SNMP server
clientsnmp
.
get_by_oid
(
"1.3.6.1.2.1.1.5.0"
)
except
:
# !!! Simple request with system name
# !!! Had to have a standard method to check SNMP server
print
(
_
(
"Trying {0}..."
).
format
(
self
.
get_mode
())
)
if
(
clientsnmp
.
get_by_oid
(
"1.3.6.1.2.1.1.5.0"
)
==
{})
:
print
(
_
(
"Error: Connection to {0} server failed"
).
format
(
self
.
get_mode
()))
sys
.
exit
(
2
)
from
glances.core.glances_stats
import
GlancesStatsClientSNMP
print
(
_
(
"Fallback to {0}"
).
format
(
self
.
get_mode
()))
# Init stats
self
.
stats
=
GlancesStatsClientSNMP
()
...
...
glances/plugins/glances_cpu.py
浏览文件 @
d68c991a
...
...
@@ -24,6 +24,18 @@ import psutil
from
glances.plugins.glances_plugin
import
GlancesPlugin
# SNMP OID
# percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
# raw user cpu time: .1.3.6.1.4.1.2021.11.50.0
# percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
# raw system cpu time: .1.3.6.1.4.1.2021.11.52.0
# percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0
# raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0
# raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0
snmp_oid
=
{
'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'
,
'user_raw'
:
'1.3.6.1.4.1.2021.11.50.0'
}
class
Plugin
(
GlancesPlugin
):
"""
...
...
@@ -46,37 +58,51 @@ class Plugin(GlancesPlugin):
# Init stats
self
.
first_call
=
True
self
.
reset
()
def
reset
(
self
):
"""
Reset/init the stats
"""
self
.
stats
=
{}
def
update
(
self
):
def
update
(
self
,
input
=
'local'
):
"""
Update CPU stats
Update CPU stats using the input method
Input method could be: local (mandatory) or snmp (optionnal)
"""
# 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)
# 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'
,
'guest'
,
'guest_nice'
]:
if
hasattr
(
cputimespercent
,
cpu
):
cpu_stats
[
cpu
]
=
getattr
(
cputimespercent
,
cpu
)
# Set the global variable to the new stats
self
.
stats
=
cpu_stats
# Reset stats
self
.
reset
()
if
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)
# 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
(
cputimespercent
,
cpu
):
self
.
stats
[
cpu
]
=
getattr
(
cputimespercent
,
cpu
)
elif
input
==
'snmp'
:
# Update stats using SNMP
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
)
for
key
in
self
.
stats
.
iterkeys
():
self
.
stats
[
key
]
=
float
(
self
.
stats
[
key
])
return
self
.
stats
...
...
@@ -147,7 +173,10 @@ class Plugin(GlancesPlugin):
# Idles CPU
# ret.append(self.curse_add_line(" ", optional=True))
if
'idle'
in
self
.
stats
:
msg
=
" {0:8}"
.
format
(
_
(
"idle:"
))
msg
=
""
if
'nice'
in
self
.
stats
:
msg
=
" "
msg
+=
"{0:8}"
.
format
(
_
(
"idle:"
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
msg
=
"{0}"
.
format
(
format
(
self
.
stats
[
'idle'
]
/
100
,
'>6.1%'
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
True
))
...
...
glances/plugins/glances_system.py
浏览文件 @
d68c991a
...
...
@@ -92,6 +92,7 @@ class Plugin(GlancesPlugin):
else
:
self
.
stats
[
'os_version'
]
=
""
elif
input
==
'snmp'
:
# Update stats using SNMP
self
.
stats
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
)
return
self
.
stats
...
...
glances/plugins/glances_uptime.py
浏览文件 @
d68c991a
...
...
@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import system libs
from
datetime
import
datetime
from
datetime
import
datetime
,
timedelta
# Check for psutil already done in the glances_core script
import
psutil
...
...
@@ -26,6 +26,8 @@ import psutil
# Import Glances libs
from
glances.plugins.glances_plugin
import
GlancesPlugin
# SNMP OID
snmp_oid
=
{
'_uptime'
:
'1.3.6.1.2.1.1.3.0'
}
class
Plugin
(
GlancesPlugin
):
"""
...
...
@@ -46,15 +48,41 @@ class Plugin(GlancesPlugin):
self
.
column_curse
=
-
1
# Enter -1 to diplay bottom
self
.
line_curse
=
0
# Init the stats
self
.
reset
()
def
update
(
self
):
def
reset
(
self
):
"""
Update uptime stat
Reset/init the stats
"""
uptime
=
datetime
.
now
()
-
datetime
.
fromtimestamp
(
psutil
.
boot_time
())
self
.
stats
=
{}
# Convert uptime to string (because datetime is not JSONifi)
self
.
stats
=
str
(
uptime
).
split
(
'.'
)[
0
]
def
update
(
self
,
input
=
'local'
):
"""
Update uptime stat using the input method
Input method could be: local (mandatory) or snmp (optionnal)
"""
# Reset stats
self
.
reset
()
if
input
==
'local'
:
# Update stats using the standard system lib
uptime
=
datetime
.
now
()
-
datetime
.
fromtimestamp
(
psutil
.
boot_time
())
# Convert uptime to string (because datetime is not JSONifi)
self
.
stats
=
str
(
uptime
).
split
(
'.'
)[
0
]
elif
input
==
'snmp'
:
# Update stats using SNMP
uptime
=
self
.
set_stats_snmp
(
snmp_oid
=
snmp_oid
)[
'_uptime'
]
try
:
# In hundredths of seconds
self
.
stats
=
str
(
timedelta
(
seconds
=
int
(
uptime
)
/
100
))
except
:
pass
# Return the result
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录