Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
cf6735a7
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,发现更多精彩内容 >>
提交
cf6735a7
编写于
9月 24, 2016
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a CouchDB exporter #928
上级
52e714ce
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
214 addition
and
3 deletion
+214
-3
NEWS
NEWS
+1
-0
conf/glances.conf
conf/glances.conf
+10
-0
docs/cmds.rst
docs/cmds.rst
+4
-0
docs/gw/couchdb.rst
docs/gw/couchdb.rst
+49
-0
docs/install.rst
docs/install.rst
+1
-1
docs/man/glances.1
docs/man/glances.1
+6
-1
glances/exports/glances_couchdb.py
glances/exports/glances_couchdb.py
+133
-0
glances/main.py
glances/main.py
+10
-1
未找到文件。
NEWS
浏览文件 @
cf6735a7
...
...
@@ -7,6 +7,7 @@ Version 2.8
Enhancements and new features:
* Add CouchDB exporter (issue #928)
* Highlight max stats in the processes list (issue #878)
Bugs corrected:
...
...
conf/glances.conf
浏览文件 @
cf6735a7
...
...
@@ -296,6 +296,16 @@ user=guest
password
=
guest
queue
=
glances_queue
[
couchdb
]
# Configuration for the --export-couchdb option
# https://www.couchdb.org
host
=
localhost
port
=
5984
db
=
glances
# user and password are optional (comment if not configured on the server side)
#user=root
#password=root
##############################################################################
# AMPS
# * enable: Enable (true) or disable (false) the AMP
...
...
docs/cmds.rst
浏览文件 @
cf6735a7
...
...
@@ -163,6 +163,10 @@ Command-Line Options
export stats to an Elasticsearch server (elasticsearch lib needed)
.. option:: --export-couchdb
export stats to a CouchDB server (couchdb lib needed)
.. option:: -c CLIENT, --client CLIENT
connect to a Glances server by IPv4/IPv6 address or hostname
...
...
docs/gw/couchdb.rst
0 → 100644
浏览文件 @
cf6735a7
.. _couchdb:
CouchDB
=======
You can export statistics to a ``CouchDB`` server.
The connection should be defined in the Glances configuration file as
following:
.. code-block:: ini
[couchdb]
host=localhost
port=5984
user=root
password=root
db=glances
and run Glances with:
.. code-block:: console
$ glances --export-couchdb
Documents are stored in native JSON format. Glances adds "type" and "time" entries.
- type: plugin name
- time: timestamp (format: "2016-09-24T16:39:08.524828Z")
Example of Couch Document for the load stats:
.. code-block:: console
{
"_id": "36cbbad81453c53ef08804cb2612d5b6",
"_rev": "1-382400899bec5615cabb99aa34df49fb",
"min15": 0.33,
"time": "2016-09-24T16:39:08.524828Z",
"min5": 0.4,
"cpucore": 4,
"load_warning": 1,
"min1": 0.5,
"history_size": 28800,
"load_critical": 5,
"type": "load",
"load_careful": 0.7
}
You can view the result using the CouchDB utils URL (http://127.0.0.1:5984/_utils/database.html?glances).
docs/install.rst
浏览文件 @
cf6735a7
...
...
@@ -22,7 +22,7 @@ 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 scandir
pip install bottle requests batinfo
py3sensors zeroconf netifaces pymdstat influxdb elasticsearch potsdb statsd pystache docker-py pysnmp pika py-cpuinfo bernhard cassandra scandir couchdb
To upgrade Glances to the latest version:
...
...
docs/man/glances.1
浏览文件 @
cf6735a7
.\" Man page generated from reStructuredText.
.
.TH "GLANCES" "1" "Sep
11, 2016" "2.7.1
" "Glances"
.TH "GLANCES" "1" "Sep
24, 2016" "2.8_DEVELOP
" "Glances"
.SH NAME
glances \- An eye on your system
.
...
...
@@ -244,6 +244,11 @@ export stats to an Elasticsearch server (elasticsearch lib needed)
.UNINDENT
.INDENT 0.0
.TP
.B \-\-export\-couchdb
export stats to a CouchDB server (couchdb lib needed)
.UNINDENT
.INDENT 0.0
.TP
.B \-c CLIENT, \-\-client CLIENT
connect to a Glances server by IPv4/IPv6 address or hostname
.UNINDENT
...
...
glances/exports/glances_couchdb.py
0 → 100644
浏览文件 @
cf6735a7
# -*- 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/>.
"""CouchDB interface class."""
import
sys
from
datetime
import
datetime
from
glances.compat
import
NoOptionError
,
NoSectionError
from
glances.logger
import
logger
from
glances.exports.glances_export
import
GlancesExport
import
couchdb
import
couchdb.mapping
class
Export
(
GlancesExport
):
"""This class manages the CouchDB export module."""
def
__init__
(
self
,
config
=
None
,
args
=
None
):
"""Init the CouchDB export IF."""
super
(
Export
,
self
).
__init__
(
config
=
config
,
args
=
args
)
# Load the Couchdb configuration file section ([export_couchdb])
self
.
host
=
None
self
.
port
=
None
self
.
user
=
None
self
.
password
=
None
self
.
db
=
None
self
.
export_enable
=
self
.
load_conf
()
if
not
self
.
export_enable
:
sys
.
exit
(
2
)
# Init the CouchDB client
self
.
client
=
self
.
init
()
def
load_conf
(
self
,
section
=
"couchdb"
):
"""Load the CouchDB 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
.
db
=
self
.
config
.
get_value
(
section
,
'db'
)
except
NoSectionError
:
logger
.
critical
(
"No CouchDB configuration found"
)
return
False
except
NoOptionError
as
e
:
logger
.
critical
(
"Error in the CouchDB configuration (%s)"
%
e
)
return
False
else
:
logger
.
debug
(
"Load CouchDB from the Glances configuration file"
)
# user and password are optional
try
:
self
.
user
=
self
.
config
.
get_value
(
section
,
'user'
)
self
.
password
=
self
.
config
.
get_value
(
section
,
'password'
)
except
NoOptionError
:
pass
return
True
def
init
(
self
):
"""Init the connection to the CouchDB server."""
if
not
self
.
export_enable
:
return
None
if
self
.
user
is
None
:
server_uri
=
'http://{}:{}/'
.
format
(
self
.
host
,
self
.
port
)
else
:
server_uri
=
'http://{}:{}@{}:{}/'
.
format
(
self
.
user
,
self
.
password
,
self
.
host
,
self
.
port
)
try
:
s
=
couchdb
.
Server
(
server_uri
)
except
Exception
as
e
:
logger
.
critical
(
"Cannot connect to CouchDB server %s (%s)"
%
(
server_uri
,
e
))
sys
.
exit
(
2
)
else
:
logger
.
info
(
"Connected to the CouchDB server %s"
%
server_uri
)
try
:
s
[
self
.
db
]
except
Exception
as
e
:
# Database did not exist
# Create it...
s
.
create
(
self
.
db
)
else
:
logger
.
info
(
"There is already a %s database"
%
self
.
db
)
return
s
def
database
(
self
):
"""Return the CouchDB database object"""
return
self
.
client
[
self
.
db
]
def
export
(
self
,
name
,
columns
,
points
):
"""Write the points to the CouchDB server."""
logger
.
debug
(
"Export {} stats to CouchDB"
.
format
(
name
))
# Create DB input
data
=
dict
(
zip
(
columns
,
points
))
# Set the type to the current stat name
data
[
'type'
]
=
name
data
[
'time'
]
=
couchdb
.
mapping
.
DateTimeField
().
_to_json
(
datetime
.
now
())
# Write input to the CouchDB database
# Result can be view: http://127.0.0.1:5984/_utils
try
:
self
.
client
[
self
.
db
].
save
(
data
)
except
Exception
as
e
:
logger
.
error
(
"Cannot export {} stats to CouchDB ({})"
.
format
(
name
,
e
))
glances/main.py
浏览文件 @
cf6735a7
...
...
@@ -175,6 +175,8 @@ Start the client browser (browser mode):\n\
dest
=
'export_rabbitmq'
,
help
=
'export stats to rabbitmq broker (pika lib needed)'
)
parser
.
add_argument
(
'--export-riemann'
,
action
=
'store_true'
,
default
=
False
,
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)'
)
# Client/Server option
parser
.
add_argument
(
'-c'
,
'--client'
,
dest
=
'client'
,
help
=
'connect to a Glances server by IPv4/IPv6 address or hostname'
)
...
...
@@ -334,7 +336,14 @@ Start the client browser (browser mode):\n\
self
.
args
=
args
# Export is only available in standalone or client mode (issue #614)
export_tag
=
args
.
export_csv
or
args
.
export_elasticsearch
or
args
.
export_statsd
or
args
.
export_influxdb
or
args
.
export_cassandra
or
args
.
export_opentsdb
or
args
.
export_rabbitmq
export_tag
=
args
.
export_csv
or
\
args
.
export_elasticsearch
or
\
args
.
export_statsd
or
\
args
.
export_influxdb
or
\
args
.
export_cassandra
or
\
args
.
export_opentsdb
or
\
args
.
export_rabbitmq
or
\
args
.
export_couchdb
if
not
(
self
.
is_standalone
()
or
self
.
is_client
())
and
export_tag
:
logger
.
critical
(
"Export is only available in standalone or client mode"
)
sys
.
exit
(
2
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录