Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
09d87e0a
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 搜索 >>
提交
09d87e0a
编写于
4月 15, 2016
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Regression on Monitoring list
上级
8efb5e2a
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
89 addition
and
39 deletion
+89
-39
conf/glances.conf
conf/glances.conf
+10
-9
glances/amps/glances_amp.py
glances/amps/glances_amp.py
+20
-2
glances/amps/glances_nginx.py
glances/amps/glances_nginx.py
+8
-4
glances/amps_list.py
glances/amps_list.py
+5
-2
glances/compat.py
glances/compat.py
+1
-1
glances/outputs/glances_curses.py
glances/outputs/glances_curses.py
+4
-4
glances/plugins/glances_amps.py
glances/plugins/glances_amps.py
+21
-7
glances/plugins/glances_ip.py
glances/plugins/glances_ip.py
+16
-9
glances/timer.py
glances/timer.py
+4
-1
未找到文件。
conf/glances.conf
浏览文件 @
09d87e0a
...
...
@@ -171,15 +171,15 @@ mem_critical=90
# A warning will be displayed if number of process < count
# * countmax: (optional) maximum number of processes
# A warning will be displayed if number of process > count
#
list_1_description=Dropbox
#
list_1_regex=.*dropbox.*
#
list_1_countmin=1
#
list_1_command=dropbox status | head -1
#
list_2_description=Python programs
#
list_2_regex=.*python.*
#
list_3_description=Famous Xeyes
#
list_3_regex=.*xeyes.*
#
list_3_countmin=1
list_1_description
=
Dropbox
list_1_regex
=.*
dropbox
.*
list_1_countmin
=
1
list_1_command
=
dropbox
status
|
head
-
1
list_2_description
=
Python
programs
list_2_regex
=.*
python
.*
list_3_description
=
Famous
Xeyes
list_3_regex
=.*
xeyes
.*
list_3_countmin
=
1
[
serverlist
]
# Define the static servers list
...
...
@@ -259,4 +259,5 @@ queue=glances_queue
enable
=
true
regex
=\/
usr
\/
sbin
\/
nginx
refresh
=
60
one_line
=
false
status_url
=
http
://
localhost
/
nginx_status
glances/amps/glances_amp.py
浏览文件 @
09d87e0a
...
...
@@ -24,6 +24,7 @@ I am your father...
"""
from
glances.compat
import
u
from
glances.timer
import
Timer
from
glances.logger
import
logger
...
...
@@ -42,6 +43,10 @@ class GlancesAmp(object):
# Init the configs
self
.
configs
=
{}
# A timer is needed to only update every refresh seconds
# Init to 0 in order to update the AMP on startup
self
.
timer
=
Timer
(
0
)
def
load_config
(
self
,
config
):
"""Load AMP parameters from the configuration file."""
...
...
@@ -55,7 +60,9 @@ class GlancesAmp(object):
#
# and optionnaly:
#
# one_line=false
# option1=opt1
# ...
#
if
(
hasattr
(
config
,
'has_section'
)
and
config
.
has_section
(
self
.
amp_name
)):
...
...
@@ -100,12 +107,20 @@ class GlancesAmp(object):
"""Return refresh time in seconds for the current application monitoring process."""
return
self
.
get
(
'refresh'
)
def
time_until_refresh
(
self
):
"""Return time in seconds until refresh."""
return
self
.
timer
.
get
()
def
should_update
(
self
):
"""Return True is the AMP should be updated:
- AMP is enable
- only update every 'refresh' seconds
"""
return
True
if
self
.
timer
.
finished
():
self
.
timer
.
set
(
self
.
refresh
())
self
.
timer
.
reset
()
return
self
.
enable
()
return
False
def
set_result
(
self
,
result
):
"""Store the result (string) into the result key of the AMP"""
...
...
@@ -113,4 +128,7 @@ class GlancesAmp(object):
def
result
(
self
):
""" Return the result of the AMP (as a string)"""
return
u
(
self
.
get
(
'result'
))
ret
=
self
.
get
(
'result'
)
if
ret
is
not
None
:
ret
=
u
(
ret
)
return
ret
glances/amps/glances_nginx.py
浏览文件 @
09d87e0a
...
...
@@ -29,19 +29,23 @@ class Amp(GlancesAmp):
"""Glances' Nginx AMP."""
def
__init__
(
self
,
args
=
None
):
"""Init the AMP."""
super
(
Amp
,
self
).
__init__
(
args
=
args
)
#
def __init__(self, args=None):
#
"""Init the AMP."""
#
super(Amp, self).__init__(args=args)
def
update
(
self
):
"""Update the AMP"""
if
self
.
should_update
():
logger
.
debug
(
'AMPS: Update {0} using status URL {1}'
.
format
(
self
.
amp_name
,
self
.
get
(
'status_url'
)))
# Get the Nginx status
req
=
requests
.
get
(
self
.
get
(
'status_url'
))
if
req
.
ok
:
# u'Active connections: 1 \nserver accepts handled requests\n 1 1 1 \nReading: 0 Writing: 1 Waiting: 0 \n'
self
.
set_result
(
req
.
text
)
if
self
.
get
(
'one_line'
)
is
not
None
and
self
.
get
(
'one_line'
).
lower
()
==
'true'
:
self
.
set_result
(
req
.
text
.
replace
(
'
\n
'
,
''
))
else
:
self
.
set_result
(
req
.
text
)
else
:
logger
.
debug
(
'AMPS: Can not grab status URL {0} ({1})'
.
format
(
self
.
get
(
'status_url'
),
req
.
reason
))
...
...
glances/amps_list.py
浏览文件 @
09d87e0a
...
...
@@ -21,7 +21,7 @@
import
os
import
re
import
subprocess
import
threading
from
glances.compat
import
listkeys
,
iteritems
from
glances.logger
import
logger
...
...
@@ -100,7 +100,10 @@ class AmpsList(object):
# At least one process is matching the regex
logger
.
debug
(
"AMPS: {} process detected (PID={})"
.
format
(
k
,
amps_list
[
0
][
'pid'
]))
# Call the AMP update method
v
.
update
()
# TODO: should be non blocking
thread
=
threading
.
Thread
(
target
=
v
.
update
)
thread
.
start
()
# v.update()
return
self
.
__amps_dict
...
...
glances/compat.py
浏览文件 @
09d87e0a
...
...
@@ -32,7 +32,7 @@ if PY3:
from
xmlrpc.client
import
Fault
,
ProtocolError
,
ServerProxy
,
Transport
from
xmlrpc.server
import
SimpleXMLRPCRequestHandler
,
SimpleXMLRPCServer
from
urllib.request
import
urlopen
from
urllib.error
import
URLError
from
urllib.error
import
URLError
,
timeout
input
=
input
range
=
range
...
...
glances/outputs/glances_curses.py
浏览文件 @
09d87e0a
...
...
@@ -725,13 +725,13 @@ class _GlancesCurses(object):
self
.
display_plugin
(
stats_docker
)
self
.
new_line
()
self
.
display_plugin
(
stats_processcount
)
self
.
new_line
()
self
.
display_plugin
(
stats_amps
)
if
glances_processes
.
process_filter
is
None
and
cs_status
is
None
:
# Do not display stats monitor list if a filter exist
# Do not display stats monitor list
and AMPS
if a filter exist
self
.
new_line
()
self
.
display_plugin
(
stats_monitor
)
self
.
new_line
()
self
.
new_line
()
self
.
display_plugin
(
stats_amps
)
# self.new_line()
self
.
display_plugin
(
stats_processlist
,
display_optional
=
(
screen_x
>
102
),
display_additional
=
(
not
OSX
),
...
...
glances/plugins/glances_amps.py
浏览文件 @
09d87e0a
...
...
@@ -21,6 +21,7 @@
from
glances.compat
import
iteritems
from
glances.amps_list
import
AmpsList
as
glancesAmpsList
from
glances.logger
import
logger
from
glances.plugins.glances_plugin
import
GlancesPlugin
...
...
@@ -54,10 +55,14 @@ class Plugin(GlancesPlugin):
self
.
reset
()
if
self
.
input_method
==
'local'
:
# TODO
for
k
,
v
in
iteritems
(
self
.
glances_amps
.
update
()):
self
.
stats
.
append
({
k
:
v
.
result
()})
# self.stats.append({k: v.result()})
self
.
stats
.
append
({
'key'
:
k
,
'result'
:
v
.
result
(),
'refresh'
:
v
.
refresh
(),
'timer'
:
v
.
time_until_refresh
()})
else
:
# Not available in SNMP mode
pass
return
self
.
stats
...
...
@@ -73,12 +78,21 @@ class Plugin(GlancesPlugin):
# Build the string message
for
m
in
self
.
stats
:
for
k
,
v
in
iteritems
(
m
):
msg
=
'{0:<16} '
.
format
(
k
)
if
m
[
'result'
]
is
None
:
# Only display AMP if a result exist
continue
# Display AMP
# first_column = '{0} {1}/{2}'.format(m['key'], int(m['timer']), int(m['refresh']))
first_column
=
'{0}'
.
format
(
m
[
'key'
])
for
l
in
m
[
'result'
].
split
(
'
\n
'
):
# Display first column with the process name...
msg
=
'{0:<16} '
.
format
(
first_column
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{0}'
.
format
(
v
.
replace
(
'
\n
'
,
''
))
ret
.
append
(
self
.
curse_add_line
(
msg
,
splittable
=
True
))
ret
.
append
(
self
.
curse_new_line
())
# ... only on the first line
first_column
=
''
# Display AMP result in the second column
ret
.
append
(
self
.
curse_add_line
(
l
,
splittable
=
True
))
ret
.
append
(
self
.
curse_new_line
())
# Delete the last empty line
try
:
...
...
glances/plugins/glances_ip.py
浏览文件 @
09d87e0a
...
...
@@ -138,11 +138,15 @@ class Plugin(GlancesPlugin):
# VPN with no internet access (issue #842)
msg
=
'/{0}'
.
format
(
self
.
stats
[
'mask_cidr'
])
ret
.
append
(
self
.
curse_add_line
(
msg
))
if
self
.
stats
[
'public_address'
]
is
not
None
:
msg
=
' Pub '
ret
.
append
(
self
.
curse_add_line
(
msg
,
'TITLE'
))
msg
=
'{0:}'
.
format
(
self
.
stats
[
'public_address'
])
ret
.
append
(
self
.
curse_add_line
(
msg
))
try
:
msg_pub
=
'{0:}'
.
format
(
self
.
stats
[
'public_address'
])
except
UnicodeEncodeError
:
pass
else
:
if
self
.
stats
[
'public_address'
]
is
not
None
:
msg
=
' Pub '
ret
.
append
(
self
.
curse_add_line
(
msg
,
'TITLE'
))
ret
.
append
(
self
.
curse_add_line
(
msg_pub
))
return
ret
...
...
@@ -186,7 +190,10 @@ class PublicIpAddress(object):
queue_target
.
put
(
None
)
else
:
# Request depend on service
if
not
json
:
queue_target
.
put
(
response
)
else
:
queue_target
.
put
(
loads
(
response
)[
key
])
try
:
if
not
json
:
queue_target
.
put
(
response
)
else
:
queue_target
.
put
(
loads
(
response
)[
key
])
except
ValueError
:
queue_target
.
put
(
None
)
glances/timer.py
浏览文件 @
09d87e0a
...
...
@@ -2,7 +2,7 @@
#
# This file is part of Glances.
#
# Copyright (C) 201
5
Nicolargo <nicolas@nicolargo.com>
# Copyright (C) 201
6
Nicolargo <nicolas@nicolargo.com>
#
# Glances is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
...
...
@@ -53,6 +53,9 @@ class Timer(object):
def
reset
(
self
):
self
.
start
()
def
get
(
self
):
return
self
.
duration
-
(
self
.
target
-
time
())
def
set
(
self
,
duration
):
self
.
duration
=
duration
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录