Deploying nextcloud-exporter for Prometheus monitoring to Dokku

If you want to get Nextcloud metrics into Prometheus, you can use the https://github.com/xperimental/nextcloud-exporter/. It provides a couple of useful metrics to export and visualize in Grafana.

This tutorial is mostly based on this post: https://richardwillis.info/blog/monitor-dokku-server-prometheus-loki-grafana It requires a Grafana and Prometheus installation as described in the linked post. Also, you need a working Nextcloud installation in order to setup the exporter and query metrics from it’s API.

Generate Nextcloud API token

# Generate random value (for example using openssl)
TOKEN=$(openssl rand -hex 32)
# Set token (using the occ console application)
nextcloud.occ config:app:set serverinfo token --value "$TOKEN"

Setup nextcloud-exporter app on Dokku

Prepare the app

# Create App and port mapping
dokku apps:create nextcloud-exporter
dokku proxy:ports-set nextcloud-exporter http:80:9205

# The Docker Image doesn't recognize Letsencrypt as a valid CA, ignoring
dokku config:set --no-restart node-exporter DOKKU_DOCKERFILE_START_CMD="--server https://nextcloud.example.com --auth-token $TOKEN --tls-skip-verify true"

Deploy, setup letsencrypt and authentication

# Update to host network and disable deployment checks
dokku docker-options:add nextcloud-exporter deploy "--net=host"
dokku checks:disable nextcloud-exporter

# Pull Docker image and deploy app
docker image pull xperimental/nextcloud-exporter:latest
docker image tag xperimental/nextcloud-exporter:latest dokku/nextcloud-exporter:latest
dokku tags:deploy nextcloud-exporter latest

# Letsencrypt and create authentication
dokku letsencrypt nextcloud-exporter
dokku http-auth:on nextcloud-exporter <username> <password>

Add nextcloud-exporter to Prometheus configuration

Modify the target to your settings:

# vim /var/lib/dokku/data/storage/prometheus/config/prometheus.yml
  - job_name: nextcloud-exporter
    scrape_interval: 90s
    scheme: https
    basic_auth:
      username: $username
      password: $passw
    static_configs:
      - targets:
          - 'nextcloud-exporter.dokku.example.com'