diff options
Diffstat (limited to '')
-rw-r--r-- | collectors/python.d.plugin/ipfs/ipfs.chart.py (renamed from python.d/ipfs.chart.py) | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/python.d/ipfs.chart.py b/collectors/python.d.plugin/ipfs/ipfs.chart.py index 43500dfb5..3f6794e48 100644 --- a/python.d/ipfs.chart.py +++ b/collectors/python.d.plugin/ipfs/ipfs.chart.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Description: IPFS netdata python.d module -# Authors: Pawel Krupa (paulfantom), davidak +# Authors: davidak +# SPDX-License-Identifier: GPL-3.0-or-later import json @@ -26,31 +27,43 @@ CHARTS = { 'bandwidth': { 'options': [None, 'IPFS Bandwidth', 'kbits/s', 'Bandwidth', 'ipfs.bandwidth', 'line'], 'lines': [ - ["in", None, "absolute", 8, 1000], - ["out", None, "absolute", -8, 1000] - ]}, + ['in', None, 'absolute', 8, 1000], + ['out', None, 'absolute', -8, 1000] + ] + }, 'peers': { 'options': [None, 'IPFS Peers', 'peers', 'Peers', 'ipfs.peers', 'line'], 'lines': [ - ["peers", None, 'absolute'] - ]}, + ['peers', None, 'absolute'] + ] + }, 'repo_size': { 'options': [None, 'IPFS Repo Size', 'GB', 'Size', 'ipfs.repo_size', 'area'], 'lines': [ - ["avail", None, "absolute", 1, 1e9], - ["size", None, "absolute", 1, 1e9], - ]}, + ['avail', None, 'absolute', 1, 1e9], + ['size', None, 'absolute', 1, 1e9], + ] + }, 'repo_objects': { 'options': [None, 'IPFS Repo Objects', 'objects', 'Objects', 'ipfs.repo_objects', 'line'], 'lines': [ - ["objects", None, "absolute", 1, 1], - ["pinned", None, "absolute", 1, 1], - ["recursive_pins", None, "absolute", 1, 1] - ]}, + ['objects', None, 'absolute', 1, 1], + ['pinned', None, 'absolute', 1, 1], + ['recursive_pins', None, 'absolute', 1, 1] + ] + } } -SI_zeroes = {'k': 3, 'm': 6, 'g': 9, 't': 12, - 'p': 15, 'e': 18, 'z': 21, 'y': 24} +SI_zeroes = { + 'k': 3, + 'm': 6, + 'g': 9, + 't': 12, + 'p': 15, + 'e': 18, + 'z': 21, + 'y': 24 +} class Service(UrlService): @@ -60,6 +73,7 @@ class Service(UrlService): self.order = ORDER self.definitions = CHARTS self.__storage_max = None + self.do_pinapi = self.configuration.get('pinapi') def _get_json(self, sub_url): """ @@ -73,7 +87,7 @@ class Service(UrlService): @staticmethod def _recursive_pins(keys): - return len([k for k in keys if keys[k]["Type"] == b"recursive"]) + return sum(1 for k in keys if keys[k]['Type'] == b'recursive') @staticmethod def _dehumanize(store_max): @@ -93,7 +107,7 @@ class Service(UrlService): def _storagemax(self, store_cfg): if self.__storage_max is None: - self.__storage_max = self._dehumanize(store_cfg['StorageMax']) + self.__storage_max = self._dehumanize(store_cfg) return self.__storage_max def _get_data(self): @@ -106,13 +120,15 @@ class Service(UrlService): '/api/v0/stats/bw': [('in', 'RateIn', int), ('out', 'RateOut', int)], '/api/v0/swarm/peers': - [('peers', 'Strings', len)], + [('peers', 'Peers', len)], '/api/v0/stats/repo': - [('size', 'RepoSize', int), ('objects', 'NumObjects', int)], - '/api/v0/pin/ls': - [('pinned', 'Keys', len), ('recursive_pins', 'Keys', self._recursive_pins)], - '/api/v0/config/show': [('avail', 'Datastore', self._storagemax)] + [('size', 'RepoSize', int), ('objects', 'NumObjects', int), ('avail', 'StorageMax', self._storagemax)], } + if self.do_pinapi: + cfg.update({ + '/api/v0/pin/ls': + [('pinned', 'Keys', len), ('recursive_pins', 'Keys', self._recursive_pins)] + }) r = dict() for suburl in cfg: in_json = self._get_json(suburl) |