summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2023-10-08 10:10:13 +0200
committernicolargo <nicolas@nicolargo.com>2023-10-08 10:10:13 +0200
commit55d7c07543a52c82839ea177763d4840f228bab7 (patch)
tree775bc2b61857f9683facd08b62c55760209cc68b
parentcb4a8b80b7e4b440132df8aed8fac4203d1dc6d9 (diff)
CouchDB migration from CouchDB to PyCouchDB library #2570
-rw-r--r--README.rst2
-rw-r--r--conf/glances.conf6
-rw-r--r--docs/gw/couchdb.rst8
-rw-r--r--glances/exports/couchdb/__init__.py56
-rw-r--r--optional-requirements.txt2
-rwxr-xr-xsetup.py4
6 files changed, 36 insertions, 42 deletions
diff --git a/README.rst b/README.rst
index b76de522..3af03fe4 100644
--- a/README.rst
+++ b/README.rst
@@ -95,7 +95,6 @@ Optional dependencies:
- ``bottle`` (for Web server mode)
- ``cassandra-driver`` (for the Cassandra export module)
- ``chevron`` (for the action script feature)
-- ``couchdb`` (for the CouchDB export module)
- ``docker`` (for the Containers Docker monitoring support)
- ``elasticsearch`` (for the Elastic Search export module)
- ``graphitesender`` (For the Graphite export module)
@@ -105,6 +104,7 @@ Optional dependencies:
- ``kafka-python`` (for the Kafka export module)
- ``netifaces`` (for the IP plugin)
- ``py3nvml`` (for the GPU plugin)
+- ``pycouchdb`` (for the CouchDB export module)
- ``pika`` (for the RabbitMQ/ActiveMQ export module)
- ``podman`` (for the Containers Podman monitoring support)
- ``potsdb`` (for the OpenTSDB export module)
diff --git a/conf/glances.conf b/conf/glances.conf
index 7bf00d66..d957ed3f 100644
--- a/conf/glances.conf
+++ b/conf/glances.conf
@@ -595,10 +595,8 @@ topic_structure=per-metric
host=localhost
port=5984
db=glances
-# user and password are optional (comment if not configured on the server side)
-# If they are used, then the https protocol will be used
-#user=root
-#password=root
+user=admin
+password=admin
[mongodb]
# Configuration for the --export mongodb option
diff --git a/docs/gw/couchdb.rst b/docs/gw/couchdb.rst
index b5bf2e0f..5916ba8f 100644
--- a/docs/gw/couchdb.rst
+++ b/docs/gw/couchdb.rst
@@ -11,10 +11,10 @@ following:
[couchdb]
host=localhost
- port=
+ port=5984
+ db=glances
user=root
password=example
- db=glances
and run Glances with:
@@ -26,7 +26,7 @@ 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")
+- ``time``: timestamp (format: "2016-09-24T16:39:08.524Z")
Example of Couch Document for the load stats:
@@ -36,7 +36,7 @@ Example of Couch Document for the load stats:
"_id": "36cbbad81453c53ef08804cb2612d5b6",
"_rev": "1-382400899bec5615cabb99aa34df49fb",
"min15": 0.33,
- "time": "2016-09-24T16:39:08.524828Z",
+ "time": "2016-09-24T16:39:08.524Z",
"min5": 0.4,
"cpucore": 4,
"load_warning": 1,
diff --git a/glances/exports/couchdb/__init__.py b/glances/exports/couchdb/__init__.py
index 4c50000c..7f3a216a 100644
--- a/glances/exports/couchdb/__init__.py
+++ b/glances/exports/couchdb/__init__.py
@@ -9,14 +9,21 @@
"""CouchDB interface class."""
+#
+# How to test ?
+#
+# 1) docker run -d -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=admin -p 5984:5984 --name my-couchdb couchdb
+# 2) ./venv/bin/python -m glances -C ./conf/glances.conf --export couchdb --quiet
+# 3) Result can be seen at: http://127.0.0.1:5984/_utils
+#
+
import sys
from datetime import datetime
from glances.logger import logger
from glances.exports.export import GlancesExport
-import couchdb
-import couchdb.mapping
+import pycouchdb
class Export(GlancesExport):
@@ -27,15 +34,11 @@ class Export(GlancesExport):
"""Init the CouchDB export IF."""
super(Export, self).__init__(config=config, args=args)
- # Mandatory configuration keys (additional to host and port)
- self.db = None
-
- # Optional configuration keys
- self.user = None
- self.password = None
-
- # Load the Cassandra configuration file section
- self.export_enable = self.load_conf('couchdb', mandatories=['host', 'port', 'db'], options=['user', 'password'])
+ # Load the CouchDB configuration file section
+ # User and Password are mandatory with CouchDB 3.0 and higher
+ self.export_enable = self.load_conf('couchdb',
+ mandatories=['host', 'port', 'db',
+ 'user', 'password'])
if not self.export_enable:
sys.exit(2)
@@ -47,35 +50,29 @@ class Export(GlancesExport):
if not self.export_enable:
return None
- if self.user is None:
- server_uri = 'http://{}:{}/'.format(self.host, self.port)
- else:
- # Force https if a login/password is provided
- # Related to https://github.com/nicolargo/glances/issues/2124
- server_uri = 'https://{}:{}@{}:{}/'.format(self.user, self.password, self.host, self.port)
+ # @TODO: https
+ server_uri = 'http://{}:{}@{}:{}/'.format(self.user, self.password,
+ self.host, self.port)
try:
- s = couchdb.Server(server_uri)
+ s = pycouchdb.Server(server_uri)
except Exception as e:
logger.critical("Cannot connect to CouchDB server (%s)" % e)
sys.exit(2)
else:
- logger.info("Connected to the CouchDB server")
+ logger.info("Connected to the CouchDB server version %s" % s.info()['version'])
try:
- s[self.db]
+ s.database(self.db)
except Exception:
# Database did not exist
# Create it...
s.create(self.db)
+ logger.info("Create CouchDB database %s" % self.db)
else:
- logger.info("There is already a %s database" % self.db)
-
- return s
+ logger.info("CouchDB database %s already exist" % self.db)
- def database(self):
- """Return the CouchDB database object"""
- return self.client[self.db]
+ return s.database(self.db)
def export(self, name, columns, points):
"""Write the points to the CouchDB server."""
@@ -84,13 +81,12 @@ class Export(GlancesExport):
# Create DB input
data = dict(zip(columns, points))
- # Set the type to the current stat name
+ # Add the type and the timestamp in ISO format
data['type'] = name
- data['time'] = couchdb.mapping.DateTimeField()._to_json(datetime.now())
+ data['time'] = datetime.now().isoformat()[:-3] + 'Z'
# Write data to the CouchDB database
- # Result can be seen at: http://127.0.0.1:5984/_utils
try:
- self.client[self.db].save(data)
+ self.client.save(data)
except Exception as e:
logger.error("Cannot export {} stats to CouchDB ({})".format(name, e))
diff --git a/optional-requirements.txt b/optional-requirements.txt
index d53ef338..0de8809c 100644
--- a/optional-requirements.txt
+++ b/optional-requirements.txt
@@ -6,7 +6,6 @@ bernhard
bottle
cassandra-driver
chevron
-couchdb
docker>=6.1.1
elasticsearch
graphitesender
@@ -21,6 +20,7 @@ pika
podman; python_version >= "3.6"
potsdb
prometheus_client
+pycouchdb
pygal
pymdstat
pymongo; python_version >= "3.7"
diff --git a/setup.py b/setup.py
index 24e09e87..092a3a82 100755
--- a/setup.py
+++ b/setup.py
@@ -56,8 +56,8 @@ def get_install_extras_require():
'browser': ['zeroconf>=0.19.1'],
'cloud': ['requests'],
'containers': ['docker>=6.1.1', 'python-dateutil', 'six', 'podman', 'packaging'],
- 'export': ['bernhard', 'cassandra-driver', 'couchdb', 'elasticsearch',
- 'graphitesender', 'influxdb>=1.0.0', 'influxdb-client', 'pymongo',
+ 'export': ['bernhard', 'cassandra-driver', 'elasticsearch', 'graphitesender',
+ 'ibmcloudant', 'influxdb>=1.0.0', 'influxdb-client', 'pymongo',
'kafka-python', 'pika', 'paho-mqtt', 'potsdb', 'prometheus_client',
'pyzmq', 'statsd'],
'gpu': ['py3nvml'],