summaryrefslogtreecommitdiffstats
path: root/collectors/python.d.plugin/rabbitmq
diff options
context:
space:
mode:
Diffstat (limited to 'collectors/python.d.plugin/rabbitmq')
-rw-r--r--collectors/python.d.plugin/rabbitmq/README.md2
-rw-r--r--collectors/python.d.plugin/rabbitmq/rabbitmq.chart.py122
-rw-r--r--collectors/python.d.plugin/rabbitmq/rabbitmq.conf10
3 files changed, 56 insertions, 78 deletions
diff --git a/collectors/python.d.plugin/rabbitmq/README.md b/collectors/python.d.plugin/rabbitmq/README.md
index 22d367c4..4ac60605 100644
--- a/collectors/python.d.plugin/rabbitmq/README.md
+++ b/collectors/python.d.plugin/rabbitmq/README.md
@@ -54,3 +54,5 @@ socket:
When no configuration file is found, module tries to connect to: `localhost:15672`.
---
+
+[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fcollectors%2Fpython.d.plugin%2Frabbitmq%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]()
diff --git a/collectors/python.d.plugin/rabbitmq/rabbitmq.chart.py b/collectors/python.d.plugin/rabbitmq/rabbitmq.chart.py
index 8298b403..a8f72592 100644
--- a/collectors/python.d.plugin/rabbitmq/rabbitmq.chart.py
+++ b/collectors/python.d.plugin/rabbitmq/rabbitmq.chart.py
@@ -3,23 +3,12 @@
# Author: l2isbad
# SPDX-License-Identifier: GPL-3.0-or-later
-from collections import namedtuple
from json import loads
-from socket import gethostbyname, gaierror
-from threading import Thread
-try:
- from queue import Queue
-except ImportError:
- from Queue import Queue
from bases.FrameworkServices.UrlService import UrlService
-# default module values (can be overridden per job in `config`)
-update_every = 1
-priority = 60000
-retries = 60
-
-METHODS = namedtuple('METHODS', ['get_data', 'url', 'stats'])
+API_NODE = 'api/nodes'
+API_OVERVIEW = 'api/overview'
NODE_STATS = [
'fd_used',
@@ -64,15 +53,15 @@ CHARTS = {
]
},
'memory': {
- 'options': [None, 'Memory', 'MB', 'overview', 'rabbitmq.memory', 'line'],
+ 'options': [None, 'Memory', 'MiB', 'overview', 'rabbitmq.memory', 'area'],
'lines': [
- ['mem_used', 'used', 'absolute', 1, 1024 << 10]
+ ['mem_used', 'used', 'absolute', 1, 1 << 20]
]
},
'disk_space': {
- 'options': [None, 'Disk Space', 'GB', 'overview', 'rabbitmq.disk_space', 'line'],
+ 'options': [None, 'Disk Space', 'GiB', 'overview', 'rabbitmq.disk_space', 'area'],
'lines': [
- ['disk_free', 'free', 'absolute', 1, 1024 ** 3]
+ ['disk_free', 'free', 'absolute', 1, 1 << 30]
]
},
'socket_descriptors': {
@@ -111,7 +100,7 @@ CHARTS = {
]
},
'message_rates': {
- 'options': [None, 'Message Rates', 'messages/s', 'overview', 'rabbitmq.message_rates', 'stacked'],
+ 'options': [None, 'Message Rates', 'messages/s', 'overview', 'rabbitmq.message_rates', 'line'],
'lines': [
['message_stats_ack', 'ack', 'incremental'],
['message_stats_redeliver', 'redeliver', 'incremental'],
@@ -127,74 +116,62 @@ class Service(UrlService):
UrlService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
- self.host = self.configuration.get('host', '127.0.0.1')
- self.port = self.configuration.get('port', 15672)
- self.scheme = self.configuration.get('scheme', 'http')
+ self.url = '{0}://{1}:{2}'.format(
+ configuration.get('scheme', 'http'),
+ configuration.get('host', '127.0.0.1'),
+ configuration.get('port', 15672),
+ )
+ self.node_name = str()
- def check(self):
- # We can't start if <host> AND <port> not specified
- if not (self.host and self.port):
- self.error('Host is not defined in the module configuration file')
- return False
+ def _get_data(self):
+ data = dict()
- # Hostname -> ip address
- try:
- self.host = gethostbyname(self.host)
- except gaierror as error:
- self.error(str(error))
- return False
-
- # Add handlers (auth, self signed cert accept)
- self.url = '{scheme}://{host}:{port}/api'.format(scheme=self.scheme,
- host=self.host,
- port=self.port)
- # Add methods
- api_node = self.url + '/nodes'
- api_overview = self.url + '/overview'
- self.methods = [METHODS(get_data=self._get_overview_stats,
- url=api_node,
- stats=NODE_STATS),
- METHODS(get_data=self._get_overview_stats,
- url=api_overview,
- stats=OVERVIEW_STATS)]
- return UrlService.check(self)
+ stats = self.get_overview_stats()
- def _get_data(self):
- threads = list()
- queue = Queue()
- result = dict()
+ if not stats:
+ return None
+
+ data.update(stats)
+
+ stats = self.get_nodes_stats()
+
+ if not stats:
+ return None
+
+ data.update(stats)
- for method in self.methods:
- th = Thread(target=method.get_data,
- args=(queue, method.url, method.stats))
- th.start()
- threads.append(th)
+ return data or None
- for thread in threads:
- thread.join()
- result.update(queue.get())
+ def get_overview_stats(self):
+ url = '{0}/{1}'.format(self.url, API_OVERVIEW)
- return result or None
+ raw = self._get_raw_data(url)
- def _get_overview_stats(self, queue, url, stats):
- """
- Format data received from http request
- :return: dict
- """
+ if not raw:
+ return None
- raw_data = self._get_raw_data(url)
+ data = loads(raw)
- if not raw_data:
- return queue.put(dict())
- data = loads(raw_data)
- data = data[0] if isinstance(data, list) else data
+ self.node_name = data['node']
- to_netdata = fetch_data(raw_data=data, metrics=stats)
- return queue.put(to_netdata)
+ return fetch_data(raw_data=data, metrics=OVERVIEW_STATS)
+
+ def get_nodes_stats(self):
+ url = '{0}/{1}/{2}'.format(self.url, API_NODE, self.node_name)
+
+ raw = self._get_raw_data(url)
+
+ if not raw:
+ return None
+
+ data = loads(raw)
+
+ return fetch_data(raw_data=data, metrics=NODE_STATS)
def fetch_data(raw_data, metrics):
data = dict()
+
for metric in metrics:
value = raw_data
metrics_list = metric.split('.')
@@ -204,4 +181,5 @@ def fetch_data(raw_data, metrics):
except KeyError:
continue
data['_'.join(metrics_list)] = value
+
return data
diff --git a/collectors/python.d.plugin/rabbitmq/rabbitmq.conf b/collectors/python.d.plugin/rabbitmq/rabbitmq.conf
index 3f90da8a..ae0dbdb7 100644
--- a/collectors/python.d.plugin/rabbitmq/rabbitmq.conf
+++ b/collectors/python.d.plugin/rabbitmq/rabbitmq.conf
@@ -27,11 +27,9 @@
# If unset, the default for python.d.plugin is used.
# priority: 60000
-# retries sets the number of retries to be made in case of failures.
-# If unset, the default for python.d.plugin is used.
-# Attempts to restore the service are made once every update_every
-# and only if the module has collected values in the past.
-# retries: 60
+# penalty indicates whether to apply penalty to update_every in case of failures.
+# Penalty will increase every 5 failed updates in a row. Maximum penalty is 10 minutes.
+# penalty: yes
# autodetection_retry sets the job re-check interval in seconds.
# The job is not deleted if check fails.
@@ -58,7 +56,7 @@
# # JOBs sharing a name are mutually exclusive
# update_every: 1 # the JOB's data collection frequency
# priority: 60000 # the JOB's order on the dashboard
-# retries: 60 # the JOB's number of restoration attempts
+# penalty: yes # the JOB's penalty
# autodetection_retry: 0 # the JOB's re-check interval in seconds
#
# Additionally to the above, rabbitmq plugin also supports the following: