Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
74593f13
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 搜索 >>
提交
74593f13
编写于
10月 15, 2016
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a ZeroMQ export module #939
上级
0c49fecf
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
192 addition
and
5 deletion
+192
-5
NEWS
NEWS
+1
-0
README.rst
README.rst
+2
-2
conf/glances.conf
conf/glances.conf
+11
-0
docs/gw/zeromq.rst
docs/gw/zeromq.rst
+53
-0
docs/install.rst
docs/install.rst
+1
-1
docs/man/glances.1
docs/man/glances.1
+1
-1
glances/exports/glances_zeromq.py
glances/exports/glances_zeromq.py
+120
-0
glances/main.py
glances/main.py
+3
-1
未找到文件。
NEWS
浏览文件 @
74593f13
...
...
@@ -7,6 +7,7 @@ Version 2.8
Enhancements and new features:
* Add ZeroMQ exporter (issue #939)
* Add CouchDB exporter (issue #928)
* Highlight max stats in the processes list (issue #878)
* Docker alerts and actions (issue #875)
...
...
README.rst
浏览文件 @
74593f13
...
...
@@ -109,14 +109,14 @@ features (like the Web interface, exports modules, sensors...):
.. code-block:: console
pip install bottle requests batinfo https://bitbucket.org/gleb_zhulik/py3sensors/get/tip.tar.gz zeroconf netifaces pymdstat influxdb elasticsearch potsdb statsd pystache docker-py pysnmp pika py-cpuinfo bernhard cassandra-driver scandir
pip install bottle requests batinfo https://bitbucket.org/gleb_zhulik/py3sensors/get/tip.tar.gz zeroconf netifaces pymdstat influxdb elasticsearch potsdb statsd pystache docker-py pysnmp pika py-cpuinfo bernhard cassandra-driver scandir
pyzmq
To upgrade Glances to the latest version:
.. code-block:: console
pip install --upgrade glances
pip install --upgrade bottle requests batinfo https://bitbucket.org/gleb_zhulik/py3sensors/get/tip.tar.gz zeroconf netifaces pymdstat influxdb elasticsearch potsdb statsd pystache docker-py pysnmp pika py-cpuinfo bernhard cassandra-driver scandir
pip install --upgrade bottle requests batinfo https://bitbucket.org/gleb_zhulik/py3sensors/get/tip.tar.gz zeroconf netifaces pymdstat influxdb elasticsearch potsdb statsd pystache docker-py pysnmp pika py-cpuinfo bernhard cassandra-driver scandir
pyzmq
If you need to install Glances in a specific user location, use:
...
...
conf/glances.conf
浏览文件 @
74593f13
...
...
@@ -319,6 +319,17 @@ db=glances
#user=root
#password=root
[
zeromq
]
# Configuration for the --export-zeromq option
# http://www.zeromq.org
host
=
127
.
0
.
0
.
1
port
=
5678
# Glances envelopes the stats in a publish message with two frames:
# - First frame containing the following prefix (STRING)
# - Second frame with the Glances plugin name (STRING)
# - Third frame with the Glances plugin stats (JSON)
prefix
=
G
##############################################################################
# AMPS
# * enable: Enable (true) or disable (false) the AMP
...
...
docs/gw/zeromq.rst
0 → 100644
浏览文件 @
74593f13
.. _zeromq:
ZeroMQ
======
You can export statistics to a ``ZeroMQ`` server.
The connection should be defined in the Glances configuration file as
following:
.. code-block:: ini
[zeromq]
host=127.0.0.1
port=5678
prefix=G
Note: Glances envelopes the stats in a publish message with two frames.
- first frame containing the following prefix (as STRING)
- second frame with the Glances plugin name (as STRING)
- third frame with the Glances plugin stats (as JSON)
Run Glances with:
.. code-block:: console
$ glances --export-zeromq
Following is a simple Python client to subscribe to the Glances stats:
.. code-block:: python
# -*- coding: utf-8 -*-
#
# ZeroMQ subscriber for Glances
#
import json
import zmq
context = zmq.Context()
subscriber = context.socket(zmq.SUB)
subscriber.setsockopt(zmq.SUBSCRIBE, 'G')
subscriber.connect("tcp://127.0.0.1:5678")
while True:
_, plugin, data_raw = subscriber.recv_multipart()
data = json.loads(data_raw)
print('{} => {}'.format(plugin, data))
subscriber.close()
context.term()
docs/install.rst
浏览文件 @
74593f13
...
...
@@ -22,7 +22,7 @@ features (like the Web interface, exports modules, sensors...):
.. code-block:: console
pip install bottle requests batinfo py3sensors zeroconf netifaces pymdstat influxdb elasticsearch potsdb statsd pystache docker-py pysnmp pika py-cpuinfo bernhard cassandra scandir couchdb
pip install bottle requests batinfo py3sensors zeroconf netifaces pymdstat influxdb elasticsearch potsdb statsd pystache docker-py pysnmp pika py-cpuinfo bernhard cassandra scandir couchdb
pyzmq
To upgrade Glances to the latest version:
...
...
docs/man/glances.1
浏览文件 @
74593f13
.\" Man page generated from reStructuredText.
.
.TH "GLANCES" "1" "Oct 1
0
, 2016" "2.8_DEVELOP" "Glances"
.TH "GLANCES" "1" "Oct 1
5
, 2016" "2.8_DEVELOP" "Glances"
.SH NAME
glances \- An eye on your system
.
...
...
glances/exports/glances_zeromq.py
0 → 100644
浏览文件 @
74593f13
# -*- coding: utf-8 -*-
#
# This file is part of Glances.
#
# Copyright (C) 2016 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Glances is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""ZeroMQ interface class."""
import
sys
from
datetime
import
datetime
import
time
import
json
from
glances.compat
import
NoOptionError
,
NoSectionError
from
glances.logger
import
logger
from
glances.exports.glances_export
import
GlancesExport
import
zmq
class
Export
(
GlancesExport
):
"""This class manages the ZeroMQ export module."""
def
__init__
(
self
,
config
=
None
,
args
=
None
):
"""Init the ZeroMQ export IF."""
super
(
Export
,
self
).
__init__
(
config
=
config
,
args
=
args
)
# Load the ZeroMQ configuration file section ([export_zeromq])
self
.
host
=
None
self
.
port
=
None
self
.
export_enable
=
self
.
load_conf
()
if
not
self
.
export_enable
:
sys
.
exit
(
2
)
# Init the ZeroMQ context
self
.
client
=
self
.
init
()
def
load_conf
(
self
,
section
=
"zeromq"
):
"""Load the ZeroMQ configuration in the Glances configuration file."""
if
self
.
config
is
None
:
return
False
try
:
self
.
host
=
self
.
config
.
get_value
(
section
,
'host'
)
self
.
port
=
self
.
config
.
get_value
(
section
,
'port'
)
self
.
prefix
=
self
.
config
.
get_value
(
section
,
'prefix'
)
except
NoSectionError
:
logger
.
critical
(
"No ZeroMQ configuration found"
)
return
False
except
NoOptionError
as
e
:
logger
.
critical
(
"Error in the ZeroMQ configuration (%s)"
%
e
)
return
False
else
:
logger
.
debug
(
"Load ZeroMQ from the Glances configuration file"
)
return
True
def
init
(
self
):
"""Init the connection to the CouchDB server."""
if
not
self
.
export_enable
:
return
None
server_uri
=
'tcp://{}:{}'
.
format
(
self
.
host
,
self
.
port
)
try
:
context
=
zmq
.
Context
()
publisher
=
context
.
socket
(
zmq
.
PUB
)
publisher
.
bind
(
server_uri
)
except
Exception
as
e
:
logger
.
critical
(
"Cannot connect to ZeroMQ server %s (%s)"
%
(
server_uri
,
e
))
sys
.
exit
(
2
)
else
:
logger
.
info
(
"Connected to the ZeroMQ server %s"
%
server_uri
)
return
publisher
def
exit
(
self
):
"""Close the socket"""
self
.
client
.
close
()
def
export
(
self
,
name
,
columns
,
points
):
"""Write the points to the ZeroMQ server."""
logger
.
debug
(
"Export {} stats to ZeroMQ"
.
format
(
name
))
# Create DB input
data
=
dict
(
zip
(
columns
,
points
))
# Do not publish empty stats
if
data
==
{}:
return
False
# Glances envelopes the stats in a publish message with two frames:
# - First frame containing the following prefix (STRING)
# - Second frame with the Glances plugin name (STRING)
# - Third frame with the Glances plugin stats (JSON)
message
=
[
str
(
self
.
prefix
),
name
,
json
.
dumps
(
data
)]
# Write data to the ZeroMQ bus
# Result can be view: tcp://host:port
try
:
self
.
client
.
send_multipart
(
message
)
except
Exception
as
e
:
logger
.
error
(
"Cannot export {} stats to ZeroMQ ({})"
.
format
(
name
,
e
))
return
True
glances/main.py
浏览文件 @
74593f13
...
...
@@ -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
...
...
@@ -176,6 +176,8 @@ Start the client browser (browser mode):\n\
dest
=
'export_riemann'
,
help
=
'export stats to riemann broker (bernhard lib needed)'
)
parser
.
add_argument
(
'--export-couchdb'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'export_couchdb'
,
help
=
'export stats to a CouchDB server (couch lib needed)'
)
parser
.
add_argument
(
'--export-zeromq'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'export_zeromq'
,
help
=
'export stats to a ZeroMQ server (pyzmq lib needed)'
)
# Client/Server option
parser
.
add_argument
(
'-c'
,
'--client'
,
dest
=
'client'
,
help
=
'connect to a Glances server by IPv4/IPv6 address or hostname'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录