Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
20ca58d5
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 搜索 >>
提交
20ca58d5
编写于
3月 31, 2019
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' into issue1446
上级
2853f54e
f9ae1eb7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
46 addition
and
51 deletion
+46
-51
NEWS
NEWS
+2
-0
conf/glances.conf
conf/glances.conf
+1
-0
glances/exports/glances_mqtt.py
glances/exports/glances_mqtt.py
+8
-5
glances/plugins/glances_alert.py
glances/plugins/glances_alert.py
+35
-46
未找到文件。
NEWS
浏览文件 @
20ca58d5
...
@@ -15,6 +15,8 @@ Bugs corrected:
...
@@ -15,6 +15,8 @@ Bugs corrected:
* Fix Cassandra table name export #1402
* Fix Cassandra table name export #1402
* 500 Internal Server Error /api/3/network/interface_name #1401
* 500 Internal Server Error /api/3/network/interface_name #1401
* Connection to MQTT server failed : getaddrinfo() argument 2 must be integer or string #1450
* `l` keypress (hide alert log) not working after some time #1449
Others:
Others:
...
...
conf/glances.conf
浏览文件 @
20ca58d5
...
@@ -413,6 +413,7 @@ port=8883
...
@@ -413,6 +413,7 @@ port=8883
user
=
guest
user
=
guest
password
=
guest
password
=
guest
topic
=
glances
topic
=
glances
tls
=
true
[
couchdb
]
[
couchdb
]
# Configuration for the --export couchdb option
# Configuration for the --export couchdb option
...
...
glances/exports/glances_mqtt.py
浏览文件 @
20ca58d5
...
@@ -42,20 +42,22 @@ class Export(GlancesExport):
...
@@ -42,20 +42,22 @@ class Export(GlancesExport):
self
.
user
=
None
self
.
user
=
None
self
.
password
=
None
self
.
password
=
None
self
.
topic
=
None
self
.
topic
=
None
self
.
tls
=
'true'
# Load the MQTT configuration file
# Load the MQTT configuration file
self
.
export_enable
=
self
.
load_conf
(
'mqtt'
,
self
.
export_enable
=
self
.
load_conf
(
'mqtt'
,
mandatories
=
[
'host'
,
'password'
],
mandatories
=
[
'host'
,
'password'
],
options
=
[
'port'
,
'user'
,
'topic'
])
options
=
[
'port'
,
'user'
,
'topic'
,
'tls'
])
if
not
self
.
export_enable
:
if
not
self
.
export_enable
:
exit
(
'Missing MQTT config'
)
exit
(
'Missing MQTT config'
)
# Get the current hostname
# Get the current hostname
self
.
hostname
=
socket
.
gethostname
()
self
.
hostname
=
socket
.
gethostname
()
self
.
port
=
self
.
port
or
8883
self
.
port
=
int
(
self
.
port
)
or
8883
self
.
topic
=
self
.
topic
or
'glances'
self
.
topic
=
self
.
topic
or
'glances'
self
.
user
=
self
.
user
or
'glances'
self
.
user
=
self
.
user
or
'glances'
self
.
tls
=
(
self
.
tls
.
lower
()
==
'true'
)
# Init the MQTT client
# Init the MQTT client
self
.
client
=
self
.
init
()
self
.
client
=
self
.
init
()
...
@@ -69,7 +71,8 @@ class Export(GlancesExport):
...
@@ -69,7 +71,8 @@ class Export(GlancesExport):
clean_session
=
False
)
clean_session
=
False
)
client
.
username_pw_set
(
username
=
self
.
user
,
client
.
username_pw_set
(
username
=
self
.
user
,
password
=
self
.
password
)
password
=
self
.
password
)
client
.
tls_set
(
certs
.
where
())
if
self
.
tls
:
client
.
tls_set
(
certs
.
where
())
client
.
connect
(
host
=
self
.
host
,
client
.
connect
(
host
=
self
.
host
,
port
=
self
.
port
)
port
=
self
.
port
)
client
.
loop_start
()
client
.
loop_start
()
...
@@ -81,8 +84,8 @@ class Export(GlancesExport):
...
@@ -81,8 +84,8 @@ class Export(GlancesExport):
def
export
(
self
,
name
,
columns
,
points
):
def
export
(
self
,
name
,
columns
,
points
):
"""Write the points in MQTT."""
"""Write the points in MQTT."""
WHITELIST
=
'_-'
+
string
.
ascii_letters
+
string
.
digits
WHITELIST
=
'_-'
+
string
.
ascii_letters
+
string
.
digits
SUBSTITUTE
=
'_'
SUBSTITUTE
=
'_'
def
whitelisted
(
s
,
def
whitelisted
(
s
,
whitelist
=
WHITELIST
,
whitelist
=
WHITELIST
,
...
...
glances/plugins/glances_alert.py
浏览文件 @
20ca58d5
...
@@ -114,59 +114,48 @@ class Plugin(GlancesPlugin):
...
@@ -114,59 +114,48 @@ class Plugin(GlancesPlugin):
ret
=
[]
ret
=
[]
# Only process if display plugin enable...
# Only process if display plugin enable...
if
not
self
.
stats
and
self
.
is_disable
():
if
not
self
.
stats
or
self
.
is_disable
():
return
ret
return
ret
# Build the string message
# Build the string message
# Header
# Header
ret
.
append
(
self
.
curse_add_line
(
global_message
(),
"TITLE"
))
ret
.
append
(
self
.
curse_add_line
(
global_message
(),
"TITLE"
))
if
self
.
stats
:
# Loop over alerts
# Header
for
alert
in
self
.
stats
:
# msg = 'Warning or critical alerts'
# New line
# ret.append(self.curse_add_line(msg, "TITLE"))
ret
.
append
(
self
.
curse_new_line
())
# logs_len = glances_events.len()
# Start
# if logs_len > 1:
msg
=
str
(
datetime
.
fromtimestamp
(
alert
[
0
]))
# msg = ' (last {} entries)'.format(logs_len)
ret
.
append
(
self
.
curse_add_line
(
msg
))
# else:
# Duration
# msg = ' (one entry)'
if
alert
[
1
]
>
0
:
# ret.append(self.curse_add_line(msg, "TITLE"))
# If finished display duration
# Loop over alerts
msg
=
' ({})'
.
format
(
datetime
.
fromtimestamp
(
alert
[
1
])
-
for
alert
in
self
.
stats
:
datetime
.
fromtimestamp
(
alert
[
0
]))
# New line
else
:
ret
.
append
(
self
.
curse_new_line
())
msg
=
' (ongoing)'
# Start
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
str
(
datetime
.
fromtimestamp
(
alert
[
0
]))
ret
.
append
(
self
.
curse_add_line
(
" - "
))
# Infos
if
alert
[
1
]
>
0
:
# If finished do not display status
msg
=
'{} on {}'
.
format
(
alert
[
2
],
alert
[
3
])
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
# Duration
else
:
if
alert
[
1
]
>
0
:
msg
=
str
(
alert
[
3
])
# If finished display duration
ret
.
append
(
self
.
curse_add_line
(
msg
,
decoration
=
alert
[
2
]))
msg
=
' ({})'
.
format
(
datetime
.
fromtimestamp
(
alert
[
1
])
-
# Min / Mean / Max
datetime
.
fromtimestamp
(
alert
[
0
]))
if
self
.
approx_equal
(
alert
[
6
],
alert
[
4
],
tolerance
=
0.1
):
else
:
msg
=
' ({:.1f})'
.
format
(
alert
[
5
])
msg
=
' (ongoing)'
else
:
msg
=
' (Min:{:.1f} Mean:{:.1f} Max:{:.1f})'
.
format
(
alert
[
6
],
alert
[
5
],
alert
[
4
])
ret
.
append
(
self
.
curse_add_line
(
msg
))
# Top processes
top_process
=
', '
.
join
([
p
[
'name'
]
for
p
in
alert
[
9
]])
if
top_process
!=
''
:
msg
=
': {}'
.
format
(
top_process
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
append
(
self
.
curse_add_line
(
" - "
))
# Infos
if
alert
[
1
]
>
0
:
# If finished do not display status
msg
=
'{} on {}'
.
format
(
alert
[
2
],
alert
[
3
])
ret
.
append
(
self
.
curse_add_line
(
msg
))
else
:
msg
=
str
(
alert
[
3
])
ret
.
append
(
self
.
curse_add_line
(
msg
,
decoration
=
alert
[
2
]))
# Min / Mean / Max
if
self
.
approx_equal
(
alert
[
6
],
alert
[
4
],
tolerance
=
0.1
):
msg
=
' ({:.1f})'
.
format
(
alert
[
5
])
else
:
msg
=
' (Min:{:.1f} Mean:{:.1f} Max:{:.1f})'
.
format
(
alert
[
6
],
alert
[
5
],
alert
[
4
])
ret
.
append
(
self
.
curse_add_line
(
msg
))
# Top processes
top_process
=
', '
.
join
([
p
[
'name'
]
for
p
in
alert
[
9
]])
if
top_process
!=
''
:
msg
=
': {}'
.
format
(
top_process
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
# logger.info(alert)
return
ret
return
ret
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录