From e44da25849e6ac0136ceea76e3d4b07c9942e1e8 Mon Sep 17 00:00:00 2001 From: nico Date: Wed, 21 Nov 2018 18:28:43 +0100 Subject: ajustments and multigraph additions + add storages and filecount to multigraph plugin * ajust dictkeys to match over all plugins * update Readme --- README.md | 38 +++++++++++++++++++++++++++++--------- nextcloud_files.py | 6 +++--- nextcloud_multi.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++- nextcloud_storage.py | 6 +++--- 4 files changed, 82 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 267f9a8..3a503ad 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Nextcloud Munin Plugin -Within this repository there are some basic Munin Plugins gathering information from the NextCloud external API. I choose to also include a multigraph plugin `nextcloud_multi` which does everything the other plugins do but in one single request. +Within this repository there are some basic Munin Plugins gathering information from the NextCloud external API. I choose to also include a multigraph plugin `nextcloud_multi.py` which does everything the other plugins dynamically. -There are drawbacks to using a multigraph plugin which can be read up here : [Munin-Monitoring.org](http://guide.munin-monitoring.org/en/latest/plugin/multigraphing.html) +There are requirements for using a multigraph plugin which can be read up here : [Munin-Monitoring.org/multigraphing](http://guide.munin-monitoring.org/en/latest/plugin/multigraphing.html) ## install -To use these plugins properly some configuration parameters need to be added to the plugin-config `/etc/munin/plugin-config.d/munin-node`. +To use these plugins properly some configuration parameters need to be added to the plugin-config `/etc/munin/plugin-config.d/custom-config`. ``` [nextcloud_*] url = https://URL.TO.YOUR.NEXTCLOUD.tld/ocs/v2.php/apps/serverinfo/api/v1/info @@ -16,25 +16,45 @@ To install these plugins, you just have to symlink those plugins you would like After this has been done the munin-node needs to be restarted to facilitate the new plugins. `systemctl restart munin-node` +It is possible to run the plugins in a virtual environment, for that the environment needs to be initialized and the required packages to be installed. +``` +virtualenv -p python3 /path/to/your/venv + +pip install -r requirements.txt +``` + ### everything working? To check if everything is working as expected check if the plugins are listed and actually gather data. ``` telnet localhost 4949 # localhost or IP the munin-node list -fetch nextcloud_shares -fetch nextcloud_users -fetch nextcloud_db -fetch nextcloud_apps +fetch nextcloud_shares.py +num_fed_shares_received.value 1 +num_shares_link_no_password.value 5 +num_shares_user.value 13 +num_shares.value 21 +num_shares_link.value 5 +num_shares_groups.value 0 +num_fed_shares_sent.value 0 ``` If everything works as it should, list will return the symlinked plugins within the list of active plugins. ##### multipgrah plugin -To check if the multigraph plugin is working correctly it is necessary to first instruct the capability multigraph before the `list` instruction. +To check if the multigraph plugin is working correctly, it is necessary to first instruct the multigraph capability, before the `list` instruction will list the plugin. ``` telnet localhost 4949 # localhost or IP the munin-node cap multigraph list -fetch nextcloud_multi +fetch nextcloud_multi.py +multigraph nextcloud_shares +num_fed_shares_received.value 1 +num_shares_link_no_password.value 5 +num_shares_user.value 13 +num_shares.value 21 +num_shares_link.value 5 +num_shares_groups.value 0 +num_fed_shares_sent.value 0 +... ``` The `fetch` commands will run the script and return the gathered values. As long as none of them are NaN everything works as expected. diff --git a/nextcloud_files.py b/nextcloud_files.py index 226a94f..ee12d77 100755 --- a/nextcloud_files.py +++ b/nextcloud_files.py @@ -20,7 +20,7 @@ import os class NextcloudStorage: def config(self): config = { - 'storage': [ + 'filecount': [ 'graph_title Nextcloud Files', 'graph_args --base 1000 -l 0', 'graph_vlabel number of files', @@ -36,12 +36,12 @@ class NextcloudStorage: def get_data(self, api_response): data = { - 'nextcloud_storage': [], + 'nextcloud_filecount': [], } # append the total number of files present num_files = api_response['ocs']['data']['nextcloud']['storage']['num_files'] - data['nextcloud_storage'].append('num_files.value %s' % num_files) + data['nextcloud_filecount'].append('num_files.value %s' % num_files) return data diff --git a/nextcloud_multi.py b/nextcloud_multi.py index 5e4b18e..4598252 100755 --- a/nextcloud_multi.py +++ b/nextcloud_multi.py @@ -97,6 +97,37 @@ class NextcloudMultiGraph: 'num_updates_available.info number of available app updates', 'num_updates_available.min 0', 'num_updates_available.warning 1' + ], + 'storages': [ + 'multigraph nextcloud_storages', + 'graph_title Nextcloud Storages', + 'graph_args --base 1000 -l 0', + 'graph_vlabel number', + 'graph_info graph showing the number of storages', + 'graph_category nextcloud', + 'num_storages.label total number of storages', + 'num_storages.info current over all total of storages', + 'num_storages.min 0', + 'num_storages_local.label number of local storages', + 'num_storages_local.info current over all total of storage', + 'num_storages_local.min 0', + 'num_storages_home.label number of home storages', + 'num_storages_home.info current over all total of storage', + 'num_storages_home.min 0', + 'num_storages_other.label number of other storages', + 'num_storages_other.info current over all total of storage', + 'num_storages_other.min 0' + ], + "filecount": [ + 'multigraph nextcloud_filecount', + 'graph_title Nextcloud Files', + 'graph_args --base 1000 -l 0', + 'graph_vlabel number of files', + 'graph_info graph showing the number of files', + 'graph_category nextcloud', + 'num_files.label number of files', + 'num_files.info current number of files in the repository', + 'num_files.min 0' ] } @@ -107,7 +138,9 @@ class NextcloudMultiGraph: 'nextcloud_users': [], 'nextcloud_shares': [], 'nextcloud_dbsize': [], - 'nextcloud_available_updates': [] + 'nextcloud_available_updates': [], + 'nextcloud_storages': [], + 'nextcloud_filecount': [] } # users @@ -144,6 +177,19 @@ class NextcloudMultiGraph: data['nextcloud_available_updates'].append('multigraph nextcloud_available_updates') data['nextcloud_available_updates'].append('num_updates_available.value %s' % num_updates_available) + # storage + storage = api_response['ocs']['data']['nextcloud']['storage'] + data['nextcloud_storages'].append('multigraph nextcloud_storages') + + # append for every key in storage the key and the value if the key starts with "num" + [data['nextcloud_storages'].append(str(key) + ".value " + str(storage[key])) + for key in storage if key.startswith('num_storages')] + + # filecount + num_files = api_response['ocs']['data']['nextcloud']['storage']['num_files'] + data['nextcloud_filecount'].append('multigraph nextcloud_filecount') + data['nextcloud_filecount'].append('num_files.value %s' % num_files) + return data def run(self): diff --git a/nextcloud_storage.py b/nextcloud_storage.py index ed6c74e..ee3d7d2 100755 --- a/nextcloud_storage.py +++ b/nextcloud_storage.py @@ -21,7 +21,7 @@ class NextcloudStorage: def config(self): config = { 'storage': [ - 'graph_title Nextcloud Storage', + 'graph_title Nextcloud Storages', 'graph_args --base 1000 -l 0', 'graph_vlabel number of storage', 'graph_info graph showing the number of storages', @@ -45,14 +45,14 @@ class NextcloudStorage: def get_data(self, api_response): data = { - 'nextcloud_storage': [], + 'nextcloud_storages': [], } # storage storage = api_response['ocs']['data']['nextcloud']['storage'] # append for every key in storage the key and the value if the key starts with "num" - [data['nextcloud_storage'].append(str(key) + ".value " + str(storage[key])) + [data['nextcloud_storages'].append(str(key) + ".value " + str(storage[key])) for key in storage if key.startswith('num_storages')] return data -- cgit v1.2.3-18-g5258