Nextcloud Munin Plugin

basic idea

For a longer period of time I was looking for a Munin plugin to monitor the activity, especially the user activity on my cloud instance. There are some plugins out there, but most of them depend on externally querying the database.
With the External API and the server info dashboard Nextcloud itself presents an endpoint to gather data from. This way the database action is handled by the cloud and I can just grab the data from the endpoint.

why python?

I choose python to utilize the immensely strong requests module. In addition to that no extra json dump was necessary to work with the data which made the data extraction really easy.

# init requests session with specific header and credentials
s = requests.Session()
s.auth = auth
s.headers.update({'Accept': 'application/json'})

# request data from api
r = s.get(URL)
api_response = r.json()

In this example auth and url are passed as variables which were defined earlier in the plugin to specific environment variables. All together those 5 lines do the complete request and conversion to json action of the plugin.

Munin config

On running the plugins for the first time Munin will correctly recognize the configuration, even if the URL and authentication information is not set up until that point.


Both plugins need essentially the same configuration added to the the plugin-config /etc/munin/plugin-config.d/munin-node.

url = https://URL.TO.YOUR.NEXTCLOUD.tld/ocs/v2.php/apps/serverinfo/api/v1/info
username = username
password = password or logintoken


If all necessary configuration parameters are set the resulting graphs should look something like this.

Github : nextcloud-munin-py

comments powered by Disqus