├── backup ├── sudoers ├── clone-node.sh ├── backup.sh ├── re_initialise.sh ├── backup_client.sh └── restore.sh ├── mastodon ├── admin.env ├── versions.env ├── wait-for-container.sh ├── mastodon.env.template └── setup-mastodon.sh ├── .gitignore ├── sysctl └── 99-vm-max-map-count.conf ├── CODEOWNERS ├── monitoring ├── grafana-datasources.yaml ├── grafana-dashboards.yaml ├── monitoring-admin.env ├── monitoring-versions.env ├── prometheus.yaml ├── postgres-monitoring-queries.yaml ├── mastodon.json ├── caddy.json ├── sidekiq.json └── redis.json ├── systemd ├── clone-node.service ├── mastodon.service ├── mastodon-setup.service ├── mastodon-net-external.service ├── mastodon-net-internal.service ├── metrics-provider-es.service ├── mastodon-redis.service ├── metrics-provider-sidekiq.service ├── mastodon-db.service ├── metrics-provider-redis.service ├── metrics-provider-cadvisor.service ├── metrics-provider-mastodon.service ├── metrics-provider-nodeexporter.service ├── caddy.service ├── metrics-provider-postgres.service ├── mastodon-sidekiq.service ├── mastodon-web.service ├── mastodon-streaming.service ├── monitoring-prometheus.service ├── monitoring-grafana.service └── mastodon-es.service ├── code-of-conduct.md ├── caddy └── Caddyfile ├── clone-node.yaml ├── LICENSE ├── mastodon.yaml └── README.md /backup/sudoers: -------------------------------------------------------------------------------- 1 | backup ALL=NOPASSWD: /opt/backup/backup_client.sh 2 | -------------------------------------------------------------------------------- /mastodon/admin.env: -------------------------------------------------------------------------------- 1 | ADMIN_USER="__REPLACE_ME_WITH_ADMIN_USERNAME__" 2 | ADMIN_EMAIL="__REPLACE_ME_WITH_ADMIN_EMAIL__" 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # backup ssh keys 2 | backup/backup_key 3 | backup/backup_key.pub 4 | 5 | # generated ignition files 6 | *.json 7 | -------------------------------------------------------------------------------- /sysctl/99-vm-max-map-count.conf: -------------------------------------------------------------------------------- 1 | # Elasticsearch requires this to be 262144 or higher, 2 | # otherwise it refuses to start. 3 | 4 | vm.max_map_count=262144 5 | -------------------------------------------------------------------------------- /mastodon/versions.env: -------------------------------------------------------------------------------- 1 | MASTODON_IMAGE=tootsuite/mastodon:v3.5.3 2 | POSTGRES_IMAGE=postgres:14-alpine 3 | REDIS_IMAGE=redis:7-alpine 4 | ES_IMAGE=docker.elastic.co/elasticsearch/elasticsearch:7.17.4 5 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # CODEOWNERS file for flatcar-mastodon 2 | # This file defines who is responsible for code review 3 | # See: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners 4 | 5 | * @flatcar/flatcar-maintainers 6 | -------------------------------------------------------------------------------- /monitoring/grafana-datasources.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: 1 2 | 3 | datasources: 4 | - name: Prometheus 5 | type: prometheus 6 | access: proxy 7 | orgId: 1 8 | url: http://monitoring-prometheus:9090 9 | basicAuth: false 10 | isDefault: true 11 | editable: true 12 | -------------------------------------------------------------------------------- /systemd/clone-node.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Clone a remote mastodon node 3 | Requires=network-online.target 4 | After=docker.socket network-online.target 5 | 6 | [Service] 7 | Type=oneshot 8 | ExecStart=/opt/clone/clone-node.sh 9 | 10 | [Install] 11 | WantedBy=multi-user.target 12 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | We follow the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md). 4 | 5 | Please contact [private Maintainer mailing list](maintainers@flatcar-linux.org) or the Cloud Native Foundation mediator, conduct@cncf.io, to report an issue. -------------------------------------------------------------------------------- /monitoring/grafana-dashboards.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: 1 2 | 3 | providers: 4 | - name: 'Prometheus' 5 | orgId: 1 6 | folder: '' 7 | type: file 8 | disableDeletion: false 9 | editable: true 10 | allowUiUpdates: true 11 | options: 12 | path: /etc/grafana/provisioning/dashboards 13 | 14 | -------------------------------------------------------------------------------- /systemd/mastodon.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Mastodon umbrella service 3 | Requires=mastodon-sidekiq.service mastodon-web.service mastodon-streaming.service 4 | After=mastodon-sidekiq.service mastodon-web.service mastodon-streaming.service 5 | 6 | [Service] 7 | Type=oneshot 8 | RemainAfterExit=yes 9 | ExecStart=/usr/bin/true 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /systemd/mastodon-setup.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Mastodon first-time set-up and maintenance mode 3 | PartOf=mastodon.service 4 | Requires=mastodon-db.service mastodon-redis.service mastodon-es.service 5 | After=mastodon-db.service mastodon-redis.service mastodon-es.service 6 | 7 | [Service] 8 | Type=oneshot 9 | WorkingDirectory=/opt/mastodon 10 | ExecStart=/opt/mastodon/setup-mastodon.sh 11 | -------------------------------------------------------------------------------- /monitoring/monitoring-admin.env: -------------------------------------------------------------------------------- 1 | # DO NOT USE UNNECESSARY QUOTES around values. 2 | # This is a docker --env file and everything following the '=' will be used as value. 3 | # Quotes will end up IN the values, which can break things. 4 | 5 | # Grafana admin user to log in at https://${DOMAIN}/monitoring/ 6 | GF_SECURITY_ADMIN_USER=flatcar 7 | GF_SECURITY_ADMIN_PASSWORD=__REPLACE_ME_WITH_GRAFANA_ADM!N_PASSW0RD__ 8 | -------------------------------------------------------------------------------- /monitoring/monitoring-versions.env: -------------------------------------------------------------------------------- 1 | CADVISOR_IMAGE=gcr.io/cadvisor/cadvisor:v0.46.0 2 | ES_EXPORTER_IMAGE=prometheuscommunity/elasticsearch-exporter:v1.5.0 3 | MASTODON_EXPORTER_IMAGE=systemli/prometheus-mastodon-exporter:1.0 4 | NODEEXPORTER_IMAGE=prom/node-exporter:v1.3.1 5 | POSTGRES_EXPORTER_IMAGE=prometheuscommunity/postgres-exporter:v0.11.1 6 | REDIS_EXPORTER_IMAGE=oliver006/redis_exporter:v1.45.0 7 | SIDEKIQ_EXPORTER_IMAGE=ghcr.io/t-lo/sidekiq-prometheus-exporter:0.1.17.1 8 | 9 | PROMETHEUS_IMAGE=prom/prometheus:v2.40.1 10 | GRAFANA_IMAGE=grafana/grafana:9.2.4 11 | -------------------------------------------------------------------------------- /systemd/mastodon-net-external.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Mastodon external docker network 3 | PartOf=mastodon.service 4 | Requires=docker.socket 5 | After=docker.socket 6 | 7 | [Service] 8 | Type=oneshot 9 | RemainAfterExit=yes 10 | User=mastodon 11 | # Remove stale network from unclean shut-down. 12 | # It's OK if this fails (nothing to clean up), and we don't want the failure recorded. 13 | ExecStartPre=-/usr/bin/sh -c "/usr/bin/docker network rm mastodon-net-external || true" 14 | ExecStart=/usr/bin/docker network create --subnet 192.168.1.0/24 mastodon-net-external 15 | ExecStop=/usr/bin/docker network rm mastodon-net-external 16 | -------------------------------------------------------------------------------- /systemd/mastodon-net-internal.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Mastodon internal docker network 3 | PartOf=mastodon.service 4 | Requires=docker.socket 5 | After=docker.socket 6 | 7 | [Service] 8 | Type=oneshot 9 | RemainAfterExit=yes 10 | User=mastodon 11 | # Remove stale network from unclean shut-down. 12 | # It's OK if this fails (nothing to clean up), and we don't want the failure recorded. 13 | ExecStartPre=-/usr/bin/sh -c "/usr/bin/docker network rm mastodon-net-internal || true" 14 | ExecStart=/usr/bin/docker network create --internal --subnet 10.0.0.0/24 mastodon-net-internal 15 | ExecStop=/usr/bin/docker network rm mastodon-net-internal 16 | -------------------------------------------------------------------------------- /systemd/metrics-provider-es.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Elasticsearch prometheus metrics exporter 3 | Requires=mastodon-es.service 4 | After=mastodon-es.service 5 | 6 | [Service] 7 | EnvironmentFile=/opt/mastodon/monitoring-versions.env 8 | WorkingDirectory=/opt/mastodon 9 | User=mastodon 10 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 11 | --label "org.label-schema.group=monitoring" \ 12 | --name=metrics-provider-es \ 13 | ${ES_EXPORTER_IMAGE} \ 14 | --es.uri=http://mastodon-es:9200 15 | 16 | ExecStop=/usr/bin/docker stop metrics-provider-es 17 | 18 | [Install] 19 | WantedBy=multi-user.target 20 | -------------------------------------------------------------------------------- /systemd/mastodon-redis.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Redis for Mastodon 3 | PartOf=mastodon.service 4 | Requires=mastodon-net-internal.service 5 | After=mastodon-net-internal.service 6 | 7 | [Service] 8 | WorkingDirectory=/opt/mastodon 9 | User=mastodon 10 | EnvironmentFile=/opt/mastodon/versions.env 11 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 12 | --health-cmd="redis-cli ping" \ 13 | --volume=/opt/mastodon/redis:/data \ 14 | --name=mastodon-redis \ 15 | --hostname=mastodon-redis \ 16 | ${REDIS_IMAGE} 17 | ExecStartPost=/opt/mastodon/wait-for-container.sh mastodon-redis .State.Health healthy 18 | ExecStop=/usr/bin/docker stop mastodon-redis 19 | -------------------------------------------------------------------------------- /mastodon/wait-for-container.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Helper script to wait for a container to enter a certain state. 4 | # Used in systemd services to e.g. ensure containers running or health before continuing. 5 | 6 | set -euo pipefail 7 | 8 | container="$1" 9 | field="$2" 10 | condition="$3" 11 | timeout="${4:-300}" 12 | 13 | echo "Waiting max. ${timeout} seconds for '${container}' field '${field}' to become '${condition}'". 14 | 15 | start="$(date +%s)" 16 | until /usr/bin/docker inspect -f "{{${field}}}" "${container}" 2>/dev/null | grep -w "${condition}"; do 17 | sleep 0.1 18 | now="$(date +%s)" 19 | if [ $((now - start)) -gt "$timeout" ] ; then 20 | echo "Timeout after ${timeout} seconds waiting for '${container}' field '${field}' to become '${condition}'". >&2 21 | exit 1 22 | fi 23 | done 24 | -------------------------------------------------------------------------------- /systemd/metrics-provider-sidekiq.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Sidekiq prometheus metrics exporter 3 | # On first boot, mastodon-setup will need some time to create mastodon.env used below. 4 | Requires=mastodon-redis.service mastodon-setup.service 5 | After=mastodon-redis.service mastodon-setup.service 6 | 7 | [Service] 8 | WorkingDirectory=/opt/mastodon 9 | User=mastodon 10 | EnvironmentFile=/opt/mastodon/monitoring-versions.env 11 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 12 | --name=metrics-provider-sidekiq \ 13 | --label "org.label-schema.group=monitoring" \ 14 | --env-file="./mastodon.env" \ 15 | --env RACK_ENV="production" \ 16 | ${SIDEKIQ_EXPORTER_IMAGE} 17 | 18 | ExecStop=/usr/bin/docker stop metrics-provider-sidekiq 19 | 20 | [Install] 21 | WantedBy=multi-user.target 22 | -------------------------------------------------------------------------------- /systemd/mastodon-db.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Postgres DB for Mastodon 3 | PartOf=mastodon.service 4 | Requires=mastodon-net-internal.service 5 | After=mastodon-net-internal.service 6 | 7 | [Service] 8 | WorkingDirectory=/opt/mastodon 9 | User=mastodon 10 | EnvironmentFile=/opt/mastodon/versions.env 11 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 12 | --shm-size=256mb \ 13 | --health-cmd="pg_isready -U postgres" \ 14 | --env POSTGRES_HOST_AUTH_METHOD=trust \ 15 | --volume=/opt/mastodon/postgres:/var/lib/postgresql/data \ 16 | --name=mastodon-db \ 17 | --hostname=mastodon-db \ 18 | ${POSTGRES_IMAGE} 19 | ExecStartPost=/opt/mastodon/wait-for-container.sh mastodon-db .State.Health healthy 20 | ExecStop=/usr/bin/docker stop mastodon-db 21 | -------------------------------------------------------------------------------- /systemd/metrics-provider-redis.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Redis prometheus metrics exporter 3 | # On first boot, mastodon-setup will need some time to create mastodon.env used below. 4 | Requires=mastodon-redis.service mastodon-setup.service 5 | After=mastodon-redis.service mastodon-setup.service 6 | 7 | [Service] 8 | WorkingDirectory=/opt/mastodon 9 | User=mastodon 10 | EnvironmentFile=/opt/mastodon/monitoring-versions.env 11 | # To construct command line options 12 | EnvironmentFile=/opt/mastodon/mastodon.env 13 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 14 | --name=metrics-provider-redis \ 15 | --label "org.label-schema.group=monitoring" \ 16 | ${REDIS_EXPORTER_IMAGE} \ 17 | --redis.addr "${REDIS_HOST}:${REDIS_PORT}" --redis.password "${REDIS_PASSWORD}" 18 | 19 | ExecStop=/usr/bin/docker stop metrics-provider-redis 20 | 21 | [Install] 22 | WantedBy=multi-user.target 23 | -------------------------------------------------------------------------------- /systemd/metrics-provider-cadvisor.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=CAdvisor prometheus metrics exporter 3 | 4 | [Service] 5 | EnvironmentFile=/opt/mastodon/monitoring-versions.env 6 | ExecStart=/usr/bin/docker run --rm --privileged \ 7 | --name metrics-provider-cadvisor \ 8 | --device /dev/kmsg:/dev/kmsg \ 9 | --volume /:/rootfs:ro \ 10 | --volume /var/run:/var/run:ro \ 11 | --volume /sys:/sys:ro \ 12 | --volume /var/lib/docker:/var/lib/docker:ro \ 13 | --volume /cgroup:/cgroup:ro \ 14 | --label "org.label-schema.group=monitoring" \ 15 | --net host \ 16 | --add-host host.docker.internal:host-gateway \ 17 | ${CADVISOR_IMAGE} \ 18 | --listen_ip=host.docker.internal --port=9101 19 | ExecStop=/usr/bin/docker stop metrics-provider-cadvisor 20 | 21 | [Install] 22 | WantedBy=multi-user.target 23 | -------------------------------------------------------------------------------- /systemd/metrics-provider-mastodon.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Mastodon prometheus metrics exporter 3 | Requires=mastodon-web.service 4 | After=mastodon-web.service 5 | 6 | [Service] 7 | WorkingDirectory=/opt/mastodon 8 | User=mastodon 9 | EnvironmentFile=/opt/mastodon/monitoring-versions.env 10 | EnvironmentFile=/opt/mastodon/mastodon.env 11 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 12 | --name=metrics-provider-mastodon \ 13 | --label "org.label-schema.group=monitoring" \ 14 | ${MASTODON_EXPORTER_IMAGE} \ 15 | -mastodon-url=https://${LOCAL_DOMAIN} \ 16 | -web.listen-address :9102 17 | ExecStartPost=/opt/mastodon/wait-for-container.sh metrics-provider-mastodon .State.Status running 18 | ExecStartPost=/usr/bin/docker network connect mastodon-net-external metrics-provider-mastodon 19 | 20 | ExecStop=/usr/bin/docker stop metrics-provider-mastodon 21 | 22 | [Install] 23 | WantedBy=multi-user.target 24 | -------------------------------------------------------------------------------- /backup/clone-node.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | 6 | clone_basedir="/opt/clone" 7 | remote_backup_basedir="/opt/backup" 8 | 9 | clone_lockdir="${clone_basedir}/.lock" 10 | 11 | if ! mkdir "${clone_lockdir}"; then 12 | echo "Failed to acquire lock dir '${clone_lockdir}' - did a previous clone attempt fail?" 13 | exit 1 14 | fi 15 | 16 | remote_address="$(cat "$clone_basedir/source_node")" 17 | 18 | remote=("ssh" 19 | "-o" "UserKnownHostsFile=/dev/null" 20 | "-o" "StrictHostKeyChecking=no" 21 | "-i" "${clone_basedir}/.ssh/backup_key" 22 | "${remote_address}" 23 | "sudo") 24 | 25 | echo "Fetching backup." 26 | "${remote[@]}" "${remote_backup_basedir}"/backup_client.sh \ 27 | | docker run --rm -i ghcr.io/flatcar/pigz:latest -d -c - \ 28 | | tar x --directory / 29 | 30 | echo "Re-initialising system" 31 | "${clone_basedir}/re_initialise.sh" 32 | 33 | # Remove backup private SSH keyfile. Not necessary any more. 34 | rm -rf "${clone_basedir}/.ssh" 35 | 36 | echo "Disabling clone-node service" 37 | systemctl disable clone-node.service 38 | -------------------------------------------------------------------------------- /systemd/metrics-provider-nodeexporter.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=NodeExporter prometheus metrics exporter 3 | 4 | [Service] 5 | EnvironmentFile=/opt/mastodon/monitoring-versions.env 6 | ExecStart=/usr/bin/docker run --rm \ 7 | --name metrics-provider-nodeexporter \ 8 | --volume /:/rootfs:ro \ 9 | --volume /sys:/host/sys:ro \ 10 | --volume /proc:/host/proc:ro \ 11 | --label "org.label-schema.group=monitoring" \ 12 | --net host \ 13 | --add-host host.docker.internal:host-gateway \ 14 | ${NODEEXPORTER_IMAGE} \ 15 | --path.procfs=/host/proc \ 16 | --path.rootfs=/rootfs \ 17 | --path.sysfs=/host/sys \ 18 | --collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/) \ 19 | --web.listen-address=host.docker.internal:9100 20 | 21 | ExecStop=/usr/bin/docker stop metrics-provider-cadvisor 22 | 23 | [Install] 24 | WantedBy=multi-user.target 25 | -------------------------------------------------------------------------------- /backup/backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Back up an instance and store the data in the local directory. 4 | # 5 | # NOTE that to prevent inconsistent data, the MASTODON SERVICE WILL BE STOPPED for the duration of the backup. 6 | # 7 | # Backup can run either locally or remote. To run locally, start this script without options. 8 | # 9 | # For remote mode, which uses scp/ssh, supply "user@remote_host" and a private key file as first and second argument. 10 | 11 | set -euo pipefail 12 | backup_basedir="/opt/backup" 13 | 14 | remote=() 15 | 16 | if [ "$#" -gt 0 ] ; then 17 | if [ -n "${1:-}" -a -s "${2:-}" ] ; then 18 | remote=( ssh -i "${2}" "${1}" ) 19 | echo "Backing up from remote via '${remote[*]}'" 20 | remote+=( sudo ) 21 | else 22 | echo "Error parsing command line arguments." 23 | echo "Usage: $0 " 24 | fi 25 | else 26 | echo "Backing up from local host" 27 | fi 28 | 29 | ts="$(date --rfc-3339=seconds | sed -e 's/[ :]/_/g' -e 's/+.*//')" 30 | fname="mastodon-backup-${ts}.tgz" 31 | 32 | echo "Pulling backup '${fname}'." 33 | "${remote[@]}" "${backup_basedir}"/backup_client.sh > "${fname}" 34 | 35 | echo "Done" 36 | -------------------------------------------------------------------------------- /mastodon/mastodon.env.template: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT USE UNNECESSARY QUOTES around values. 3 | # This is a docker --env file and everything following the '=' will be used as value. 4 | # Quotes will end up IN the values, which can break things. 5 | # 6 | 7 | LOCAL_DOMAIN=__REPLACE_ME_WITH_DOMAIN__ 8 | VIRTUAL_HOST=__REPLACE_ME_WITH_DOMAIN__ 9 | 10 | SMTP_FROM_ADDRESS="__REPLACE_ME_WITH_MASTODON_NOTIFICATIONS_DISPLAY_NAME__" <__REPLACE_ME_WITH_MASTODON_NOTIFICATIONS_EMAIL__> 11 | SMTP_SERVER=__REPLACE_ME_WITH_MASTODON_NOTIFICATIONS_SMTP_SERVER__ 12 | SMTP_PORT=__REPLACE_ME_WITH_MASTODON_NOTIFICATIONS_SMTP_SERVER_PORT__ 13 | SMTP_LOGIN=__REPLACE_ME_WITH_MASTODON_NOTIFICATIONS_SMTP_USER__ 14 | SMTP_PASSWORD=__REPLACE_ME_WITH_MASTODON_NOTIFICATIONS_SMTP_PASSWORD__ 15 | 16 | # These might need changing depending on the SMTP server you're using 17 | SMTP_AUTH_METHOD=plain 18 | SMTP_OPENSSL_VERIFY_MODE=peer 19 | 20 | 21 | # These defaults can largely remain untouched 22 | DEFAULT_LOCALE=en 23 | SINGLE_USER_MODE=false 24 | DB_HOST=mastodon-db 25 | DB_PORT=5432 26 | DB_NAME=postgres 27 | DB_USER=postgres 28 | DB_PASS= 29 | REDIS_HOST=mastodon-redis 30 | REDIS_PORT=6379 31 | REDIS_PASSWORD= 32 | ES_HOST=mastodon-es 33 | ES_ENABLED=true 34 | -------------------------------------------------------------------------------- /systemd/caddy.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Caddy web server front-end and HTTPS termination for Mastodon 3 | # On first boot, mastodon-setup will need some time to create mastodon.env used below. 4 | Requires=mastodon-net-external.service mastodon-setup.service 5 | After=mastodon-net-external.service mastodon-setup.service 6 | 7 | [Service] 8 | WorkingDirectory=/opt/caddy 9 | User=www 10 | # for LOCAL_DOMAIN 11 | EnvironmentFile=/opt/mastodon/mastodon.env 12 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-external \ 13 | --volume=/opt/caddy/etc:/etc/caddy \ 14 | --volume=/opt/caddy/logs:/logs \ 15 | --volume=/opt/caddy/data:/data \ 16 | --volume=/opt/caddy/config:/config \ 17 | --volume=/opt/mastodon/public:/srv/mastodon/public \ 18 | --hostname="${LOCAL_DOMAIN}" \ 19 | --name=caddy-webserver \ 20 | -p 80:80 \ 21 | -p 443:443 \ 22 | caddy:2-alpine 23 | ExecStop=/usr/bin/docker stop caddy-webserver 24 | 25 | [Install] 26 | WantedBy=multi-user.target 27 | -------------------------------------------------------------------------------- /systemd/metrics-provider-postgres.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=PostgreSQL prometheus metrics exporter 3 | # On first boot, mastodon-setup will need some time to create mastodon.env used below. 4 | Requires=mastodon-db.service mastodon-setup.service 5 | After=mastodon-db.service mastodon-setup.service 6 | 7 | [Service] 8 | WorkingDirectory=/opt/mastodon 9 | User=mastodon 10 | EnvironmentFile=/opt/mastodon/monitoring-versions.env 11 | # To construct DATA_SOURCE_NAME 12 | EnvironmentFile=/opt/mastodon/mastodon.env 13 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 14 | --name=metrics-provider-postgres \ 15 | --volume=/opt/mastodon/postgres-monitoring-queries.yaml:/postgres-monitoring-queries.yaml \ 16 | --label "org.label-schema.group=monitoring" \ 17 | --env DATA_SOURCE_NAME="postgresql://${DB_USER}:${DB_PASS}@mastodon-db:${DB_PORT}/postgres?sslmode=disable" \ 18 | --env PG_EXPORTER_EXTEND_QUERY_PATH=/postgres-monitoring-queries.yaml \ 19 | prometheuscommunity/postgres-exporter:v0.11.1 20 | 21 | ExecStop=/usr/bin/docker stop metrics-provider-postgres 22 | 23 | [Install] 24 | WantedBy=multi-user.target 25 | -------------------------------------------------------------------------------- /systemd/mastodon-sidekiq.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Mastodon Sidekiq 3 | PartOf=mastodon.service 4 | Requires=mastodon-db.service mastodon-redis.service mastodon-es.service mastodon-net-external.service mastodon-setup.service 5 | After=mastodon-db.service mastodon-redis.service mastodon-es.service mastodon-net-external.service mastodon-setup.service 6 | 7 | [Service] 8 | WorkingDirectory=/opt/mastodon 9 | User=mastodon 10 | EnvironmentFile=/opt/mastodon/versions.env 11 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 12 | --health-cmd="wget -q --spider --proxy=off localhost:5050/health || exit 1" \ 13 | --volume=/opt/mastodon/public:/mastodon/public/system \ 14 | --env VIRTUAL_PATH="/" \ 15 | --env VIRTUAL_PORT="5050" \ 16 | --env-file="./mastodon.env" \ 17 | --name=mastodon-sidekiq \ 18 | --hostname=mastodon-sidekiq \ 19 | ${MASTODON_IMAGE} \ 20 | bundle exec sidekiq 21 | ExecStartPost=/opt/mastodon/wait-for-container.sh mastodon-sidekiq .State.Status running 22 | ExecStartPost=/usr/bin/docker network connect mastodon-net-external mastodon-sidekiq 23 | ExecStop=/usr/bin/docker stop mastodon-sidekiq 24 | -------------------------------------------------------------------------------- /monitoring/prometheus.yaml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | evaluation_interval: 15s 4 | 5 | scrape_configs: 6 | - job_name: 'cadvisor' 7 | scrape_interval: 5s 8 | static_configs: 9 | - targets: ['host.docker.internal:9101'] 10 | 11 | - job_name: 'mastodon_es' 12 | scrape_interval: 5s 13 | static_configs: 14 | - targets: ['metrics-provider-es:9114'] 15 | 16 | - job_name: 'mastodon_metrics' 17 | scrape_interval: 10s 18 | honor_labels: true 19 | static_configs: 20 | - targets: ['metrics-provider-mastodon:9102'] 21 | 22 | - job_name: 'nodeexporter' 23 | scrape_interval: 5s 24 | static_configs: 25 | - targets: ['host.docker.internal:9100'] 26 | 27 | - job_name: 'mastodon_postgres' 28 | scrape_interval: 5s 29 | static_configs: 30 | - targets: ['metrics-provider-postgres:9187'] 31 | 32 | - job_name: 'mastodon_redis' 33 | scrape_interval: 5s 34 | static_configs: 35 | - targets: ['metrics-provider-redis:9121'] 36 | 37 | - job_name: 'mastodon_sidekiq' 38 | scrape_interval: 5s 39 | static_configs: 40 | - targets: ['metrics-provider-sidekiq:9292'] 41 | 42 | - job_name: 'prometheus' 43 | scrape_interval: 10s 44 | static_configs: 45 | - targets: ['localhost:9090'] 46 | 47 | - job_name: 'caddy' 48 | scrape_interval: 10s 49 | static_configs: 50 | - targets: ['caddy-webserver:2019'] 51 | -------------------------------------------------------------------------------- /systemd/mastodon-web.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Mastodon Web frontend 3 | PartOf=mastodon.service 4 | Requires=mastodon-db.service mastodon-redis.service mastodon-es.service mastodon-net-external.service mastodon-setup.service 5 | After=mastodon-db.service mastodon-redis.service mastodon-es.service mastodon-net-external.service mastodon-setup.service 6 | 7 | [Service] 8 | WorkingDirectory=/opt/mastodon 9 | User=mastodon 10 | EnvironmentFile=/opt/mastodon/versions.env 11 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 12 | --health-cmd="wget -q --spider --proxy=off localhost:5050/health || exit 1" \ 13 | --volume=/opt/mastodon/public:/mastodon/public/system \ 14 | --env VIRTUAL_PATH="/" \ 15 | --env VIRTUAL_PORT="5050" \ 16 | --env-file="./mastodon.env" \ 17 | --name=mastodon-web \ 18 | --env ALTERNATE_DOMAINS=mastodon-web \ 19 | -p 127.0.0.1:5050:5050 \ 20 | ${MASTODON_IMAGE} \ 21 | bundle exec rails s -p 5050 22 | ExecStartPost=/opt/mastodon/wait-for-container.sh mastodon-web .State.Status running 23 | ExecStartPost=/usr/bin/docker network connect mastodon-net-external mastodon-web 24 | ExecStop=/usr/bin/docker stop mastodon-web 25 | -------------------------------------------------------------------------------- /systemd/mastodon-streaming.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Mastodon Web streaming 3 | PartOf=mastodon.service 4 | Requires=mastodon-db.service mastodon-redis.service mastodon-es.service mastodon-net-external.service mastodon-setup.service 5 | After=mastodon-db.service mastodon-redis.service mastodon-es.service mastodon-net-external.service mastodon-setup.service 6 | 7 | [Service] 8 | WorkingDirectory=/opt/mastodon 9 | User=mastodon 10 | EnvironmentFile=/opt/mastodon/versions.env 11 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 12 | --health-cmd="wget -q --spider --proxy=off localhost:5051/api/v1/streaming/health || exit 1" \ 13 | --volume=/opt/mastodon/public:/mastodon/public/system \ 14 | --env VIRTUAL_PATH="/api/v1/streaming" \ 15 | --env VIRTUAL_PORT="5051" \ 16 | --env PORT="5051" \ 17 | --env-file="./mastodon.env" \ 18 | --name=mastodon-streaming \ 19 | --hostname=mastodon-streaming \ 20 | -p 127.0.0.1:5051:5051 \ 21 | ${MASTODON_IMAGE} \ 22 | node ./streaming 23 | ExecStartPost=/opt/mastodon/wait-for-container.sh mastodon-streaming .State.Status running 24 | ExecStartPost=/usr/bin/docker network connect mastodon-net-external mastodon-streaming 25 | ExecStop=/usr/bin/docker stop mastodon-streaming 26 | -------------------------------------------------------------------------------- /systemd/monitoring-prometheus.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Prometheus metrics scraper and time series db 3 | Requires=mastodon-net-internal.service mastodon-net-external.service 4 | After=mastodon-net-internal.service mastodon-net-external.service 5 | 6 | [Service] 7 | WorkingDirectory=/opt/mastodon 8 | User=mastodon 9 | EnvironmentFile=/opt/mastodon/monitoring-versions.env 10 | ExecStartPre=+/usr/bin/chown -R 65534 ./prometheus 11 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 12 | --volume=/opt/mastodon/prometheus/etc:/etc/prometheus \ 13 | --volume=/opt/mastodon/prometheus/data:/prometheus \ 14 | --name=monitoring-prometheus \ 15 | --label "org.label-schema.group=monitoring" \ 16 | --add-host host.docker.internal:host-gateway \ 17 | ${PROMETHEUS_IMAGE} \ 18 | --config.file=/etc/prometheus/prometheus.yaml \ 19 | --storage.tsdb.path=/prometheus \ 20 | --web.console.libraries=/etc/prometheus/console_libraries \ 21 | --web.console.templates=/etc/prometheus/consoles \ 22 | --storage.tsdb.retention.time=200h \ 23 | --web.enable-lifecycle 24 | ExecStartPost=/opt/mastodon/wait-for-container.sh monitoring-prometheus .State.Status running 25 | ExecStartPost=/usr/bin/docker network connect mastodon-net-external monitoring-prometheus 26 | 27 | ExecStop=/usr/bin/docker stop monitoring-prometheus 28 | 29 | [Install] 30 | WantedBy=multi-user.target 31 | -------------------------------------------------------------------------------- /systemd/monitoring-grafana.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Grafana monitoring dashboards service 3 | # On first boot, mastodon-setup will need some time to create mastodon.env used below. 4 | Requires=mastodon-net-internal.service mastodon-net-external.service mastodon-setup.service 5 | After=mastodon-net-internal.service mastodon-net-external.service mastodon-setup.service 6 | 7 | [Service] 8 | WorkingDirectory=/opt/mastodon 9 | User=mastodon 10 | EnvironmentFile=/opt/mastodon/monitoring-versions.env 11 | EnvironmentFile=/opt/mastodon/monitoring-admin.env 12 | # for LOCAL_DOMAIN 13 | EnvironmentFile=/opt/mastodon/mastodon.env 14 | ExecStartPre=+/usr/bin/chown -R 472 ./grafana 15 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 16 | --volume=/opt/mastodon/grafana/data:/var/lib/grafana \ 17 | --volume=/opt/mastodon/grafana/dashboards:/etc/grafana/provisioning/dashboards \ 18 | --volume=/opt/mastodon/grafana/datasources:/etc/grafana/provisioning/datasources \ 19 | --name=monitoring-grafana \ 20 | --label "org.label-schema.group=monitoring" \ 21 | --env-file /opt/mastodon/monitoring-admin.env \ 22 | --env GF_SERVER_DOMAIN="${LOCAL_DOMAIN}" \ 23 | --env GF_SERVER_ROOT_URL="https://%(domain)s/monitoring/" \ 24 | --env GF_SERVER_SERVE_FROM_SUBPATH="true" \ 25 | ${GRAFANA_IMAGE} 26 | ExecStartPost=/opt/mastodon/wait-for-container.sh monitoring-grafana .State.Status running 27 | ExecStartPost=/usr/bin/docker network connect mastodon-net-external monitoring-grafana 28 | 29 | ExecStop=/usr/bin/docker stop monitoring-grafana 30 | 31 | [Install] 32 | WantedBy=multi-user.target 33 | -------------------------------------------------------------------------------- /caddy/Caddyfile: -------------------------------------------------------------------------------- 1 | { 2 | email __REPLACE_ME_WITH_WEBMASTER_EMAIL__ 3 | 4 | admin 0.0.0.0:2019 5 | servers { 6 | metrics 7 | } 8 | 9 | } 10 | 11 | __REPLACE_ME_WITH_DOMAIN__ { 12 | log { 13 | output file /logs/access.log 14 | } 15 | 16 | root * /srv/mastodon/public 17 | 18 | encode gzip 19 | 20 | @static file 21 | 22 | handle @static { 23 | file_server 24 | } 25 | 26 | handle /monitoring/* { 27 | uri strip_prefix /monitoring 28 | reverse_proxy monitoring-grafana:3000 { 29 | header_up Host {host} 30 | header_up X-Forwarded-Proto https 31 | header_up X-Real-IP {remote_host} 32 | } 33 | } 34 | 35 | handle /api/v1/streaming* { 36 | reverse_proxy mastodon-streaming:5051 { 37 | header_up X-Forwarded-Proto https 38 | } 39 | } 40 | 41 | handle { 42 | reverse_proxy mastodon-web:5050 { 43 | header_up X-Forwarded-Proto https 44 | } 45 | } 46 | 47 | header { 48 | Strict-Transport-Security "max-age=31536000;" 49 | } 50 | 51 | header /sw.js Cache-Control "public, max-age=0"; 52 | header /emoji* Cache-Control "public, max-age=31536000, immutable" 53 | header /packs* Cache-Control "public, max-age=31536000, immutable" 54 | header /system/accounts/avatars* Cache-Control "public, max-age=31536000, immutable" 55 | header /system/media_attachments/files* Cache-Control "public, max-age=31536000, immutable" 56 | 57 | handle_errors { 58 | @5xx expression `{http.error.status_code} >= 500 && {http.error.status_code} < 600` 59 | rewrite @5xx /500.html 60 | file_server 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /clone-node.yaml: -------------------------------------------------------------------------------- 1 | variant: flatcar 2 | version: 1.0.0 3 | 4 | passwd: 5 | users: 6 | - name: www 7 | no_create_home: true 8 | groups: [ docker ] 9 | - name: mastodon 10 | no_create_home: true 11 | groups: [ docker ] 12 | - name: backup 13 | 14 | storage: 15 | directories: 16 | # Restore scripts and secrets 17 | - path: /opt/clone 18 | mode: 0700 19 | - path: /opt/clone/.ssh 20 | mode: 0700 21 | # Postgres directory is not in backup because db is backed up via SQL dump 22 | - path: /opt/mastodon/postgres 23 | mode: 0755 24 | user: 25 | name: mastodon 26 | group: 27 | name: mastodon 28 | 29 | files: 30 | - path: /etc/sysctl.d/99-vm-max-map-count.conf 31 | mode: 0644 32 | contents: 33 | local: sysctl/99-vm-max-map-count.conf 34 | # Restore scripts and secrets 35 | - path: /opt/clone/.ssh/backup_key 36 | mode: 0400 37 | contents: 38 | local: backup/backup_key 39 | - path: /opt/clone/clone-node.sh 40 | mode: 0500 41 | contents: 42 | local: backup/clone-node.sh 43 | - path: /opt/clone/re_initialise.sh 44 | mode: 0500 45 | contents: 46 | local: backup/re_initialise.sh 47 | - path: /opt/clone/source_node 48 | mode: 0400 49 | contents: 50 | # Replace BACKUPUSER@HOST with backup user name and host (domain or IP address) 51 | # of the source node. 52 | inline: | 53 | BACKUPUSER@HOST 54 | - path: /etc/systemd/system/clone-node.service 55 | mode: 0644 56 | contents: 57 | local: systemd/clone-node.service 58 | 59 | # backup user sudo access and pubkey 60 | - path: /etc/sudoers.d/backup 61 | mode: 0440 62 | contents: 63 | local: backup/sudoers 64 | - path: /home/backup/.ssh/authorized_keys 65 | mode: 0444 66 | contents: 67 | local: backup/backup_key.pub 68 | user: 69 | name: backup 70 | 71 | systemd: 72 | units: 73 | - name: clone-node.service 74 | enabled: true 75 | -------------------------------------------------------------------------------- /backup/re_initialise.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # (Re-)initialise a system from a backup that has been dumped into the root tree. 4 | 5 | chown mastodon:mastodon /opt/mastodon/mastodon.env 6 | 7 | source /opt/mastodon/versions.env 8 | chmod 0444 /opt/backup/mastodon_db_backup.sql 9 | 10 | # We start the DB container to import the backup SQL dump. 11 | # Note that the container's health check will not succeed until after the dump was imported. 12 | echo "Importing mastodon database" 13 | # We run this in the background instead of using --detach so the log output remains visible 14 | /usr/bin/docker run --rm \ 15 | --shm-size=256mb \ 16 | --health-cmd="pg_isready -U postgres" \ 17 | --env POSTGRES_HOST_AUTH_METHOD=trust \ 18 | --volume=/opt/backup/mastodon_db_backup.sql:/docker-entrypoint-initdb.d/mastodon_db.sql \ 19 | --volume=/opt/mastodon/postgres:/var/lib/postgresql/data \ 20 | --name=mastodon-db-import \ 21 | "${POSTGRES_IMAGE}" & 22 | 23 | # 20 minutes max for db import. The DB container can be shut down as soon as the DB is up (healthy) 24 | # as the SQL import happens before the DB is started in the container. 25 | /opt/mastodon/wait-for-container.sh mastodon-db-import .State.Health healthy 1200 26 | /usr/bin/docker stop mastodon-db-import 27 | 28 | rm /opt/backup/mastodon_db_backup.sql 29 | 30 | echo "Enabling mastodon and monitoring service units" 31 | systemctl daemon-reload 32 | 33 | for f in /etc/systemd/system/mastodon* \ 34 | /etc/systemd/system/metrics-provider* \ 35 | /etc/systemd/system/monitoring* \ 36 | /etc/systemd/system/caddy* ; do 37 | 38 | if ! grep -q '\[Install\]' "${f}"; then 39 | # Some services are pulled in by other services and do not need installation. 40 | continue 41 | fi 42 | 43 | u="$(basename "$f")" 44 | systemctl enable "$u" 45 | done 46 | 47 | echo "Starting mastodon, monitoring, and web server" 48 | systemctl start --all "mastodon*" "monitoring-*" "metrics-provider-*" caddy 49 | -------------------------------------------------------------------------------- /systemd/mastodon-es.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Elasticsearch for Mastodon 3 | PartOf=mastodon.service 4 | Requires=mastodon-net-internal.service 5 | After=mastodon-net-internal.service 6 | 7 | [Service] 8 | WorkingDirectory=/opt/mastodon 9 | User=mastodon 10 | EnvironmentFile=/opt/mastodon/versions.env 11 | ExecStartPre=+/usr/bin/rm -f elasticsearch/nodes/*/node.lock 12 | ExecStartPre=+/usr/bin/chown -R 1000:1001 ./elasticsearch 13 | # Most parameters are taken from Mastodon upstream docker-compose: https://github.com/mastodon/mastodon/blob/main/docker-compose.yml#L26 14 | # ingest.geoip.downloader.enabled=false is from https://discuss.elastic.co/t/how-to-disable-geoip-usage-in-7-14-0/281076 15 | # and disables downloading geoip data on start. ES container uses internal networking only, with no outside connectivity at all. 16 | ExecStart=/usr/bin/docker run --rm --network=mastodon-net-internal \ 17 | --health-cmd="curl --silent --fail localhost:9200/_cluster/health || exit 1" \ 18 | --volume=/opt/mastodon/elasticsearch:/usr/share/elasticsearch/data \ 19 | --env ES_JAVA_OPTS="-Xms512m -Xmx512m -Des.enforce.bootstrap.checks=true" \ 20 | --env bootstrap.memory_lock=true \ 21 | --env xpack.license.self_generated.type=basic \ 22 | --env xpack.security.enabled=false \ 23 | --env xpack.watcher.enabled=false \ 24 | --env xpack.graph.enabled=false \ 25 | --env xpack.ml.enabled=false \ 26 | --env ingest.geoip.downloader.enabled=false \ 27 | --env cluster.name=es-mastodon \ 28 | --env discovery.type=single-node \ 29 | --env thread_pool.write.queue_size=1000 \ 30 | --ulimit memlock=-1:-1 \ 31 | --ulimit nofile=65536:65536 \ 32 | --name=mastodon-es \ 33 | --hostname=mastodon-es \ 34 | ${ES_IMAGE} 35 | ExecStartPost=/opt/mastodon/wait-for-container.sh mastodon-es .State.Health healthy 36 | ExecStop=/usr/bin/docker stop mastodon-es 37 | -------------------------------------------------------------------------------- /backup/backup_client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | if [ "${1:-}" = "backup-db" ] ; then 6 | PGPASSWORD="${DB_PASS}" pg_dump -h "${DB_HOST}" -p "${DB_PORT}" -U "${DB_USER}" 7 | exit 8 | fi 9 | 10 | caddy_paths=("/opt/caddy") 11 | 12 | mastodon_paths=("/opt/mastodon/public" 13 | "/opt/mastodon/elasticsearch" 14 | "/opt/mastodon/redis" 15 | "/opt/mastodon/mastodon.env" 16 | "/opt/mastodon/versions.env") 17 | 18 | monitoring_paths=("/opt/mastodon/grafana" 19 | "/opt/mastodon/prometheus" 20 | "/opt/mastodon/monitoring-versions.env" 21 | "/opt/mastodon/monitoring-admin.env" 22 | "/opt/mastodon/postgres-monitoring-queries.yaml") 23 | 24 | extra_paths=("/opt/backup" 25 | "/opt/mastodon/wait-for-container.sh" 26 | "/opt/mastodon/setup-mastodon.sh") 27 | 28 | service_wildcards=("/etc/systemd/system/mastodon*" 29 | "/etc/systemd/system/monitoring-*" 30 | "/etc/systemd/system/metrics-provider-*" 31 | "/etc/systemd/system/caddy*.service") 32 | 33 | source /opt/mastodon/versions.env 34 | 35 | echo "CLIENT: Stopping mastodon and monitoring services" >&2 36 | trap 'systemctl start --all "mastodon*" "monitoring*" "metrics*" caddy' EXIT 37 | systemctl stop "mastodon*" "monitoring*" "metrics*" caddy 38 | 39 | echo "CLIENT: Creating DB snapshot" >&2 40 | f=$(mktemp) 41 | mv "$f" /opt/backup/mastodon_db_backup.sql 42 | 43 | systemctl start mastodon-db 44 | 45 | docker run --rm --env-file /opt/mastodon/mastodon.env \ 46 | -v /opt/backup/backup_client.sh:/backup_client.sh \ 47 | --network=mastodon-net-internal "${POSTGRES_IMAGE}" \ 48 | /backup_client.sh backup-db >>/opt/backup/mastodon_db_backup.sql 49 | 50 | systemctl stop mastodon-db 51 | 52 | echo "CLIENT: Transmitting data" >&2 53 | shopt -s nullglob 54 | tar -pc ${caddy_paths[@]} ${mastodon_paths[@]} ${monitoring_paths[@]} ${extra_paths[@]} ${service_wildcards[@]} | docker run --rm -i ghcr.io/flatcar/pigz:latest -c 55 | 56 | trap '' EXIT 57 | echo "CLIENT: Starting mastodon and monitoring services" >&2 58 | systemctl start --all "mastodon*" "monitoring*" "metrics*" caddy 59 | -------------------------------------------------------------------------------- /backup/restore.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | this_script="/opt/backup/restore.sh" 4 | 5 | set -euo pipefail 6 | 7 | backup_file="${1:-}" 8 | 9 | if [ ! -f "${backup_file}" ] ; then 10 | echo "ERROR: missing backup tarball file." 11 | echo "Usage: $0 " 12 | echo " - backup created with 'backup.sh'" 13 | echo 14 | exit 1 15 | fi 16 | 17 | # Only sith lords and backup files deal in absolutes. 18 | backup_file="$(realpath "${backup_file}")" 19 | 20 | if [[ "${backup_file}" == /opt/mastodon/* ]] \ 21 | || [[ "${backup_file}" == /opt/backup/* ]] \ 22 | || [[ "${backup_file}" == /opt/caddy/* ]] ; then 23 | echo "ERROR: backup file '${backup_file}' resides in a path that wiĺl be WIPED!" 24 | echo " Move outside /opt/mastodon, /opt/backup, or /opt/caddy and try again." 25 | echo 26 | exit 1 27 | fi 28 | 29 | 30 | reinit_script="/opt/backup/re_initialise.sh" 31 | 32 | if [ "$(realpath "$0")" = "$this_script" ] ; then 33 | # The wiping below will also remove this very script, so we create a tempfile to run from. 34 | tmp_restore_script="$(mktemp)" 35 | chmod 700 "${tmp_restore_script}" 36 | cat "${this_script}" >> "${tmp_restore_script}" 37 | echo "Moving to tempfile '${tmp_restore_script}'" 38 | exec "${tmp_restore_script}" "${@}" 39 | fi 40 | 41 | trap "rm -f '${0}'" EXIT 42 | 43 | if [ ! -f "${reinit_script}" ] ; then 44 | echo "INTERNAL ERROR: re-init script not present." 45 | exit 2 46 | fi 47 | 48 | tmp_reinit_script="$(mktemp)" 49 | chmod 700 "${tmp_reinit_script}" 50 | cat "${reinit_script}" >> "${tmp_reinit_script}" 51 | 52 | trap "rm -f '${0}' '${tmp_reinit_script}'" EXIT 53 | 54 | echo "Stopping and disabling all mastodon, monitoring and web services, and wiping service files." 55 | 56 | systemctl stop "mastodon*" "metrics-provider-*" "monitoring*" "caddy*" 57 | 58 | for f in /etc/systemd/system/mastodon* \ 59 | /etc/systemd/system/metrics-provider* \ 60 | /etc/systemd/system/monitoring* \ 61 | /etc/systemd/system/caddy* ; do 62 | u="$(basename "$f")" 63 | # Sadly, "disable" does not support globbing like "start" and "stop" do 64 | systemctl disable "$u" 65 | done 66 | 67 | rm -f /etc/systemd/system/mastodon* /etc/systemd/system/metrics-provider-* /etc/systemd/system/monitoring* /etc/systemd/system/caddy* 68 | 69 | echo "Removing mastodon, web server, and metrics data." 70 | rm -rf /opt/mastodon/ /opt/caddy/ /opt/backup/ 71 | 72 | echo "Restoring backup from '${backup_file}'" 73 | cat "${backup_file}" | docker run --rm -i ghcr.io/flatcar/pigz:latest -d -c - \ 74 | | tar x --directory / 75 | 76 | echo "Re-initialising system" 77 | "${tmp_reinit_script}" 78 | -------------------------------------------------------------------------------- /mastodon/setup-mastodon.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | if [ -f ./mastodon.env ] ; then 6 | echo "Mastodon already initialised, nothing to do." 7 | exit 0 8 | fi 9 | 10 | # Get image versions, admin account 11 | source ./versions.env 12 | source ./admin.env 13 | 14 | echo "Starting first-time set-up." 15 | 16 | temp_cfg=$(mktemp) 17 | chmod 600 "${temp_cfg}" 18 | cat ./mastodon.env.template >> "${temp_cfg}" 19 | 20 | echo "Generating keys and secrets." 21 | 22 | secret="$(docker run -i --network mastodon-net-internal --rm -e RUBYOPT=-W0 \ 23 | ${MASTODON_IMAGE} bundle exec rake secret)" 24 | echo "SECRET_KEY_BASE=${secret}" >> "${temp_cfg}" 25 | 26 | secret="$(docker run -i --network mastodon-net-internal --rm -e RUBYOPT=-W0 \ 27 | "${MASTODON_IMAGE}" bundle exec rake secret)" 28 | echo "OTP_SECRET=${secret}" >> "${temp_cfg}" 29 | docker run -i --network mastodon-net-internal --rm -e RUBYOPT=-W0 \ 30 | ${MASTODON_IMAGE} bundle exec rake mastodon:webpush:generate_vapid_key \ 31 | >> "${temp_cfg}" 32 | 33 | 34 | echo "Initialising the database." 35 | docker run -i --network mastodon-net-internal --rm --env-file "${temp_cfg}" \ 36 | -e RUBYOPT=-W0 -e DISABLE_DATABASE_ENVIRONMENT_CHECK=1 ${MASTODON_IMAGE} \ 37 | bundle exec rake db:setup 38 | 39 | echo "Creating admin user $ADMIN_USER w/ email $ADMIN_EMAIL" 40 | 41 | out="$(mktemp)" 42 | # Setting the hostname to the domain of the admin user's email works around a tootctl DNS check issue. 43 | # See https://github.com/mastodon/mastodon/issues/15850 for details. 44 | admin_email_domain="$(echo "${ADMIN_EMAIL}" | sed 's/.*@//')" 45 | docker run -i --network mastodon-net-internal --rm --env-file "${temp_cfg}" \ 46 | -e RUBYOPT=-W0 -e RAILS_ENV=production --hostname "${admin_email_domain}" ${MASTODON_IMAGE} \ 47 | bundle exec bin/tootctl accounts create "${ADMIN_USER}" --email "${ADMIN_EMAIL}" --confirmed --role admin \ 48 | >> "${out}" 49 | 50 | pass="$(awk '/New password:/ {print $3}' "${out}")" 51 | 52 | if [ -z "${pass}" ] ; then 53 | echo "ERROR: unable to extract password for admin user." 54 | exit 1 55 | fi 56 | 57 | rm "${out}" 58 | echo "ADMIN_PASSWORD='${pass}'" >>admin.env 59 | chmod 400 admin.env 60 | 61 | echo "Precompiling assets." 62 | docker run -i --network mastodon-net-internal --rm --env-file "${temp_cfg}" \ 63 | -e RUBYOPT=-W0 -e RAILS_ENV=production ${MASTODON_IMAGE} \ 64 | bundle exec rails assets:precompile 65 | 66 | echo "Building initial feed." 67 | docker run -i --network mastodon-net-internal --rm --env-file "${temp_cfg}" \ 68 | -e RUBYOPT=-W0 -e RAILS_ENV=production ${MASTODON_IMAGE} \ 69 | bundle exec bin/tootctl feeds build 70 | 71 | chown mastodon:mastodon "${temp_cfg}" 72 | chmod 400 "${temp_cfg}" 73 | mv "${temp_cfg}" mastodon.env 74 | 75 | echo "All Done!" 76 | -------------------------------------------------------------------------------- /monitoring/postgres-monitoring-queries.yaml: -------------------------------------------------------------------------------- 1 | pg_replication: 2 | query: "SELECT CASE WHEN NOT pg_is_in_recovery() THEN 0 ELSE GREATEST (0, EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp()))) END AS lag" 3 | master: true 4 | metrics: 5 | - lag: 6 | usage: "GAUGE" 7 | description: "Replication lag behind master in seconds" 8 | 9 | pg_postmaster: 10 | query: "SELECT pg_postmaster_start_time as start_time_seconds from pg_postmaster_start_time()" 11 | master: true 12 | metrics: 13 | - start_time_seconds: 14 | usage: "GAUGE" 15 | description: "Time at which postmaster started" 16 | 17 | pg_stat_user_tables: 18 | query: | 19 | SELECT 20 | current_database() datname, 21 | schemaname, 22 | relname, 23 | seq_scan, 24 | seq_tup_read, 25 | idx_scan, 26 | idx_tup_fetch, 27 | n_tup_ins, 28 | n_tup_upd, 29 | n_tup_del, 30 | n_tup_hot_upd, 31 | n_live_tup, 32 | n_dead_tup, 33 | n_mod_since_analyze, 34 | COALESCE(last_vacuum, '1970-01-01Z') as last_vacuum, 35 | COALESCE(last_autovacuum, '1970-01-01Z') as last_autovacuum, 36 | COALESCE(last_analyze, '1970-01-01Z') as last_analyze, 37 | COALESCE(last_autoanalyze, '1970-01-01Z') as last_autoanalyze, 38 | vacuum_count, 39 | autovacuum_count, 40 | analyze_count, 41 | autoanalyze_count 42 | FROM 43 | pg_stat_user_tables 44 | metrics: 45 | - datname: 46 | usage: "LABEL" 47 | description: "Name of current database" 48 | - schemaname: 49 | usage: "LABEL" 50 | description: "Name of the schema that this table is in" 51 | - relname: 52 | usage: "LABEL" 53 | description: "Name of this table" 54 | - seq_scan: 55 | usage: "COUNTER" 56 | description: "Number of sequential scans initiated on this table" 57 | - seq_tup_read: 58 | usage: "COUNTER" 59 | description: "Number of live rows fetched by sequential scans" 60 | - idx_scan: 61 | usage: "COUNTER" 62 | description: "Number of index scans initiated on this table" 63 | - idx_tup_fetch: 64 | usage: "COUNTER" 65 | description: "Number of live rows fetched by index scans" 66 | - n_tup_ins: 67 | usage: "COUNTER" 68 | description: "Number of rows inserted" 69 | - n_tup_upd: 70 | usage: "COUNTER" 71 | description: "Number of rows updated" 72 | - n_tup_del: 73 | usage: "COUNTER" 74 | description: "Number of rows deleted" 75 | - n_tup_hot_upd: 76 | usage: "COUNTER" 77 | description: "Number of rows HOT updated (i.e., with no separate index update required)" 78 | - n_live_tup: 79 | usage: "GAUGE" 80 | description: "Estimated number of live rows" 81 | - n_dead_tup: 82 | usage: "GAUGE" 83 | description: "Estimated number of dead rows" 84 | - n_mod_since_analyze: 85 | usage: "GAUGE" 86 | description: "Estimated number of rows changed since last analyze" 87 | - last_vacuum: 88 | usage: "GAUGE" 89 | description: "Last time at which this table was manually vacuumed (not counting VACUUM FULL)" 90 | - last_autovacuum: 91 | usage: "GAUGE" 92 | description: "Last time at which this table was vacuumed by the autovacuum daemon" 93 | - last_analyze: 94 | usage: "GAUGE" 95 | description: "Last time at which this table was manually analyzed" 96 | - last_autoanalyze: 97 | usage: "GAUGE" 98 | description: "Last time at which this table was analyzed by the autovacuum daemon" 99 | - vacuum_count: 100 | usage: "COUNTER" 101 | description: "Number of times this table has been manually vacuumed (not counting VACUUM FULL)" 102 | - autovacuum_count: 103 | usage: "COUNTER" 104 | description: "Number of times this table has been vacuumed by the autovacuum daemon" 105 | - analyze_count: 106 | usage: "COUNTER" 107 | description: "Number of times this table has been manually analyzed" 108 | - autoanalyze_count: 109 | usage: "COUNTER" 110 | description: "Number of times this table has been analyzed by the autovacuum daemon" 111 | 112 | pg_statio_user_tables: 113 | query: "SELECT current_database() datname, schemaname, relname, heap_blks_read, heap_blks_hit, idx_blks_read, idx_blks_hit, toast_blks_read, toast_blks_hit, tidx_blks_read, tidx_blks_hit FROM pg_statio_user_tables" 114 | metrics: 115 | - datname: 116 | usage: "LABEL" 117 | description: "Name of current database" 118 | - schemaname: 119 | usage: "LABEL" 120 | description: "Name of the schema that this table is in" 121 | - relname: 122 | usage: "LABEL" 123 | description: "Name of this table" 124 | - heap_blks_read: 125 | usage: "COUNTER" 126 | description: "Number of disk blocks read from this table" 127 | - heap_blks_hit: 128 | usage: "COUNTER" 129 | description: "Number of buffer hits in this table" 130 | - idx_blks_read: 131 | usage: "COUNTER" 132 | description: "Number of disk blocks read from all indexes on this table" 133 | - idx_blks_hit: 134 | usage: "COUNTER" 135 | description: "Number of buffer hits in all indexes on this table" 136 | - toast_blks_read: 137 | usage: "COUNTER" 138 | description: "Number of disk blocks read from this table's TOAST table (if any)" 139 | - toast_blks_hit: 140 | usage: "COUNTER" 141 | description: "Number of buffer hits in this table's TOAST table (if any)" 142 | - tidx_blks_read: 143 | usage: "COUNTER" 144 | description: "Number of disk blocks read from this table's TOAST table indexes (if any)" 145 | - tidx_blks_hit: 146 | usage: "COUNTER" 147 | description: "Number of buffer hits in this table's TOAST table indexes (if any)" 148 | 149 | pg_process_idle: 150 | query: | 151 | WITH 152 | metrics AS ( 153 | SELECT 154 | application_name, 155 | SUM(EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - state_change))::bigint)::float AS process_idle_seconds_sum, 156 | COUNT(*) AS process_idle_seconds_count 157 | FROM pg_stat_activity 158 | WHERE state = 'idle' 159 | GROUP BY application_name 160 | ), 161 | buckets AS ( 162 | SELECT 163 | application_name, 164 | le, 165 | SUM( 166 | CASE WHEN EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - state_change)) <= le 167 | THEN 1 168 | ELSE 0 169 | END 170 | )::bigint AS bucket 171 | FROM 172 | pg_stat_activity, 173 | UNNEST(ARRAY[1, 2, 5, 15, 30, 60, 90, 120, 300]) AS le 174 | GROUP BY application_name, le 175 | ORDER BY application_name, le 176 | ) 177 | SELECT 178 | application_name, 179 | process_idle_seconds_sum as seconds_sum, 180 | process_idle_seconds_count as seconds_count, 181 | ARRAY_AGG(le) AS seconds, 182 | ARRAY_AGG(bucket) AS seconds_bucket 183 | FROM metrics JOIN buckets USING (application_name) 184 | GROUP BY 1, 2, 3 185 | metrics: 186 | - application_name: 187 | usage: "LABEL" 188 | description: "Application Name" 189 | - seconds: 190 | usage: "HISTOGRAM" 191 | description: "Idle time of server processes" 192 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /mastodon.yaml: -------------------------------------------------------------------------------- 1 | variant: flatcar 2 | version: 1.0.0 3 | 4 | passwd: 5 | users: 6 | - name: www 7 | no_create_home: true 8 | groups: [ docker ] 9 | - name: mastodon 10 | no_create_home: true 11 | groups: [ docker ] 12 | - name: backup 13 | 14 | storage: 15 | directories: 16 | # Caddy 17 | - path: /opt/caddy 18 | mode: 0755 19 | user: 20 | name: www 21 | group: 22 | name: www 23 | - path: /opt/caddy/data 24 | mode: 0755 25 | user: 26 | name: www 27 | group: 28 | name: www 29 | - path: /opt/caddy/logs 30 | mode: 0755 31 | user: 32 | name: www 33 | group: 34 | name: www 35 | - path: /opt/caddy/etc 36 | mode: 0755 37 | user: 38 | name: www 39 | group: 40 | name: www 41 | - path: /opt/caddy/config 42 | mode: 0755 43 | user: 44 | name: www 45 | group: 46 | name: www 47 | 48 | # Mastodon 49 | - path: /opt/mastodon 50 | mode: 0755 51 | user: 52 | name: mastodon 53 | group: 54 | name: mastodon 55 | - path: /opt/mastodon/elasticsearch 56 | mode: 0755 57 | user: 58 | name: mastodon 59 | group: 60 | name: mastodon 61 | - path: /opt/mastodon/postgres 62 | mode: 0755 63 | user: 64 | name: mastodon 65 | group: 66 | name: mastodon 67 | - path: /opt/mastodon/redis 68 | mode: 0755 69 | user: 70 | name: mastodon 71 | group: 72 | name: mastodon 73 | - path: /opt/mastodon/public 74 | mode: 0755 75 | # hard-coded in Mastodon container image 76 | user: 77 | id: 991 78 | group: 79 | id: 991 80 | 81 | # Monitoring 82 | - path: /opt/mastodon/grafana 83 | mode: 0755 84 | user: 85 | name: mastodon 86 | group: 87 | name: mastodon 88 | - path: /opt/mastodon/grafana/data 89 | mode: 0755 90 | user: 91 | name: mastodon 92 | group: 93 | name: mastodon 94 | - path: /opt/mastodon/grafana/dashboards 95 | mode: 0755 96 | user: 97 | name: mastodon 98 | group: 99 | name: mastodon 100 | - path: /opt/mastodon/grafana/datasources 101 | mode: 0755 102 | user: 103 | name: mastodon 104 | group: 105 | name: mastodon 106 | - path: /opt/mastodon/prometheus 107 | mode: 0755 108 | user: 109 | name: mastodon 110 | group: 111 | name: mastodon 112 | - path: /opt/mastodon/prometheus/etc 113 | mode: 0755 114 | user: 115 | name: mastodon 116 | group: 117 | name: mastodon 118 | - path: /opt/mastodon/prometheus/data 119 | mode: 0755 120 | user: 121 | name: mastodon 122 | group: 123 | name: mastodon 124 | 125 | # Backup 126 | - path: /opt/backup 127 | mode: 0700 128 | 129 | files: 130 | - path: /etc/sysctl.d/99-vm-max-map-count.conf 131 | mode: 0644 132 | contents: 133 | local: sysctl/99-vm-max-map-count.conf 134 | 135 | - path: /opt/caddy/etc/Caddyfile 136 | mode: 0644 137 | contents: 138 | local: caddy/Caddyfile 139 | 140 | # Mastodon 141 | - path: /opt/mastodon/admin.env 142 | mode: 0600 143 | contents: 144 | local: mastodon/admin.env 145 | - path: /opt/mastodon/mastodon.env.template 146 | mode: 0644 147 | contents: 148 | local: mastodon/mastodon.env.template 149 | - path: /opt/mastodon/setup-mastodon.sh 150 | mode: 0755 151 | contents: 152 | local: mastodon/setup-mastodon.sh 153 | - path: /opt/mastodon/versions.env 154 | mode: 0644 155 | contents: 156 | local: mastodon/versions.env 157 | 158 | - path: /opt/mastodon/wait-for-container.sh 159 | mode: 0755 160 | contents: 161 | local: mastodon/wait-for-container.sh 162 | 163 | - path: /etc/systemd/system/mastodon-net-external.service 164 | mode: 0644 165 | contents: 166 | local: systemd/mastodon-net-external.service 167 | - path: /etc/systemd/system/mastodon-net-internal.service 168 | mode: 0644 169 | contents: 170 | local: systemd/mastodon-net-internal.service 171 | - path: /etc/systemd/system/caddy.service 172 | mode: 0644 173 | contents: 174 | local: systemd/caddy.service 175 | - path: /etc/systemd/system/mastodon-db.service 176 | mode: 0644 177 | contents: 178 | local: systemd/mastodon-db.service 179 | - path: /etc/systemd/system/mastodon-es.service 180 | mode: 0644 181 | contents: 182 | local: systemd/mastodon-es.service 183 | - path: /etc/systemd/system/mastodon-redis.service 184 | mode: 0644 185 | contents: 186 | local: systemd/mastodon-redis.service 187 | - path: /etc/systemd/system/mastodon-setup.service 188 | mode: 0644 189 | contents: 190 | local: systemd/mastodon-setup.service 191 | - path: /etc/systemd/system/mastodon-sidekiq.service 192 | mode: 0644 193 | contents: 194 | local: systemd/mastodon-sidekiq.service 195 | - path: /etc/systemd/system/mastodon-streaming.service 196 | mode: 0644 197 | contents: 198 | local: systemd/mastodon-streaming.service 199 | - path: /etc/systemd/system/mastodon-web.service 200 | mode: 0644 201 | contents: 202 | local: systemd/mastodon-web.service 203 | - path: /etc/systemd/system/mastodon.service 204 | mode: 0644 205 | contents: 206 | local: systemd/mastodon.service 207 | 208 | # Monitoring 209 | - path: /opt/mastodon/monitoring-admin.env 210 | mode: 0400 211 | user: 212 | name: mastodon 213 | contents: 214 | local: monitoring/monitoring-admin.env 215 | - path: /opt/mastodon/monitoring-versions.env 216 | mode: 0644 217 | contents: 218 | local: monitoring/monitoring-versions.env 219 | - path: /opt/mastodon/postgres-monitoring-queries.yaml 220 | mode: 0644 221 | contents: 222 | local: monitoring/postgres-monitoring-queries.yaml 223 | - path: /opt/mastodon/prometheus/etc/prometheus.yaml 224 | mode: 0644 225 | contents: 226 | local: monitoring/prometheus.yaml 227 | - path: /opt/mastodon/grafana/datasources/grafana-datasources.yaml 228 | mode: 0644 229 | contents: 230 | local: monitoring/grafana-datasources.yaml 231 | - path: /opt/mastodon/grafana/dashboards/grafana-dashboards.yaml 232 | mode: 0644 233 | contents: 234 | local: monitoring/grafana-dashboards.yaml 235 | - path: /opt/mastodon/grafana/dashboards/docker-containers.json 236 | mode: 0644 237 | contents: 238 | source: https://raw.githubusercontent.com/flatcar/flatcar-mastodon/main/monitoring/docker-containers.json 239 | - path: /opt/mastodon/grafana/dashboards/elasticsearch.json 240 | mode: 0644 241 | contents: 242 | source: https://raw.githubusercontent.com/flatcar/flatcar-mastodon/main/monitoring/elasticsearch.json 243 | - path: /opt/mastodon/grafana/dashboards/host-system.json 244 | mode: 0644 245 | contents: 246 | source: https://raw.githubusercontent.com/flatcar/flatcar-mastodon/main/monitoring/host-system.json 247 | - path: /opt/mastodon/grafana/dashboards/mastodon.json 248 | mode: 0644 249 | contents: 250 | source: https://raw.githubusercontent.com/flatcar/flatcar-mastodon/main/monitoring/mastodon.json 251 | - path: /opt/mastodon/grafana/dashboards/monitoring.json 252 | mode: 0644 253 | contents: 254 | source: https://raw.githubusercontent.com/flatcar/flatcar-mastodon/main/monitoring/monitoring.json 255 | - path: /opt/mastodon/grafana/dashboards/postgres.json 256 | mode: 0644 257 | contents: 258 | source: https://raw.githubusercontent.com/flatcar/flatcar-mastodon/main/monitoring/postgres.json 259 | - path: /opt/mastodon/grafana/dashboards/redis.json 260 | mode: 0644 261 | contents: 262 | source: https://raw.githubusercontent.com/flatcar/flatcar-mastodon/main/monitoring/redis.json 263 | - path: /opt/mastodon/grafana/dashboards/sidekiq.json 264 | mode: 0644 265 | contents: 266 | source: https://raw.githubusercontent.com/flatcar/flatcar-mastodon/main/monitoring/sidekiq.json 267 | - path: /opt/mastodon/grafana/dashboards/caddy.json 268 | mode: 0644 269 | contents: 270 | source: https://raw.githubusercontent.com/flatcar/flatcar-mastodon/main/monitoring/caddy.json 271 | 272 | - path: /etc/systemd/system/metrics-provider-cadvisor.service 273 | mode: 0644 274 | contents: 275 | local: systemd/metrics-provider-cadvisor.service 276 | - path: /etc/systemd/system/metrics-provider-es.service 277 | mode: 0644 278 | contents: 279 | local: systemd/metrics-provider-es.service 280 | - path: /etc/systemd/system/metrics-provider-mastodon.service 281 | mode: 0644 282 | contents: 283 | local: systemd/metrics-provider-mastodon.service 284 | - path: /etc/systemd/system/metrics-provider-nodeexporter.service 285 | mode: 0644 286 | contents: 287 | local: systemd/metrics-provider-nodeexporter.service 288 | - path: /etc/systemd/system/metrics-provider-postgres.service 289 | mode: 0644 290 | contents: 291 | local: systemd/metrics-provider-postgres.service 292 | - path: /etc/systemd/system/metrics-provider-redis.service 293 | mode: 0644 294 | contents: 295 | local: systemd/metrics-provider-redis.service 296 | - path: /etc/systemd/system/metrics-provider-sidekiq.service 297 | mode: 0644 298 | contents: 299 | local: systemd/metrics-provider-sidekiq.service 300 | - path: /etc/systemd/system/monitoring-grafana.service 301 | mode: 0644 302 | contents: 303 | local: systemd/monitoring-grafana.service 304 | - path: /etc/systemd/system/monitoring-prometheus.service 305 | mode: 0644 306 | contents: 307 | local: systemd/monitoring-prometheus.service 308 | 309 | # Backup 310 | - path: /opt/backup/backup_client.sh 311 | mode: 0500 312 | contents: 313 | local: backup/backup_client.sh 314 | - path: /opt/backup/backup.sh 315 | mode: 0500 316 | contents: 317 | local: backup/backup.sh 318 | - path: /opt/backup/restore.sh 319 | mode: 0500 320 | contents: 321 | local: backup/restore.sh 322 | - path: /opt/clone/re_initialise.sh 323 | mode: 0500 324 | contents: 325 | local: backup/re_initialise.sh 326 | - path: /etc/sudoers.d/backup 327 | mode: 0440 328 | contents: 329 | local: backup/sudoers 330 | - path: /home/backup/.ssh/authorized_keys 331 | mode: 0444 332 | contents: 333 | local: backup/backup_key.pub 334 | user: 335 | name: backup 336 | 337 | systemd: 338 | units: 339 | - name: mastodon-net-external.service 340 | enabled: true 341 | - name: mastodon-net-internal.service 342 | enabled: true 343 | - name: caddy.service 344 | enabled: true 345 | - name: mastodon-db.service 346 | enabled: true 347 | - name: mastodon-es.service 348 | enabled: true 349 | - name: mastodon-redis.service 350 | enabled: true 351 | - name: mastodon-setup.service 352 | enabled: true 353 | - name: mastodon-sidekiq.service 354 | enabled: true 355 | - name: mastodon-streaming.service 356 | enabled: true 357 | - name: mastodon-web.service 358 | enabled: true 359 | - name: mastodon.service 360 | enabled: true 361 | 362 | - name: metrics-provider-cadvisor.service 363 | enabled: true 364 | - name: metrics-provider-es.service 365 | enabled: true 366 | - name: metrics-provider-mastodon.service 367 | enabled: true 368 | - name: metrics-provider-nodeexporter.service 369 | enabled: true 370 | - name: metrics-provider-postgres.service 371 | enabled: true 372 | - name: metrics-provider-redis.service 373 | enabled: true 374 | - name: metrics-provider-sidekiq.service 375 | enabled: true 376 | - name: monitoring-grafana.service 377 | enabled: true 378 | - name: monitoring-prometheus.service 379 | enabled: true 380 | -------------------------------------------------------------------------------- /monitoring/mastodon.json: -------------------------------------------------------------------------------- 1 | { 2 | "annotations": { 3 | "list": [ 4 | { 5 | "builtIn": 1, 6 | "datasource": { 7 | "type": "grafana", 8 | "uid": "-- Grafana --" 9 | }, 10 | "enable": true, 11 | "hide": true, 12 | "iconColor": "rgba(0, 211, 255, 1)", 13 | "name": "Annotations & Alerts", 14 | "target": { 15 | "limit": 100, 16 | "matchAny": false, 17 | "tags": [], 18 | "type": "dashboard" 19 | }, 20 | "type": "dashboard" 21 | } 22 | ] 23 | }, 24 | "editable": true, 25 | "fiscalYearStartMonth": 0, 26 | "graphTooltip": 0, 27 | "id": 16, 28 | "links": [], 29 | "liveNow": false, 30 | "panels": [ 31 | { 32 | "datasource": { 33 | "type": "prometheus", 34 | "uid": "PBFA97CFB590B2093" 35 | }, 36 | "fieldConfig": { 37 | "defaults": { 38 | "color": { 39 | "mode": "palette-classic" 40 | }, 41 | "custom": { 42 | "axisCenteredZero": false, 43 | "axisColorMode": "text", 44 | "axisLabel": "", 45 | "axisPlacement": "auto", 46 | "axisSoftMin": 0, 47 | "barAlignment": 0, 48 | "drawStyle": "line", 49 | "fillOpacity": 30, 50 | "gradientMode": "none", 51 | "hideFrom": { 52 | "legend": false, 53 | "tooltip": false, 54 | "viz": false 55 | }, 56 | "lineInterpolation": "smooth", 57 | "lineWidth": 1, 58 | "pointSize": 5, 59 | "scaleDistribution": { 60 | "type": "linear" 61 | }, 62 | "showPoints": "auto", 63 | "spanNulls": false, 64 | "stacking": { 65 | "group": "A", 66 | "mode": "none" 67 | }, 68 | "thresholdsStyle": { 69 | "mode": "off" 70 | } 71 | }, 72 | "mappings": [], 73 | "thresholds": { 74 | "mode": "percentage", 75 | "steps": [ 76 | { 77 | "color": "green", 78 | "value": null 79 | }, 80 | { 81 | "color": "red", 82 | "value": 100 83 | } 84 | ] 85 | } 86 | }, 87 | "overrides": [] 88 | }, 89 | "gridPos": { 90 | "h": 9, 91 | "w": 12, 92 | "x": 0, 93 | "y": 0 94 | }, 95 | "id": 5, 96 | "options": { 97 | "legend": { 98 | "calcs": [], 99 | "displayMode": "list", 100 | "placement": "bottom", 101 | "showLegend": true 102 | }, 103 | "tooltip": { 104 | "mode": "single", 105 | "sort": "none" 106 | } 107 | }, 108 | "pluginVersion": "9.1.1", 109 | "targets": [ 110 | { 111 | "datasource": { 112 | "type": "prometheus", 113 | "uid": "PBFA97CFB590B2093" 114 | }, 115 | "editorMode": "code", 116 | "exemplar": false, 117 | "expr": "mastodon_statuses", 118 | "format": "time_series", 119 | "instant": false, 120 | "interval": "", 121 | "legendFormat": "posts", 122 | "range": true, 123 | "refId": "A" 124 | } 125 | ], 126 | "title": "Total number of posts", 127 | "type": "timeseries" 128 | }, 129 | { 130 | "datasource": { 131 | "type": "prometheus", 132 | "uid": "PBFA97CFB590B2093" 133 | }, 134 | "fieldConfig": { 135 | "defaults": { 136 | "color": { 137 | "mode": "palette-classic" 138 | }, 139 | "custom": { 140 | "axisCenteredZero": false, 141 | "axisColorMode": "text", 142 | "axisLabel": "", 143 | "axisPlacement": "auto", 144 | "axisSoftMin": 0, 145 | "barAlignment": 0, 146 | "drawStyle": "line", 147 | "fillOpacity": 30, 148 | "gradientMode": "none", 149 | "hideFrom": { 150 | "legend": false, 151 | "tooltip": false, 152 | "viz": false 153 | }, 154 | "lineInterpolation": "smooth", 155 | "lineWidth": 1, 156 | "pointSize": 5, 157 | "scaleDistribution": { 158 | "type": "linear" 159 | }, 160 | "showPoints": "auto", 161 | "spanNulls": false, 162 | "stacking": { 163 | "group": "A", 164 | "mode": "none" 165 | }, 166 | "thresholdsStyle": { 167 | "mode": "off" 168 | } 169 | }, 170 | "mappings": [], 171 | "thresholds": { 172 | "mode": "percentage", 173 | "steps": [ 174 | { 175 | "color": "green", 176 | "value": null 177 | }, 178 | { 179 | "color": "red", 180 | "value": 100 181 | } 182 | ] 183 | } 184 | }, 185 | "overrides": [ 186 | { 187 | "matcher": { 188 | "id": "byName", 189 | "options": "Daily growth" 190 | }, 191 | "properties": [ 192 | { 193 | "id": "custom.axisPlacement", 194 | "value": "right" 195 | }, 196 | { 197 | "id": "custom.fillOpacity", 198 | "value": 0 199 | } 200 | ] 201 | } 202 | ] 203 | }, 204 | "gridPos": { 205 | "h": 18, 206 | "w": 12, 207 | "x": 12, 208 | "y": 0 209 | }, 210 | "id": 2, 211 | "options": { 212 | "legend": { 213 | "calcs": [ 214 | "last" 215 | ], 216 | "displayMode": "list", 217 | "placement": "bottom", 218 | "showLegend": true 219 | }, 220 | "tooltip": { 221 | "mode": "single", 222 | "sort": "none" 223 | } 224 | }, 225 | "pluginVersion": "9.1.1", 226 | "targets": [ 227 | { 228 | "datasource": { 229 | "type": "prometheus", 230 | "uid": "PBFA97CFB590B2093" 231 | }, 232 | "editorMode": "code", 233 | "exemplar": false, 234 | "expr": "mastodon_domains", 235 | "format": "time_series", 236 | "instant": false, 237 | "interval": "", 238 | "legendFormat": "Total", 239 | "range": true, 240 | "refId": "A" 241 | }, 242 | { 243 | "datasource": { 244 | "type": "prometheus", 245 | "uid": "PBFA97CFB590B2093" 246 | }, 247 | "editorMode": "code", 248 | "expr": "increase(mastodon_domains[1d])", 249 | "hide": false, 250 | "legendFormat": "Daily growth", 251 | "range": true, 252 | "refId": "B" 253 | } 254 | ], 255 | "title": "Known domains", 256 | "type": "timeseries" 257 | }, 258 | { 259 | "datasource": { 260 | "type": "prometheus", 261 | "uid": "PBFA97CFB590B2093" 262 | }, 263 | "fieldConfig": { 264 | "defaults": { 265 | "color": { 266 | "mode": "palette-classic" 267 | }, 268 | "custom": { 269 | "axisCenteredZero": false, 270 | "axisColorMode": "text", 271 | "axisLabel": "", 272 | "axisPlacement": "auto", 273 | "axisSoftMin": 0, 274 | "barAlignment": 0, 275 | "drawStyle": "line", 276 | "fillOpacity": 30, 277 | "gradientMode": "none", 278 | "hideFrom": { 279 | "legend": false, 280 | "tooltip": false, 281 | "viz": false 282 | }, 283 | "lineInterpolation": "smooth", 284 | "lineWidth": 1, 285 | "pointSize": 5, 286 | "scaleDistribution": { 287 | "type": "linear" 288 | }, 289 | "showPoints": "auto", 290 | "spanNulls": false, 291 | "stacking": { 292 | "group": "A", 293 | "mode": "none" 294 | }, 295 | "thresholdsStyle": { 296 | "mode": "off" 297 | } 298 | }, 299 | "mappings": [], 300 | "thresholds": { 301 | "mode": "percentage", 302 | "steps": [ 303 | { 304 | "color": "green", 305 | "value": null 306 | }, 307 | { 308 | "color": "red", 309 | "value": 100 310 | } 311 | ] 312 | } 313 | }, 314 | "overrides": [] 315 | }, 316 | "gridPos": { 317 | "h": 9, 318 | "w": 6, 319 | "x": 0, 320 | "y": 9 321 | }, 322 | "id": 3, 323 | "options": { 324 | "legend": { 325 | "calcs": [], 326 | "displayMode": "list", 327 | "placement": "bottom", 328 | "showLegend": true 329 | }, 330 | "tooltip": { 331 | "mode": "single", 332 | "sort": "none" 333 | } 334 | }, 335 | "pluginVersion": "9.1.1", 336 | "targets": [ 337 | { 338 | "datasource": { 339 | "type": "prometheus", 340 | "uid": "PBFA97CFB590B2093" 341 | }, 342 | "editorMode": "code", 343 | "exemplar": false, 344 | "expr": "mastodon_weekly_logins", 345 | "format": "time_series", 346 | "instant": false, 347 | "interval": "", 348 | "legendFormat": "Logins", 349 | "range": true, 350 | "refId": "A" 351 | } 352 | ], 353 | "title": "Weekly logins", 354 | "type": "timeseries" 355 | }, 356 | { 357 | "datasource": { 358 | "type": "prometheus", 359 | "uid": "PBFA97CFB590B2093" 360 | }, 361 | "fieldConfig": { 362 | "defaults": { 363 | "color": { 364 | "mode": "palette-classic" 365 | }, 366 | "custom": { 367 | "axisCenteredZero": false, 368 | "axisColorMode": "text", 369 | "axisLabel": "", 370 | "axisPlacement": "auto", 371 | "axisSoftMin": 0, 372 | "barAlignment": 0, 373 | "drawStyle": "line", 374 | "fillOpacity": 30, 375 | "gradientMode": "none", 376 | "hideFrom": { 377 | "legend": false, 378 | "tooltip": false, 379 | "viz": false 380 | }, 381 | "lineInterpolation": "smooth", 382 | "lineWidth": 1, 383 | "pointSize": 5, 384 | "scaleDistribution": { 385 | "type": "linear" 386 | }, 387 | "showPoints": "auto", 388 | "spanNulls": false, 389 | "stacking": { 390 | "group": "A", 391 | "mode": "none" 392 | }, 393 | "thresholdsStyle": { 394 | "mode": "off" 395 | } 396 | }, 397 | "mappings": [], 398 | "thresholds": { 399 | "mode": "percentage", 400 | "steps": [ 401 | { 402 | "color": "green", 403 | "value": null 404 | }, 405 | { 406 | "color": "red", 407 | "value": 100 408 | } 409 | ] 410 | } 411 | }, 412 | "overrides": [] 413 | }, 414 | "gridPos": { 415 | "h": 9, 416 | "w": 6, 417 | "x": 6, 418 | "y": 9 419 | }, 420 | "id": 4, 421 | "options": { 422 | "legend": { 423 | "calcs": [], 424 | "displayMode": "list", 425 | "placement": "bottom", 426 | "showLegend": true 427 | }, 428 | "tooltip": { 429 | "mode": "single", 430 | "sort": "none" 431 | } 432 | }, 433 | "pluginVersion": "9.1.1", 434 | "targets": [ 435 | { 436 | "datasource": { 437 | "type": "prometheus", 438 | "uid": "PBFA97CFB590B2093" 439 | }, 440 | "editorMode": "code", 441 | "exemplar": false, 442 | "expr": "mastodon_weekly_statuses", 443 | "format": "time_series", 444 | "instant": false, 445 | "interval": "", 446 | "legendFormat": "posts", 447 | "range": true, 448 | "refId": "A" 449 | } 450 | ], 451 | "title": "Weekly posts", 452 | "type": "timeseries" 453 | } 454 | ], 455 | "refresh": "5s", 456 | "schemaVersion": 37, 457 | "style": "dark", 458 | "tags": [], 459 | "templating": { 460 | "list": [] 461 | }, 462 | "time": { 463 | "from": "now-6h", 464 | "to": "now" 465 | }, 466 | "timepicker": {}, 467 | "timezone": "", 468 | "title": "Mastodon", 469 | "uid": "nofc0Wd4z", 470 | "version": 1, 471 | "weekStart": "" 472 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | [![Flatcar OS](https://img.shields.io/badge/Flatcar-Website-blue?logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyNi4wLjMsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4wIiBpZD0ia2F0bWFuXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgODAwIDYwMCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgODAwIDYwMDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPHN0eWxlIHR5cGU9InRleHQvY3NzIj4NCgkuc3Qwe2ZpbGw6IzA5QkFDODt9DQo8L3N0eWxlPg0KPHBhdGggY2xhc3M9InN0MCIgZD0iTTQ0MCwxODIuOGgtMTUuOXYxNS45SDQ0MFYxODIuOHoiLz4NCjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik00MDAuNSwzMTcuOWgtMzEuOXYxNS45aDMxLjlWMzE3Ljl6Ii8+DQo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNNTQzLjgsMzE3LjlINTEydjE1LjloMzEuOVYzMTcuOXoiLz4NCjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik02NTUuMiw0MjAuOXYtOTUuNGgtMTUuOXY5NS40aC0xNS45VjI2MmgtMzEuOVYxMzQuOEgyMDkuNFYyNjJoLTMxLjl2MTU5aC0xNS45di05NS40aC0xNnY5NS40aC0xNS45djMxLjINCgloMzEuOXYxNS44aDQ3Ljh2LTE1LjhoMTUuOXYxNS44SDI3M3YtMTUuOGgyNTQuOHYxNS44aDQ3Ljh2LTE1LjhoMTUuOXYxNS44aDQ3Ljh2LTE1LjhoMzEuOXYtMzEuMkg2NTUuMnogTTQ4Ny44LDE1MWg3OS42djMxLjgNCgloLTIzLjZ2NjMuNkg1MTJ2LTYzLjZoLTI0LjJMNDg3LjgsMTUxTDQ4Ny44LDE1MXogTTIzMywyMTQuNlYxNTFoNjMuN3YyMy41aC0zMS45djE1LjhoMzEuOXYyNC4yaC0zMS45djMxLjhIMjMzVjIxNC42eiBNMzA1LDMxNy45DQoJdjE1LjhoLTQ3Ljh2MzEuOEgzMDV2NDcuN2gtOTUuNVYyODYuMUgzMDVMMzA1LDMxNy45eiBNMzEyLjYsMjQ2LjRWMTUxaDMxLjl2NjMuNmgzMS45djMxLjhMMzEyLjYsMjQ2LjRMMzEyLjYsMjQ2LjRMMzEyLjYsMjQ2LjR6DQoJIE00NDguMywzMTcuOXY5NS40aC00Ny44di00Ny43aC0zMS45djQ3LjdoLTQ3LjhWMzAyaDE1Ljl2LTE1LjhoOTUuNVYzMDJoMTUuOUw0NDguMywzMTcuOXogTTQ0MCwyNDYuNHYtMzEuOGgtMTUuOXYzMS44aC0zMS45DQoJdi03OS41aDE1Ljl2LTE1LjhoNDcuOHYxNS44aDE1Ljl2NzkuNUg0NDB6IE01OTEuNiwzMTcuOXY0Ny43aC0xNS45djE1LjhoMTUuOXYzMS44aC00Ny44di0zMS43SDUyOHYtMTUuOGgtMTUuOXY0Ny43aC00Ny44VjI4Ni4xDQoJaDEyNy4zVjMxNy45eiIvPg0KPC9zdmc+DQo=)](https://www.flatcar.org/) 4 | [![Matrix](https://img.shields.io/badge/Matrix-Chat%20with%20us!-green?logo=matrix)](https://app.element.io/#/room/#flatcar:matrix.org) 5 | [![Slack](https://img.shields.io/badge/Slack-Chat%20with%20us!-4A154B?logo=slack)](https://kubernetes.slack.com/archives/C03GQ8B5XNJ) 6 | [![Twitter Follow](https://img.shields.io/twitter/follow/flatcar?style=social)](https://x.com/flatcar) 7 | [![Mastodon Follow](https://img.shields.io/badge/Mastodon-Follow-6364FF?logo=mastodon)](https://hachyderm.io/@flatcar) 8 | [![Bluesky](https://img.shields.io/badge/Bluesky-Follow-0285FF?logo=bluesky)](https://bsky.app/profile/flatcar.org) 9 | 10 |
11 | 12 | # flatcar-mastodon 13 | Automation for deploying a Mastodon node on Flatcar. 14 | 15 | The files and config snippets in this repository allow to fully auto-provision a Mastodon node on Flatcar Container Linux. 16 | Set-up and configuration is automated via Ignition. 17 | Only instance-specific parameters need to be provided. 18 | 19 | ## Features 20 | - Fully automated deployment based on very few settings (see HowTo below). 21 | - Automated HTTPS certificate retrieval and installation (via caddy + letsencrypt). 22 | - Includes elasticsearch for full-text indexing. 23 | - Includes comprehensive monitoring suite for web server and mastodon services as well as for the host system and all containers. 24 | - Supports basic back-up and restore, as well as node cloning (e.g. for switching cloud providers, or for horizontal scaling). 25 | 26 | ## HowTo 27 | 28 | **Prerequisites** 29 | 1. A domain name for your new Mastodon instance, and access to your domain registrar's DNS (see step 7.). 30 | 2. An SMTP account for your instance to send notification emails from (any public freemailer account should work). 31 | 3. A cloud service / private cloud / physical server to provision Flatcar on. See 4. below for more information. 32 | 33 | **Set-up Instructions** 34 | 1. Clone this repo. 35 | 2. Configure basic settings for your new instance: 36 | 1. Set the domain name and webmaster email address in [`caddy/Caddyfile`](caddy/Caddyfile). 37 | 2. Configure an initial Mastodon administrator account in [`mastodon/admin.env`](mastodon/admin.env) (user name and email). 38 | - **DO NOT USE 'admin'** as username. This is a reserved name (Mastodon internal), using 'admin' will cause the initial set-up to fail. 39 | - It is pretty common in the fediverse to use one's personal account for administration. 40 | This allows users of your instance to follow their admin, and users of other instances to reach out to you. 41 | So this can be your personal account if you like. 42 | - **Note**: The email address you provide here will be used later for the initial login to your instance. 43 | Make sure there are no typos 😉 44 | 3. Configure an SMTP account for your instance to send notification emails from, and the Mastodon domain (same as web server above) 45 | in [`mastodon/mastodon.env.template`](mastodon/mastodon.env.template). 46 | - Make sure the SMTP configuration is correct as this is the only way of using the initial admin account without manually logging 47 | into the instance to retrieve the password. 48 | 4. Set up a login (username and password) for your monitoring dashboards at [`monitoring/monitoring-admin.env`](monitoring/monitoring-admin.env). 49 | You can add more users and change your password later via the Grafana web user interface. 50 | 5. Generate a ssh keypair for remote backups. The keys are also required for node cloning. 51 | ```shell 52 | ssh-keygen -P "" -f backup/backup_key 53 | ``` 54 | Keep your private backup key (generated at `backup/backup_key`) safe! 55 | It grants (limited) superuser access to the node, and you'll need it for manual and for automated backups, and for cloning your node. 56 | 3. Generate Ignition deployment configuration based on your custom settings above by running 57 | ```shell 58 | cat mastodon.yaml | docker run --rm -i -v $(pwd):/files quay.io/coreos/butane:latest --files-dir /files > ignition.json 59 | ``` 60 | 4. Kick off a [Flatcar installation](https://www.flatcar.org/docs/latest/installing/) 61 | on [your server](https://www.flatcar.org/docs/latest/installing/bare-metal/), 62 | on your [favourite public or private cloud](https://www.flatcar.org/docs/latest/installing/cloud/), 63 | on [your custom virtualisation](https://www.flatcar.org/docs/latest/installing/vms/), 64 | or on one of the [community contributed platforms](https://www.flatcar.org/docs/latest/installing/community-platforms/). 65 | Supply the `ignition.json` provisioning config generated above to the deployment (as user data, custom data etc. - it's provider specific). 66 | 5. As soon as the provisioning started and you know the final IP address of your instance, update your domain in your registrar's DNS to point to the IP of the new instance. 67 | This will allow caddy to retrieve a letsencrypt HTTPS certificate during provisioning. 68 | 6. Wait for the deployment to conclude. 69 | You should receive a welcome email from your new Mastodon instance in the administrator account's inbox (see step #3 above). 70 | The email should arrive at about the time everything is set up, so you can access your instance right away! 71 | Log in with the admin account's email address and use Mastodon's "reset password" feature to set a new password. 72 | Alternatively, ssh into the instance and check `/opt/mastodon/admin.env` for the password auto-generated by Mastodon during provisioning. 73 | 74 | Your instance will be available directly via `https://${DOMAIN}/`. 75 | You can access your monitoring dashboards at `https://${DOMAIN}/monitoring/` using the account you defined in step 2.4. above. 76 | 77 | ## Monitoring 78 | 79 | The deployment ships with a comprehensive monitoring suite. 80 | Prometheus is used to scrape and to store telemetry. 81 | Grafana dashboards are provided to keep track of various system components. 82 | 83 | Grafana dashboards are available at `https://${DOMAIN}/monitoring/` using the monitoring login defined in [`monitoring/monitoring-admin.env`](monitoring/monitoring-admin.env). 84 | 85 | We include the following dashboards: 86 | - Caddy web server requests / responses, latency, etc. 87 | - node-exporter host telemetry - CPU and memory load, disk space, etc. 88 | - cadvisor container telemetry - active containers, resource usage per container, etc. 89 | - Mastodon - posts, users, known instances. 90 | - Mastodon Sidekiq - workers, queues, jobs processed, job errors etc. 91 | - Redis - resource usage, command processing / time spent, client connections, etc. 92 | - elasticsearch - CPU / Memory usage, index/query/queue stats, thread pool state, shards state, etc. 93 | - postgres - resource usage, connections/transactions/buffer state, locks, I/O latency etc. 94 | - Resource usage of the monitoring system (container / host stats filtered to only include monitoring containers). 95 | 96 | ## Maintenance 97 | 98 | The `mastodon-setup` start-up phase (step 2 above) is also useful for maintenance and debugging. 99 | At this stage, only low-level components are up - allowing to start a maintenance environment like e.g. 100 | ```shell 101 | systemctl stop mastodon 102 | systemctl start mastodon-setup 103 | source /opt/mastodon/versions.env 104 | docker run -it --rm --network=mastodon-net-internal --env-file="./mastodon.env" -e RAILS_ENV=production ${MASTODON_IMAGE} bash 105 | ``` 106 | and interacting with the mastodon installation via `bin/tootctl`. 107 | 108 | ### Update container image versions 109 | 110 | Edit `/opt/mastodon/versions.env` and update the version tags. 111 | For minor / patch updates that do not require database migration, simply run `systemctl restart mastodon`. 112 | If DB migration and/or other manual upgrade steps are needed, enter maintenance mode (see above) and perform the required steps. 113 | 114 | Common migration steps include .e.g 115 | ``` 116 | bundle exec rake mastodon:setup # migrate the database 117 | bundle exec rails assets:precompile # recompile web assets 118 | bundle exec bin/tootctl feeds build # re-generate feeds 119 | bundle exec bin/tootctl search deploy # re-generate full-text search index 120 | ``` 121 | 122 | ## Backup and restore, node cloning and vertical scaling 123 | 124 | Automation ships with basic backup and restore features. 125 | Both node-local and remote backups are supported. 126 | 127 | Also, a "clone node" provisioning automation is supplied which will create a new Mastodon deployment based on an existing one. 128 | Node cloning can be used to switch providers, move to or from on-prem deployments, and for vertically scaling (increase or decrease instance size). 129 | 130 | **NOTE** Mastodon and monitoring services will be shut down temporarily during the backup to prevent inconsistencies. 131 | 132 | The following is backed up: 133 | - Mastodon configuration, user data (uploads etc.), redis and elasticsearch state. 134 | - Monitoring configuration and all past telemetry. 135 | - Web server logs, configuration, and state (e.g. https certificates). 136 | - Backup scripts in `/opt/backup` to preserve local changes. 137 | - All relevant systemd units. 138 | This will preserve customised parameters in these units. 139 | Also, wildcard matches are used for backup, so any additional custom `metrics-provider-*`, `monitoring-*`, `mastodon*`, and `caddy*` files are included in the backup. 140 | 141 | A `backup` account is provided for both local and remote backups. 142 | The account has `sudo` access to the `backup_client.sh` script in `/opt/backup/` but is otherwise restricted. 143 | 144 | ### Clone a node 145 | 146 | **Prerequisites**: backup user private key file, user+host of the source node. 147 | 148 | 1. Edit [`clone-node.yaml`](clone-node.yaml) and replace `BACKUPUSER@HOST` with user name (likely `backup`) and source host (IP or domain name). 149 | 2. Supply backup private key file at `backup/backup_key` 150 | 3. Generate Ignition deployment configuration based on these settings by running 151 | ```shell 152 | cat clone-node.yaml | docker run --rm -i -v $(pwd):/files quay.io/coreos/butane:latest --files-dir /files > clone.json 153 | ``` 154 | 4. Provision a new Flatcar node with your favourite hoster (or on prem, or private cloud) and supply `clone.json` as user data / custom data. 155 | Note that the new node needs to be able to reach the source node via SSH. 156 | 5. Wait for the deployment to conclude. 157 | Update DNS entries of your domain to point to the new node's IP address. 158 | 159 | ### Node-local backup 160 | 161 | Ssh into the node, change to the directory you want the backup to be created in, and run 162 | ```shell 163 | sudo /opt/backup/backup.sh 164 | ``` 165 | You can also set up a systemd timer unit to make regular backups. 166 | The backup tarball will be created in the local directory `/opt/backup/backup.sh` was called from. 167 | The tarball will follow the pattern `mastodon-backup-YYYY-MM-DD_hh_mm_ss.tgz`. 168 | Backup tarballs include all files required for restore with their full paths in the filesystem root. 169 | 170 | **NOTE** Mastodon and monitoring services will be shut down temporarily during the backup to prevent inconsistencies. 171 | 172 | **NOTE** Do not put your backup files to `/opt/backup`; that directory is only for backup scripts and will be WIPED during a restore. 173 | 174 | ### Remote backup 175 | 176 | Remote backups use ssh and are authenticated via public ssh keys in `/home/backup/.ssh/authorized_keys`. 177 | By default, this includes the public key of the SSH backup key pair generated in the HowTo (see HowTo step 2.5. above). 178 | Backup is performed via the [`backup/backup.sh`](backup/backup) script in this repository, passing both the remote user+host and the private key as a parameter, e.g.: 179 | ``` 180 | backup/backup.sh backup@mydomain.social backup/backup_key 181 | ``` 182 | 183 | **NOTE** Mastodon and monitoring services will be shut down temporarily during the backup to prevent inconsistencies. 184 | 185 | ### Restore 186 | 187 | Node restore works on a backup created with `backup.sh` (see above). 188 | Restore will first stop all running Mastodon / monitoring services and wipe all related files and service units. 189 | Then, it will restore all files from the backup tarball to root, install systemd services, and initialise the database. 190 | Lastly, it will start all mastodon / monitoring services. 191 | 192 | **NOTE** Mastodon and monitoring services will be shut down before restore, and all files will be wiped from `/opt/mastodon`, `/opt/caddy`, and `/opt/backup`. 193 | 194 | ## List of Containers and Connectivity to Container Networking 195 | 196 | The deployment uses 2 user-defined container networks - an "external" network through which containers can reach the internet, and an "internal" one without any internet connectivity. 197 | Only ports exposed on the "external" net are internet accessible. 198 | Furthermore, 2 containers use host mode networking. 199 | 200 | * Container on "external" network with ports exposed to the internet 201 | * Caddy 202 | * Host network mode containers with ports exposed on localhost 203 | * CAdvisor 204 | * Node-exporter 205 | * Container on "external" network with ports exposed to localhost 206 | * Mastodon web 207 | * Mastodon streaming 208 | * Grafana 209 | * Container on "external" network without ports exposed 210 | * Mastodon Sidekiq 211 | * Prometheus 212 | * Mastodon Prometheus exporter 213 | * Containers only on the "internal" network without internet access 214 | * Redis 215 | * Postgres 216 | * Elasticsearch 217 | * Redis Prometheus exporter 218 | * Postgres Prometheus exporter 219 | * Elasticsearch Prometheus exporter 220 | * Mastodon Sidekiq Prometheus exporter 221 | 222 | ## Services Dtructure and Dependencies 223 | 224 | All services start automatically at boot. 225 | 226 | All mastodon services are grouped in an umbrella service and can be started with `systemctl start mastodon` and torn down with `systemctl stop mastodon` respectively. 227 | 228 | Services dependent on other services are displayed towards the root; services w/o dependencies are leaves. 229 | 230 | ``` 231 | mastodon.service - Umbrella service that depends on all services. 232 | │  All dependent services will also be torn down when "mastodon.service" is stopped. 233 | ├── mastodon-sidekiq.service - Background processing, uses internal + external networking and DBs. 234 | │ ├── mastodon-net-external.service - Docker user-defined network for external networking. 235 | │ └── mastodon-setup.service - First-time setup. NOP after installation; useful for maintenance. 236 | │ │ Runs with internal network only, needs all DBs. 237 | │    ├── mastodon-db.service - Postgres, reachable via internal network only. 238 | │   ├── mastodon-es.service - Elasticsearch, reachable via internal network only. 239 | │   └── mastodon-redis.service - Redis, reachable via internal network only. 240 | │ └── mastodon-net-internal.service - User-defined container network for internal networking. No I/O to the outside. 241 | ├── mastodon-streaming.service - Streaming API, uses internal + external networking and DBs, listens to 127.0.0.1:5051. 242 | │ ├── mastodon-net-external.service 243 | │ └── mastodon-setup.service 244 | │    ├── mastodon-db.service 245 | │   ├── mastodon-es.service 246 | │   └── mastodon-redis.service 247 | │ └── mastodon-net-internal.service 248 | └── mastodon-web.service - Website, uses internal + external networking and DBs, listens to 127.0.0.1:5050. 249 | ├── mastodon-net-external.service 250 | └── mastodon-setup.service 251 |    ├── mastodon-db.service 252 |    ├── mastodon-es.service 253 |    └── mastodon-redis.service 254 | └── mastodon-net-internal.service 255 | 256 | caddy.service - Web server proxy and HTTPS termination. Takes care of certs, too. 257 | │  Proxies on external network to mastodon-web (127.0.0.1:5050) 258 | │  and mastodon-streaming (127.0.0.1:5051). 259 | └── mastodon-net-external.service - Docker user-defined network for external networking. 260 | ``` 261 | 262 | ### Start-up procedure 263 | 264 | 1. External and internal container networks are started first. 265 | 2. Databases (postgres, redis, and elasticsearch) are started as soon as the internal network is up. 266 | 3. The initial set-up script runs. 267 | This is a NOP for subsequent starts after installation. 268 | However, this stage is also useful for maintenance (see below). 269 | 4. Higher level services are starting: web, sidekiq, and streaming. 270 | 271 | -------------------------------------------------------------------------------- /monitoring/caddy.json: -------------------------------------------------------------------------------- 1 | { 2 | "annotations": { 3 | "list": [ 4 | { 5 | "builtIn": 1, 6 | "datasource": { 7 | "type": "datasource", 8 | "uid": "grafana" 9 | }, 10 | "enable": true, 11 | "hide": true, 12 | "iconColor": "rgba(0, 211, 255, 1)", 13 | "limit": 100, 14 | "name": "Annotations & Alerts", 15 | "showIn": 0, 16 | "target": { 17 | "limit": 100, 18 | "matchAny": false, 19 | "tags": [], 20 | "type": "dashboard" 21 | }, 22 | "type": "dashboard" 23 | } 24 | ] 25 | }, 26 | "editable": true, 27 | "fiscalYearStartMonth": 0, 28 | "gnetId": 13460, 29 | "graphTooltip": 0, 30 | "id": 9, 31 | "links": [], 32 | "liveNow": false, 33 | "panels": [ 34 | { 35 | "datasource": { 36 | "type": "prometheus", 37 | "uid": "PBFA97CFB590B2093" 38 | }, 39 | "fieldConfig": { 40 | "defaults": { 41 | "color": { 42 | "mode": "palette-classic" 43 | }, 44 | "custom": { 45 | "axisCenteredZero": false, 46 | "axisColorMode": "text", 47 | "axisLabel": "", 48 | "axisPlacement": "auto", 49 | "barAlignment": 0, 50 | "drawStyle": "line", 51 | "fillOpacity": 10, 52 | "gradientMode": "none", 53 | "hideFrom": { 54 | "legend": false, 55 | "tooltip": false, 56 | "viz": false 57 | }, 58 | "lineInterpolation": "linear", 59 | "lineWidth": 2, 60 | "pointSize": 5, 61 | "scaleDistribution": { 62 | "log": 10, 63 | "type": "log" 64 | }, 65 | "showPoints": "never", 66 | "spanNulls": false, 67 | "stacking": { 68 | "group": "A", 69 | "mode": "none" 70 | }, 71 | "thresholdsStyle": { 72 | "mode": "off" 73 | } 74 | }, 75 | "mappings": [], 76 | "thresholds": { 77 | "mode": "absolute", 78 | "steps": [ 79 | { 80 | "color": "green", 81 | "value": null 82 | }, 83 | { 84 | "color": "red", 85 | "value": 80 86 | } 87 | ] 88 | }, 89 | "unit": "short" 90 | }, 91 | "overrides": [] 92 | }, 93 | "gridPos": { 94 | "h": 9, 95 | "w": 12, 96 | "x": 0, 97 | "y": 0 98 | }, 99 | "id": 2, 100 | "options": { 101 | "legend": { 102 | "calcs": [ 103 | "last", 104 | "min", 105 | "max" 106 | ], 107 | "displayMode": "list", 108 | "placement": "bottom", 109 | "showLegend": true 110 | }, 111 | "tooltip": { 112 | "mode": "multi", 113 | "sort": "none" 114 | } 115 | }, 116 | "pluginVersion": "9.2.4", 117 | "targets": [ 118 | { 119 | "datasource": { 120 | "type": "prometheus", 121 | "uid": "PBFA97CFB590B2093" 122 | }, 123 | "editorMode": "code", 124 | "expr": "sum(rate(caddy_http_requests_total[1m]))", 125 | "interval": "", 126 | "legendFormat": "Requests", 127 | "range": true, 128 | "refId": "A" 129 | } 130 | ], 131 | "title": "Requests", 132 | "type": "timeseries" 133 | }, 134 | { 135 | "datasource": { 136 | "type": "prometheus", 137 | "uid": "PBFA97CFB590B2093" 138 | }, 139 | "description": "", 140 | "fieldConfig": { 141 | "defaults": { 142 | "color": { 143 | "mode": "palette-classic" 144 | }, 145 | "custom": { 146 | "axisCenteredZero": false, 147 | "axisColorMode": "text", 148 | "axisLabel": "", 149 | "axisPlacement": "auto", 150 | "barAlignment": 0, 151 | "drawStyle": "line", 152 | "fillOpacity": 10, 153 | "gradientMode": "none", 154 | "hideFrom": { 155 | "legend": false, 156 | "tooltip": false, 157 | "viz": false 158 | }, 159 | "lineInterpolation": "linear", 160 | "lineWidth": 2, 161 | "pointSize": 5, 162 | "scaleDistribution": { 163 | "type": "linear" 164 | }, 165 | "showPoints": "never", 166 | "spanNulls": false, 167 | "stacking": { 168 | "group": "A", 169 | "mode": "normal" 170 | }, 171 | "thresholdsStyle": { 172 | "mode": "off" 173 | } 174 | }, 175 | "mappings": [], 176 | "thresholds": { 177 | "mode": "absolute", 178 | "steps": [ 179 | { 180 | "color": "green", 181 | "value": null 182 | }, 183 | { 184 | "color": "red", 185 | "value": 80 186 | } 187 | ] 188 | }, 189 | "unit": "short" 190 | }, 191 | "overrides": [] 192 | }, 193 | "gridPos": { 194 | "h": 9, 195 | "w": 12, 196 | "x": 12, 197 | "y": 0 198 | }, 199 | "id": 7, 200 | "options": { 201 | "legend": { 202 | "calcs": [ 203 | "last", 204 | "mean" 205 | ], 206 | "displayMode": "table", 207 | "placement": "right", 208 | "showLegend": true 209 | }, 210 | "tooltip": { 211 | "mode": "multi", 212 | "sort": "none" 213 | } 214 | }, 215 | "pluginVersion": "9.2.4", 216 | "targets": [ 217 | { 218 | "datasource": { 219 | "type": "prometheus", 220 | "uid": "PBFA97CFB590B2093" 221 | }, 222 | "editorMode": "code", 223 | "expr": "sum(irate(caddy_http_request_duration_seconds_count[1m])) by (code)", 224 | "interval": "", 225 | "legendFormat": "{{code}}", 226 | "range": true, 227 | "refId": "A" 228 | } 229 | ], 230 | "title": "Requests by Response Code", 231 | "type": "timeseries" 232 | }, 233 | { 234 | "datasource": { 235 | "type": "prometheus", 236 | "uid": "PBFA97CFB590B2093" 237 | }, 238 | "fieldConfig": { 239 | "defaults": { 240 | "color": { 241 | "mode": "palette-classic" 242 | }, 243 | "custom": { 244 | "axisCenteredZero": false, 245 | "axisColorMode": "text", 246 | "axisLabel": "", 247 | "axisPlacement": "auto", 248 | "barAlignment": 0, 249 | "drawStyle": "line", 250 | "fillOpacity": 10, 251 | "gradientMode": "none", 252 | "hideFrom": { 253 | "legend": false, 254 | "tooltip": false, 255 | "viz": false 256 | }, 257 | "lineInterpolation": "linear", 258 | "lineWidth": 2, 259 | "pointSize": 5, 260 | "scaleDistribution": { 261 | "type": "linear" 262 | }, 263 | "showPoints": "never", 264 | "spanNulls": false, 265 | "stacking": { 266 | "group": "A", 267 | "mode": "none" 268 | }, 269 | "thresholdsStyle": { 270 | "mode": "off" 271 | } 272 | }, 273 | "mappings": [], 274 | "thresholds": { 275 | "mode": "absolute", 276 | "steps": [ 277 | { 278 | "color": "green", 279 | "value": null 280 | }, 281 | { 282 | "color": "red", 283 | "value": 80 284 | } 285 | ] 286 | }, 287 | "unit": "short" 288 | }, 289 | "overrides": [] 290 | }, 291 | "gridPos": { 292 | "h": 9, 293 | "w": 12, 294 | "x": 0, 295 | "y": 9 296 | }, 297 | "id": 8, 298 | "options": { 299 | "legend": { 300 | "calcs": [], 301 | "displayMode": "list", 302 | "placement": "bottom", 303 | "showLegend": false 304 | }, 305 | "tooltip": { 306 | "mode": "multi", 307 | "sort": "none" 308 | } 309 | }, 310 | "pluginVersion": "9.2.4", 311 | "targets": [ 312 | { 313 | "datasource": { 314 | "type": "prometheus", 315 | "uid": "PBFA97CFB590B2093" 316 | }, 317 | "editorMode": "code", 318 | "expr": "avg(avg_over_time(caddy_http_requests_in_flight[1m]))", 319 | "hide": false, 320 | "interval": "", 321 | "legendFormat": "", 322 | "range": true, 323 | "refId": "E" 324 | } 325 | ], 326 | "title": "Requests In Flight", 327 | "type": "timeseries" 328 | }, 329 | { 330 | "datasource": { 331 | "type": "prometheus", 332 | "uid": "PBFA97CFB590B2093" 333 | }, 334 | "description": "", 335 | "fieldConfig": { 336 | "defaults": { 337 | "color": { 338 | "mode": "palette-classic" 339 | }, 340 | "custom": { 341 | "axisCenteredZero": false, 342 | "axisColorMode": "text", 343 | "axisLabel": "", 344 | "axisPlacement": "auto", 345 | "barAlignment": 0, 346 | "drawStyle": "bars", 347 | "fillOpacity": 100, 348 | "gradientMode": "none", 349 | "hideFrom": { 350 | "legend": false, 351 | "tooltip": false, 352 | "viz": false 353 | }, 354 | "lineInterpolation": "linear", 355 | "lineWidth": 2, 356 | "pointSize": 5, 357 | "scaleDistribution": { 358 | "type": "linear" 359 | }, 360 | "showPoints": "never", 361 | "spanNulls": false, 362 | "stacking": { 363 | "group": "A", 364 | "mode": "normal" 365 | }, 366 | "thresholdsStyle": { 367 | "mode": "off" 368 | } 369 | }, 370 | "mappings": [], 371 | "min": 0, 372 | "thresholds": { 373 | "mode": "absolute", 374 | "steps": [ 375 | { 376 | "color": "green", 377 | "value": null 378 | }, 379 | { 380 | "color": "red", 381 | "value": 80 382 | } 383 | ] 384 | }, 385 | "unit": "none" 386 | }, 387 | "overrides": [] 388 | }, 389 | "gridPos": { 390 | "h": 9, 391 | "w": 12, 392 | "x": 12, 393 | "y": 9 394 | }, 395 | "id": 5, 396 | "options": { 397 | "legend": { 398 | "calcs": [ 399 | "last" 400 | ], 401 | "displayMode": "table", 402 | "placement": "right", 403 | "showLegend": true 404 | }, 405 | "tooltip": { 406 | "mode": "multi", 407 | "sort": "none" 408 | } 409 | }, 410 | "pluginVersion": "9.2.4", 411 | "targets": [ 412 | { 413 | "datasource": { 414 | "type": "prometheus", 415 | "uid": "PBFA97CFB590B2093" 416 | }, 417 | "editorMode": "code", 418 | "expr": "sum(irate(caddy_http_request_duration_seconds_count[1m])) by (code)", 419 | "interval": "", 420 | "legendFormat": "{{code}}", 421 | "range": true, 422 | "refId": "A" 423 | } 424 | ], 425 | "title": "Requests by Response Code (%)", 426 | "type": "timeseries" 427 | }, 428 | { 429 | "datasource": { 430 | "type": "prometheus", 431 | "uid": "PBFA97CFB590B2093" 432 | }, 433 | "fieldConfig": { 434 | "defaults": { 435 | "color": { 436 | "mode": "palette-classic" 437 | }, 438 | "custom": { 439 | "axisCenteredZero": false, 440 | "axisColorMode": "text", 441 | "axisLabel": "", 442 | "axisPlacement": "auto", 443 | "barAlignment": 0, 444 | "drawStyle": "line", 445 | "fillOpacity": 10, 446 | "gradientMode": "none", 447 | "hideFrom": { 448 | "legend": false, 449 | "tooltip": false, 450 | "viz": false 451 | }, 452 | "lineInterpolation": "linear", 453 | "lineWidth": 2, 454 | "pointSize": 5, 455 | "scaleDistribution": { 456 | "log": 2, 457 | "type": "log" 458 | }, 459 | "showPoints": "never", 460 | "spanNulls": false, 461 | "stacking": { 462 | "group": "A", 463 | "mode": "none" 464 | }, 465 | "thresholdsStyle": { 466 | "mode": "off" 467 | } 468 | }, 469 | "mappings": [], 470 | "thresholds": { 471 | "mode": "absolute", 472 | "steps": [ 473 | { 474 | "color": "green", 475 | "value": null 476 | }, 477 | { 478 | "color": "red", 479 | "value": 80 480 | } 481 | ] 482 | }, 483 | "unit": "s" 484 | }, 485 | "overrides": [] 486 | }, 487 | "gridPos": { 488 | "h": 9, 489 | "w": 12, 490 | "x": 0, 491 | "y": 18 492 | }, 493 | "id": 4, 494 | "options": { 495 | "legend": { 496 | "calcs": [ 497 | "last" 498 | ], 499 | "displayMode": "table", 500 | "placement": "right", 501 | "showLegend": true 502 | }, 503 | "tooltip": { 504 | "mode": "multi", 505 | "sort": "none" 506 | } 507 | }, 508 | "pluginVersion": "9.2.4", 509 | "targets": [ 510 | { 511 | "datasource": { 512 | "type": "prometheus", 513 | "uid": "PBFA97CFB590B2093" 514 | }, 515 | "editorMode": "code", 516 | "expr": "histogram_quantile(0.99, sum(rate(caddy_http_request_duration_seconds_bucket[1m])) by (le))", 517 | "interval": "", 518 | "legendFormat": "p99", 519 | "range": true, 520 | "refId": "A" 521 | }, 522 | { 523 | "datasource": { 524 | "type": "prometheus", 525 | "uid": "PBFA97CFB590B2093" 526 | }, 527 | "editorMode": "code", 528 | "expr": "histogram_quantile(0.95, sum(rate(caddy_http_request_duration_seconds_bucket[1m])) by (le))", 529 | "interval": "", 530 | "legendFormat": "p95", 531 | "range": true, 532 | "refId": "B" 533 | }, 534 | { 535 | "datasource": { 536 | "type": "prometheus", 537 | "uid": "PBFA97CFB590B2093" 538 | }, 539 | "editorMode": "code", 540 | "expr": "histogram_quantile(0.90, sum(rate(caddy_http_request_duration_seconds_bucket[1m])) by (le))", 541 | "interval": "", 542 | "legendFormat": "p90", 543 | "range": true, 544 | "refId": "C" 545 | }, 546 | { 547 | "datasource": { 548 | "type": "prometheus", 549 | "uid": "PBFA97CFB590B2093" 550 | }, 551 | "editorMode": "code", 552 | "expr": "histogram_quantile(0.75, sum(rate(caddy_http_request_duration_seconds_bucket[1m])) by (le))", 553 | "interval": "", 554 | "legendFormat": "p75", 555 | "range": true, 556 | "refId": "D" 557 | }, 558 | { 559 | "datasource": { 560 | "type": "prometheus", 561 | "uid": "PBFA97CFB590B2093" 562 | }, 563 | "editorMode": "code", 564 | "expr": "histogram_quantile(0.5, sum(rate(caddy_http_request_duration_seconds_bucket[1m])) by (le))", 565 | "interval": "", 566 | "legendFormat": "p50", 567 | "range": true, 568 | "refId": "E" 569 | } 570 | ], 571 | "title": "Request Duration (percentile)", 572 | "type": "timeseries" 573 | }, 574 | { 575 | "cards": {}, 576 | "color": { 577 | "cardColor": "#b4ff00", 578 | "colorScale": "linear", 579 | "colorScheme": "interpolateInferno", 580 | "exponent": 0.5, 581 | "mode": "spectrum" 582 | }, 583 | "dataFormat": "tsbuckets", 584 | "datasource": { 585 | "type": "prometheus", 586 | "uid": "PBFA97CFB590B2093" 587 | }, 588 | "fieldConfig": { 589 | "defaults": { 590 | "custom": { 591 | "hideFrom": { 592 | "legend": false, 593 | "tooltip": false, 594 | "viz": false 595 | }, 596 | "scaleDistribution": { 597 | "type": "linear" 598 | } 599 | } 600 | }, 601 | "overrides": [] 602 | }, 603 | "gridPos": { 604 | "h": 9, 605 | "w": 12, 606 | "x": 12, 607 | "y": 18 608 | }, 609 | "heatmap": {}, 610 | "hideZeroBuckets": true, 611 | "highlightCards": true, 612 | "id": 6, 613 | "interval": "", 614 | "legend": { 615 | "show": true 616 | }, 617 | "maxDataPoints": 25, 618 | "options": { 619 | "calculate": false, 620 | "calculation": {}, 621 | "cellGap": 2, 622 | "cellValues": {}, 623 | "color": { 624 | "exponent": 0.5, 625 | "fill": "#b4ff00", 626 | "mode": "scheme", 627 | "reverse": false, 628 | "scale": "exponential", 629 | "scheme": "Inferno", 630 | "steps": 128 631 | }, 632 | "exemplars": { 633 | "color": "rgba(255,0,255,0.7)" 634 | }, 635 | "filterValues": { 636 | "le": 1e-9 637 | }, 638 | "legend": { 639 | "show": true 640 | }, 641 | "rowsFrame": { 642 | "layout": "auto" 643 | }, 644 | "showValue": "never", 645 | "tooltip": { 646 | "show": true, 647 | "yHistogram": false 648 | }, 649 | "yAxis": { 650 | "axisPlacement": "left", 651 | "reverse": false, 652 | "unit": "s" 653 | } 654 | }, 655 | "pluginVersion": "9.2.4", 656 | "reverseYBuckets": false, 657 | "targets": [ 658 | { 659 | "datasource": { 660 | "type": "prometheus", 661 | "uid": "PBFA97CFB590B2093" 662 | }, 663 | "editorMode": "code", 664 | "expr": "sum(increase(caddy_http_request_duration_seconds_bucket{}[5m])) by (le)", 665 | "format": "heatmap", 666 | "interval": "", 667 | "legendFormat": "{{le}}", 668 | "range": true, 669 | "refId": "A" 670 | } 671 | ], 672 | "title": "Request Duration (heatmap)", 673 | "tooltip": { 674 | "show": true, 675 | "showHistogram": false 676 | }, 677 | "type": "heatmap", 678 | "xAxis": { 679 | "show": true 680 | }, 681 | "yAxis": { 682 | "format": "s", 683 | "logBase": 1, 684 | "show": true 685 | }, 686 | "yBucketBound": "auto" 687 | } 688 | ], 689 | "refresh": "10s", 690 | "schemaVersion": 37, 691 | "style": "dark", 692 | "tags": [ 693 | "http", 694 | "caddy", 695 | "prometheus" 696 | ], 697 | "templating": { 698 | "list": [] 699 | }, 700 | "time": { 701 | "from": "now-5m", 702 | "to": "now" 703 | }, 704 | "timepicker": { 705 | "refresh_intervals": [ 706 | "10s", 707 | "30s", 708 | "1m", 709 | "5m", 710 | "15m", 711 | "30m", 712 | "1h", 713 | "2h", 714 | "1d" 715 | ] 716 | }, 717 | "timezone": "", 718 | "title": "Caddy", 719 | "uid": "TZBbz9TMk", 720 | "version": 3, 721 | "weekStart": "" 722 | } -------------------------------------------------------------------------------- /monitoring/sidekiq.json: -------------------------------------------------------------------------------- 1 | { 2 | "annotations": { 3 | "list": [ 4 | { 5 | "builtIn": 1, 6 | "datasource": { 7 | "type": "datasource", 8 | "uid": "grafana" 9 | }, 10 | "enable": true, 11 | "hide": true, 12 | "iconColor": "rgba(0, 211, 255, 1)", 13 | "name": "Annotations & Alerts", 14 | "target": { 15 | "limit": 100, 16 | "matchAny": false, 17 | "tags": [], 18 | "type": "dashboard" 19 | }, 20 | "type": "dashboard" 21 | } 22 | ] 23 | }, 24 | "editable": true, 25 | "fiscalYearStartMonth": 0, 26 | "graphTooltip": 0, 27 | "id": 5, 28 | "links": [], 29 | "liveNow": false, 30 | "panels": [ 31 | { 32 | "datasource": { 33 | "type": "prometheus", 34 | "uid": "PBFA97CFB590B2093" 35 | }, 36 | "fieldConfig": { 37 | "defaults": { 38 | "mappings": [ 39 | { 40 | "options": { 41 | "match": "null", 42 | "result": { 43 | "text": "N/A" 44 | } 45 | }, 46 | "type": "special" 47 | } 48 | ], 49 | "thresholds": { 50 | "mode": "absolute", 51 | "steps": [ 52 | { 53 | "color": "green", 54 | "value": null 55 | }, 56 | { 57 | "color": "red", 58 | "value": 200 59 | } 60 | ] 61 | }, 62 | "unit": "none" 63 | }, 64 | "overrides": [] 65 | }, 66 | "gridPos": { 67 | "h": 4, 68 | "w": 3, 69 | "x": 0, 70 | "y": 0 71 | }, 72 | "id": 4, 73 | "links": [], 74 | "maxDataPoints": 100, 75 | "options": { 76 | "colorMode": "value", 77 | "fieldOptions": { 78 | "calcs": [ 79 | "lastNotNull" 80 | ] 81 | }, 82 | "graphMode": "area", 83 | "justifyMode": "auto", 84 | "orientation": "horizontal", 85 | "reduceOptions": { 86 | "calcs": [ 87 | "last" 88 | ], 89 | "fields": "", 90 | "values": false 91 | }, 92 | "textMode": "auto" 93 | }, 94 | "pluginVersion": "9.2.4", 95 | "targets": [ 96 | { 97 | "datasource": { 98 | "type": "prometheus", 99 | "uid": "${DS_PROMETHEUS}" 100 | }, 101 | "editorMode": "code", 102 | "exemplar": false, 103 | "expr": "sidekiq_processes", 104 | "hide": false, 105 | "instant": true, 106 | "legendFormat": "Processes", 107 | "range": false, 108 | "refId": "B" 109 | }, 110 | { 111 | "datasource": { 112 | "type": "prometheus", 113 | "uid": "${DS_PROMETHEUS}" 114 | }, 115 | "editorMode": "code", 116 | "expr": "sidekiq_workers", 117 | "format": "time_series", 118 | "instant": true, 119 | "interval": "", 120 | "intervalFactor": 1, 121 | "legendFormat": "Workers", 122 | "refId": "A" 123 | } 124 | ], 125 | "type": "stat" 126 | }, 127 | { 128 | "datasource": { 129 | "type": "prometheus", 130 | "uid": "PBFA97CFB590B2093" 131 | }, 132 | "fieldConfig": { 133 | "defaults": { 134 | "mappings": [ 135 | { 136 | "options": { 137 | "match": "null", 138 | "result": { 139 | "text": "N/A" 140 | } 141 | }, 142 | "type": "special" 143 | } 144 | ], 145 | "thresholds": { 146 | "mode": "absolute", 147 | "steps": [ 148 | { 149 | "color": "green", 150 | "value": null 151 | }, 152 | { 153 | "color": "red", 154 | "value": 200 155 | } 156 | ] 157 | }, 158 | "unit": "none" 159 | }, 160 | "overrides": [] 161 | }, 162 | "gridPos": { 163 | "h": 4, 164 | "w": 5, 165 | "x": 3, 166 | "y": 0 167 | }, 168 | "id": 21, 169 | "links": [], 170 | "maxDataPoints": 100, 171 | "options": { 172 | "colorMode": "value", 173 | "fieldOptions": { 174 | "calcs": [ 175 | "lastNotNull" 176 | ] 177 | }, 178 | "graphMode": "area", 179 | "justifyMode": "auto", 180 | "orientation": "horizontal", 181 | "reduceOptions": { 182 | "calcs": [ 183 | "last" 184 | ], 185 | "fields": "", 186 | "values": false 187 | }, 188 | "textMode": "auto" 189 | }, 190 | "pluginVersion": "9.2.4", 191 | "targets": [ 192 | { 193 | "datasource": { 194 | "type": "prometheus", 195 | "uid": "${DS_PROMETHEUS}" 196 | }, 197 | "editorMode": "code", 198 | "exemplar": false, 199 | "expr": "sidekiq_processed_jobs_total", 200 | "hide": false, 201 | "instant": true, 202 | "legendFormat": "Total processed", 203 | "range": false, 204 | "refId": "B" 205 | }, 206 | { 207 | "datasource": { 208 | "type": "prometheus", 209 | "uid": "${DS_PROMETHEUS}" 210 | }, 211 | "editorMode": "code", 212 | "expr": "sidekiq_failed_jobs_total", 213 | "format": "time_series", 214 | "instant": true, 215 | "interval": "", 216 | "intervalFactor": 1, 217 | "legendFormat": "Total failed", 218 | "refId": "A" 219 | } 220 | ], 221 | "type": "stat" 222 | }, 223 | { 224 | "datasource": {}, 225 | "fieldConfig": { 226 | "defaults": { 227 | "mappings": [ 228 | { 229 | "options": { 230 | "match": "null", 231 | "result": { 232 | "text": "N/A" 233 | } 234 | }, 235 | "type": "special" 236 | } 237 | ], 238 | "thresholds": { 239 | "mode": "absolute", 240 | "steps": [ 241 | { 242 | "color": "green", 243 | "value": null 244 | }, 245 | { 246 | "color": "red", 247 | "value": 80 248 | } 249 | ] 250 | }, 251 | "unit": "none" 252 | }, 253 | "overrides": [] 254 | }, 255 | "gridPos": { 256 | "h": 4, 257 | "w": 2, 258 | "x": 8, 259 | "y": 0 260 | }, 261 | "id": 6, 262 | "links": [], 263 | "maxDataPoints": 100, 264 | "options": { 265 | "colorMode": "value", 266 | "fieldOptions": { 267 | "calcs": [ 268 | "lastNotNull" 269 | ] 270 | }, 271 | "graphMode": "area", 272 | "justifyMode": "auto", 273 | "orientation": "horizontal", 274 | "reduceOptions": { 275 | "calcs": [ 276 | "mean" 277 | ], 278 | "fields": "", 279 | "values": false 280 | }, 281 | "textMode": "auto" 282 | }, 283 | "pluginVersion": "9.2.4", 284 | "targets": [ 285 | { 286 | "datasource": { 287 | "type": "prometheus", 288 | "uid": "${DS_PROMETHEUS}" 289 | }, 290 | "editorMode": "code", 291 | "expr": "sidekiq_scheduled_jobs", 292 | "format": "time_series", 293 | "instant": true, 294 | "interval": "", 295 | "intervalFactor": 1, 296 | "legendFormat": "", 297 | "refId": "A" 298 | } 299 | ], 300 | "title": "Scheduled jobs", 301 | "type": "stat" 302 | }, 303 | { 304 | "datasource": {}, 305 | "fieldConfig": { 306 | "defaults": { 307 | "mappings": [ 308 | { 309 | "options": { 310 | "match": "null", 311 | "result": { 312 | "text": "N/A" 313 | } 314 | }, 315 | "type": "special" 316 | } 317 | ], 318 | "thresholds": { 319 | "mode": "absolute", 320 | "steps": [ 321 | { 322 | "color": "green", 323 | "value": null 324 | }, 325 | { 326 | "color": "red", 327 | "value": 80 328 | } 329 | ] 330 | }, 331 | "unit": "none" 332 | }, 333 | "overrides": [] 334 | }, 335 | "gridPos": { 336 | "h": 4, 337 | "w": 2, 338 | "x": 10, 339 | "y": 0 340 | }, 341 | "id": 13, 342 | "links": [], 343 | "maxDataPoints": 100, 344 | "options": { 345 | "colorMode": "value", 346 | "fieldOptions": { 347 | "calcs": [ 348 | "lastNotNull" 349 | ] 350 | }, 351 | "graphMode": "area", 352 | "justifyMode": "auto", 353 | "orientation": "horizontal", 354 | "reduceOptions": { 355 | "calcs": [ 356 | "mean" 357 | ], 358 | "fields": "", 359 | "values": false 360 | }, 361 | "textMode": "auto" 362 | }, 363 | "pluginVersion": "9.2.4", 364 | "targets": [ 365 | { 366 | "datasource": { 367 | "type": "prometheus", 368 | "uid": "${DS_PROMETHEUS}" 369 | }, 370 | "editorMode": "code", 371 | "expr": "rate(sidekiq_processed_jobs_total[1m])", 372 | "format": "time_series", 373 | "instant": true, 374 | "interval": "", 375 | "intervalFactor": 1, 376 | "legendFormat": "", 377 | "refId": "A" 378 | } 379 | ], 380 | "title": "Processing rate", 381 | "type": "stat" 382 | }, 383 | { 384 | "datasource": {}, 385 | "fieldConfig": { 386 | "defaults": { 387 | "mappings": [ 388 | { 389 | "options": { 390 | "match": "null", 391 | "result": { 392 | "text": "N/A" 393 | } 394 | }, 395 | "type": "special" 396 | } 397 | ], 398 | "thresholds": { 399 | "mode": "absolute", 400 | "steps": [ 401 | { 402 | "color": "green", 403 | "value": null 404 | }, 405 | { 406 | "color": "red", 407 | "value": 80 408 | } 409 | ] 410 | }, 411 | "unit": "none" 412 | }, 413 | "overrides": [] 414 | }, 415 | "gridPos": { 416 | "h": 4, 417 | "w": 2, 418 | "x": 12, 419 | "y": 0 420 | }, 421 | "id": 12, 422 | "links": [], 423 | "maxDataPoints": 100, 424 | "options": { 425 | "colorMode": "value", 426 | "fieldOptions": { 427 | "calcs": [ 428 | "lastNotNull" 429 | ] 430 | }, 431 | "graphMode": "area", 432 | "justifyMode": "auto", 433 | "orientation": "horizontal", 434 | "reduceOptions": { 435 | "calcs": [ 436 | "mean" 437 | ], 438 | "fields": "", 439 | "values": false 440 | }, 441 | "textMode": "auto" 442 | }, 443 | "pluginVersion": "9.2.4", 444 | "targets": [ 445 | { 446 | "datasource": { 447 | "type": "prometheus", 448 | "uid": "${DS_PROMETHEUS}" 449 | }, 450 | "editorMode": "code", 451 | "expr": "rate(sidekiq_enqueued_jobs[1m])", 452 | "format": "time_series", 453 | "instant": true, 454 | "interval": "", 455 | "intervalFactor": 1, 456 | "legendFormat": "", 457 | "refId": "A" 458 | } 459 | ], 460 | "title": "Enqueuing rate", 461 | "type": "stat" 462 | }, 463 | { 464 | "datasource": {}, 465 | "fieldConfig": { 466 | "defaults": { 467 | "mappings": [ 468 | { 469 | "options": { 470 | "match": "null", 471 | "result": { 472 | "text": "N/A" 473 | } 474 | }, 475 | "type": "special" 476 | } 477 | ], 478 | "thresholds": { 479 | "mode": "absolute", 480 | "steps": [ 481 | { 482 | "color": "#299c46", 483 | "value": null 484 | }, 485 | { 486 | "color": "rgba(237, 129, 40, 0.89)", 487 | "value": 1 488 | }, 489 | { 490 | "color": "#d44a3a", 491 | "value": 10 492 | } 493 | ] 494 | }, 495 | "unit": "none" 496 | }, 497 | "overrides": [] 498 | }, 499 | "gridPos": { 500 | "h": 4, 501 | "w": 2, 502 | "x": 14, 503 | "y": 0 504 | }, 505 | "id": 10, 506 | "links": [], 507 | "maxDataPoints": 100, 508 | "options": { 509 | "colorMode": "value", 510 | "fieldOptions": { 511 | "calcs": [ 512 | "lastNotNull" 513 | ] 514 | }, 515 | "graphMode": "area", 516 | "justifyMode": "auto", 517 | "orientation": "horizontal", 518 | "reduceOptions": { 519 | "calcs": [ 520 | "mean" 521 | ], 522 | "fields": "", 523 | "values": false 524 | }, 525 | "textMode": "auto" 526 | }, 527 | "pluginVersion": "9.2.4", 528 | "targets": [ 529 | { 530 | "datasource": { 531 | "type": "prometheus", 532 | "uid": "${DS_PROMETHEUS}" 533 | }, 534 | "editorMode": "code", 535 | "expr": "increase(sidekiq_failed_jobs_total[1m])", 536 | "format": "time_series", 537 | "instant": true, 538 | "interval": "", 539 | "intervalFactor": 1, 540 | "legendFormat": "", 541 | "refId": "A" 542 | } 543 | ], 544 | "title": "Failed growth", 545 | "type": "stat" 546 | }, 547 | { 548 | "datasource": {}, 549 | "fieldConfig": { 550 | "defaults": { 551 | "mappings": [ 552 | { 553 | "options": { 554 | "match": "null", 555 | "result": { 556 | "text": "N/A" 557 | } 558 | }, 559 | "type": "special" 560 | } 561 | ], 562 | "thresholds": { 563 | "mode": "absolute", 564 | "steps": [ 565 | { 566 | "color": "#299c46", 567 | "value": null 568 | }, 569 | { 570 | "color": "rgba(237, 129, 40, 0.89)", 571 | "value": 1 572 | }, 573 | { 574 | "color": "#d44a3a", 575 | "value": 10 576 | } 577 | ] 578 | }, 579 | "unit": "none" 580 | }, 581 | "overrides": [] 582 | }, 583 | "gridPos": { 584 | "h": 4, 585 | "w": 3, 586 | "x": 16, 587 | "y": 0 588 | }, 589 | "id": 14, 590 | "links": [], 591 | "maxDataPoints": 100, 592 | "options": { 593 | "colorMode": "value", 594 | "fieldOptions": { 595 | "calcs": [ 596 | "lastNotNull" 597 | ] 598 | }, 599 | "graphMode": "area", 600 | "justifyMode": "auto", 601 | "orientation": "horizontal", 602 | "reduceOptions": { 603 | "calcs": [ 604 | "mean" 605 | ], 606 | "fields": "", 607 | "values": false 608 | }, 609 | "textMode": "auto" 610 | }, 611 | "pluginVersion": "9.2.4", 612 | "targets": [ 613 | { 614 | "datasource": { 615 | "type": "prometheus", 616 | "uid": "${DS_PROMETHEUS}" 617 | }, 618 | "editorMode": "code", 619 | "expr": "sidekiq_retry_jobs", 620 | "format": "time_series", 621 | "instant": true, 622 | "interval": "", 623 | "intervalFactor": 1, 624 | "legendFormat": "", 625 | "refId": "A" 626 | } 627 | ], 628 | "title": "Retry jobs", 629 | "type": "stat" 630 | }, 631 | { 632 | "datasource": {}, 633 | "fieldConfig": { 634 | "defaults": { 635 | "mappings": [ 636 | { 637 | "options": { 638 | "match": "null", 639 | "result": { 640 | "text": "N/A" 641 | } 642 | }, 643 | "type": "special" 644 | } 645 | ], 646 | "thresholds": { 647 | "mode": "absolute", 648 | "steps": [ 649 | { 650 | "color": "#299c46", 651 | "value": null 652 | }, 653 | { 654 | "color": "rgba(237, 129, 40, 0.89)", 655 | "value": 10 656 | }, 657 | { 658 | "color": "#d44a3a", 659 | "value": 20 660 | } 661 | ] 662 | }, 663 | "unit": "none" 664 | }, 665 | "overrides": [] 666 | }, 667 | "gridPos": { 668 | "h": 4, 669 | "w": 3, 670 | "x": 19, 671 | "y": 0 672 | }, 673 | "id": 8, 674 | "links": [], 675 | "maxDataPoints": 100, 676 | "options": { 677 | "colorMode": "value", 678 | "fieldOptions": { 679 | "calcs": [ 680 | "lastNotNull" 681 | ] 682 | }, 683 | "graphMode": "area", 684 | "justifyMode": "auto", 685 | "orientation": "horizontal", 686 | "reduceOptions": { 687 | "calcs": [ 688 | "mean" 689 | ], 690 | "fields": "", 691 | "values": false 692 | }, 693 | "textMode": "auto" 694 | }, 695 | "pluginVersion": "9.2.4", 696 | "targets": [ 697 | { 698 | "datasource": { 699 | "type": "prometheus", 700 | "uid": "${DS_PROMETHEUS}" 701 | }, 702 | "editorMode": "code", 703 | "expr": "sidekiq_dead_jobs", 704 | "format": "time_series", 705 | "instant": true, 706 | "interval": "", 707 | "intervalFactor": 1, 708 | "legendFormat": "", 709 | "refId": "A" 710 | } 711 | ], 712 | "title": "Dead jobs", 713 | "type": "stat" 714 | }, 715 | { 716 | "datasource": { 717 | "type": "prometheus", 718 | "uid": "PBFA97CFB590B2093" 719 | }, 720 | "fieldConfig": { 721 | "defaults": { 722 | "color": { 723 | "mode": "palette-classic" 724 | }, 725 | "custom": { 726 | "axisCenteredZero": false, 727 | "axisColorMode": "text", 728 | "axisLabel": "", 729 | "axisPlacement": "auto", 730 | "axisSoftMin": 0, 731 | "barAlignment": 0, 732 | "drawStyle": "line", 733 | "fillOpacity": 9, 734 | "gradientMode": "none", 735 | "hideFrom": { 736 | "legend": false, 737 | "tooltip": false, 738 | "viz": false 739 | }, 740 | "lineInterpolation": "smooth", 741 | "lineWidth": 1, 742 | "pointSize": 5, 743 | "scaleDistribution": { 744 | "type": "linear" 745 | }, 746 | "showPoints": "auto", 747 | "spanNulls": false, 748 | "stacking": { 749 | "group": "A", 750 | "mode": "none" 751 | }, 752 | "thresholdsStyle": { 753 | "mode": "off" 754 | } 755 | }, 756 | "mappings": [], 757 | "thresholds": { 758 | "mode": "absolute", 759 | "steps": [ 760 | { 761 | "color": "green", 762 | "value": null 763 | }, 764 | { 765 | "color": "#EAB839", 766 | "value": 50 767 | }, 768 | { 769 | "color": "red", 770 | "value": 100 771 | } 772 | ] 773 | } 774 | }, 775 | "overrides": [ 776 | { 777 | "matcher": { 778 | "id": "byName", 779 | "options": "Failed" 780 | }, 781 | "properties": [ 782 | { 783 | "id": "color", 784 | "value": { 785 | "fixedColor": "dark-red", 786 | "mode": "fixed" 787 | } 788 | } 789 | ] 790 | } 791 | ] 792 | }, 793 | "gridPos": { 794 | "h": 7, 795 | "w": 11, 796 | "x": 0, 797 | "y": 4 798 | }, 799 | "id": 20, 800 | "options": { 801 | "legend": { 802 | "calcs": [ 803 | "last" 804 | ], 805 | "displayMode": "table", 806 | "placement": "right", 807 | "showLegend": true 808 | }, 809 | "tooltip": { 810 | "mode": "single", 811 | "sort": "none" 812 | } 813 | }, 814 | "targets": [ 815 | { 816 | "datasource": { 817 | "type": "prometheus", 818 | "uid": "${DS_PROMETHEUS}" 819 | }, 820 | "editorMode": "code", 821 | "exemplar": false, 822 | "expr": "increase(sidekiq_processed_jobs_total[10s])", 823 | "interval": "", 824 | "legendFormat": "Processed", 825 | "range": true, 826 | "refId": "A" 827 | }, 828 | { 829 | "datasource": { 830 | "type": "prometheus", 831 | "uid": "${DS_PROMETHEUS}" 832 | }, 833 | "editorMode": "code", 834 | "expr": "increase(sidekiq_failed_jobs_total[10s])", 835 | "hide": false, 836 | "legendFormat": "Failed", 837 | "range": true, 838 | "refId": "B" 839 | } 840 | ], 841 | "title": "10s average", 842 | "type": "timeseries" 843 | }, 844 | { 845 | "datasource": { 846 | "type": "prometheus", 847 | "uid": "PBFA97CFB590B2093" 848 | }, 849 | "fieldConfig": { 850 | "defaults": { 851 | "color": { 852 | "mode": "palette-classic" 853 | }, 854 | "custom": { 855 | "axisCenteredZero": false, 856 | "axisColorMode": "text", 857 | "axisLabel": "", 858 | "axisPlacement": "auto", 859 | "axisSoftMin": 0, 860 | "barAlignment": 0, 861 | "drawStyle": "line", 862 | "fillOpacity": 9, 863 | "gradientMode": "none", 864 | "hideFrom": { 865 | "legend": false, 866 | "tooltip": false, 867 | "viz": false 868 | }, 869 | "lineInterpolation": "smooth", 870 | "lineWidth": 1, 871 | "pointSize": 5, 872 | "scaleDistribution": { 873 | "type": "linear" 874 | }, 875 | "showPoints": "auto", 876 | "spanNulls": false, 877 | "stacking": { 878 | "group": "A", 879 | "mode": "none" 880 | }, 881 | "thresholdsStyle": { 882 | "mode": "off" 883 | } 884 | }, 885 | "mappings": [], 886 | "thresholds": { 887 | "mode": "absolute", 888 | "steps": [ 889 | { 890 | "color": "green", 891 | "value": null 892 | }, 893 | { 894 | "color": "#EAB839", 895 | "value": 50 896 | }, 897 | { 898 | "color": "red", 899 | "value": 100 900 | } 901 | ] 902 | } 903 | }, 904 | "overrides": [ 905 | { 906 | "matcher": { 907 | "id": "byName", 908 | "options": "Failed" 909 | }, 910 | "properties": [ 911 | { 912 | "id": "color", 913 | "value": { 914 | "fixedColor": "dark-red", 915 | "mode": "fixed" 916 | } 917 | } 918 | ] 919 | } 920 | ] 921 | }, 922 | "gridPos": { 923 | "h": 7, 924 | "w": 11, 925 | "x": 11, 926 | "y": 4 927 | }, 928 | "id": 19, 929 | "options": { 930 | "legend": { 931 | "calcs": [ 932 | "last" 933 | ], 934 | "displayMode": "table", 935 | "placement": "right", 936 | "showLegend": true 937 | }, 938 | "tooltip": { 939 | "mode": "single", 940 | "sort": "none" 941 | } 942 | }, 943 | "targets": [ 944 | { 945 | "datasource": { 946 | "type": "prometheus", 947 | "uid": "${DS_PROMETHEUS}" 948 | }, 949 | "editorMode": "code", 950 | "exemplar": false, 951 | "expr": "increase(sidekiq_processed_jobs_total[1d])", 952 | "interval": "", 953 | "legendFormat": "Processed", 954 | "range": true, 955 | "refId": "A" 956 | }, 957 | { 958 | "datasource": { 959 | "type": "prometheus", 960 | "uid": "${DS_PROMETHEUS}" 961 | }, 962 | "editorMode": "code", 963 | "expr": "increase(sidekiq_failed_jobs_total[1d])", 964 | "hide": false, 965 | "legendFormat": "Failed", 966 | "range": true, 967 | "refId": "B" 968 | } 969 | ], 970 | "title": "24h average", 971 | "type": "timeseries" 972 | }, 973 | { 974 | "datasource": { 975 | "type": "prometheus", 976 | "uid": "PBFA97CFB590B2093" 977 | }, 978 | "fieldConfig": { 979 | "defaults": { 980 | "color": { 981 | "mode": "palette-classic" 982 | }, 983 | "custom": { 984 | "axisCenteredZero": false, 985 | "axisColorMode": "text", 986 | "axisLabel": "", 987 | "axisPlacement": "auto", 988 | "axisSoftMax": 0.1, 989 | "axisSoftMin": 0, 990 | "barAlignment": 0, 991 | "drawStyle": "line", 992 | "fillOpacity": 10, 993 | "gradientMode": "none", 994 | "hideFrom": { 995 | "legend": false, 996 | "tooltip": false, 997 | "viz": false 998 | }, 999 | "lineInterpolation": "linear", 1000 | "lineWidth": 1, 1001 | "pointSize": 5, 1002 | "scaleDistribution": { 1003 | "type": "linear" 1004 | }, 1005 | "showPoints": "never", 1006 | "spanNulls": false, 1007 | "stacking": { 1008 | "group": "A", 1009 | "mode": "none" 1010 | }, 1011 | "thresholdsStyle": { 1012 | "mode": "off" 1013 | } 1014 | }, 1015 | "links": [], 1016 | "mappings": [], 1017 | "min": 0, 1018 | "thresholds": { 1019 | "mode": "absolute", 1020 | "steps": [ 1021 | { 1022 | "color": "green", 1023 | "value": null 1024 | }, 1025 | { 1026 | "color": "red", 1027 | "value": 80 1028 | } 1029 | ] 1030 | }, 1031 | "unit": "s" 1032 | }, 1033 | "overrides": [ 1034 | { 1035 | "matcher": { 1036 | "id": "byName", 1037 | "options": "processing rate" 1038 | }, 1039 | "properties": [ 1040 | { 1041 | "id": "color", 1042 | "value": { 1043 | "fixedColor": "#447ebc", 1044 | "mode": "fixed" 1045 | } 1046 | }, 1047 | { 1048 | "id": "custom.fillOpacity", 1049 | "value": 0 1050 | }, 1051 | { 1052 | "id": "unit", 1053 | "value": "short" 1054 | }, 1055 | { 1056 | "id": "custom.axisPlacement", 1057 | "value": "right" 1058 | } 1059 | ] 1060 | } 1061 | ] 1062 | }, 1063 | "gridPos": { 1064 | "h": 7, 1065 | "w": 11, 1066 | "x": 0, 1067 | "y": 11 1068 | }, 1069 | "id": 2, 1070 | "links": [], 1071 | "options": { 1072 | "legend": { 1073 | "calcs": [ 1074 | "last" 1075 | ], 1076 | "displayMode": "table", 1077 | "placement": "right", 1078 | "showLegend": true 1079 | }, 1080 | "tooltip": { 1081 | "mode": "multi", 1082 | "sort": "none" 1083 | } 1084 | }, 1085 | "pluginVersion": "9.1.1", 1086 | "targets": [ 1087 | { 1088 | "datasource": { 1089 | "type": "prometheus", 1090 | "uid": "${DS_PROMETHEUS}" 1091 | }, 1092 | "editorMode": "code", 1093 | "expr": "rate(sidekiq_queue_latency_seconds[1m])", 1094 | "format": "time_series", 1095 | "intervalFactor": 1, 1096 | "legendFormat": "{{name}}", 1097 | "range": true, 1098 | "refId": "A" 1099 | }, 1100 | { 1101 | "datasource": { 1102 | "type": "prometheus", 1103 | "uid": "${DS_PROMETHEUS}" 1104 | }, 1105 | "editorMode": "code", 1106 | "expr": "rate(sidekiq_processed_jobs_total[1m])", 1107 | "format": "time_series", 1108 | "hide": false, 1109 | "intervalFactor": 1, 1110 | "legendFormat": "processing rate", 1111 | "range": true, 1112 | "refId": "B" 1113 | } 1114 | ], 1115 | "title": "Queues latency", 1116 | "type": "timeseries" 1117 | }, 1118 | { 1119 | "datasource": {}, 1120 | "fieldConfig": { 1121 | "defaults": { 1122 | "color": { 1123 | "mode": "palette-classic" 1124 | }, 1125 | "custom": { 1126 | "axisCenteredZero": false, 1127 | "axisColorMode": "text", 1128 | "axisLabel": "", 1129 | "axisPlacement": "auto", 1130 | "barAlignment": 0, 1131 | "drawStyle": "line", 1132 | "fillOpacity": 10, 1133 | "gradientMode": "none", 1134 | "hideFrom": { 1135 | "legend": false, 1136 | "tooltip": false, 1137 | "viz": false 1138 | }, 1139 | "lineInterpolation": "linear", 1140 | "lineWidth": 1, 1141 | "pointSize": 5, 1142 | "scaleDistribution": { 1143 | "type": "linear" 1144 | }, 1145 | "showPoints": "never", 1146 | "spanNulls": false, 1147 | "stacking": { 1148 | "group": "A", 1149 | "mode": "none" 1150 | }, 1151 | "thresholdsStyle": { 1152 | "mode": "off" 1153 | } 1154 | }, 1155 | "links": [], 1156 | "mappings": [], 1157 | "thresholds": { 1158 | "mode": "absolute", 1159 | "steps": [ 1160 | { 1161 | "color": "green", 1162 | "value": null 1163 | }, 1164 | { 1165 | "color": "red", 1166 | "value": 80 1167 | } 1168 | ] 1169 | }, 1170 | "unit": "none" 1171 | }, 1172 | "overrides": [] 1173 | }, 1174 | "gridPos": { 1175 | "h": 7, 1176 | "w": 11, 1177 | "x": 11, 1178 | "y": 11 1179 | }, 1180 | "id": 16, 1181 | "links": [], 1182 | "options": { 1183 | "legend": { 1184 | "calcs": [ 1185 | "last" 1186 | ], 1187 | "displayMode": "table", 1188 | "placement": "right", 1189 | "showLegend": true 1190 | }, 1191 | "tooltip": { 1192 | "mode": "multi", 1193 | "sort": "none" 1194 | } 1195 | }, 1196 | "pluginVersion": "9.1.1", 1197 | "targets": [ 1198 | { 1199 | "datasource": { 1200 | "type": "prometheus", 1201 | "uid": "${DS_PROMETHEUS}" 1202 | }, 1203 | "editorMode": "code", 1204 | "expr": "sidekiq_queue_enqueued_jobs", 1205 | "format": "time_series", 1206 | "intervalFactor": 1, 1207 | "legendFormat": "{{name}}", 1208 | "range": true, 1209 | "refId": "A" 1210 | } 1211 | ], 1212 | "title": "Enqueued jobs", 1213 | "type": "timeseries" 1214 | }, 1215 | { 1216 | "datasource": {}, 1217 | "fieldConfig": { 1218 | "defaults": { 1219 | "color": { 1220 | "mode": "palette-classic" 1221 | }, 1222 | "custom": { 1223 | "axisCenteredZero": false, 1224 | "axisColorMode": "text", 1225 | "axisLabel": "", 1226 | "axisPlacement": "auto", 1227 | "axisSoftMin": 0, 1228 | "barAlignment": 0, 1229 | "drawStyle": "line", 1230 | "fillOpacity": 9, 1231 | "gradientMode": "none", 1232 | "hideFrom": { 1233 | "legend": false, 1234 | "tooltip": false, 1235 | "viz": false 1236 | }, 1237 | "lineInterpolation": "smooth", 1238 | "lineWidth": 1, 1239 | "pointSize": 5, 1240 | "scaleDistribution": { 1241 | "type": "linear" 1242 | }, 1243 | "showPoints": "auto", 1244 | "spanNulls": false, 1245 | "stacking": { 1246 | "group": "A", 1247 | "mode": "none" 1248 | }, 1249 | "thresholdsStyle": { 1250 | "mode": "off" 1251 | } 1252 | }, 1253 | "mappings": [], 1254 | "thresholds": { 1255 | "mode": "absolute", 1256 | "steps": [ 1257 | { 1258 | "color": "green", 1259 | "value": null 1260 | }, 1261 | { 1262 | "color": "#EAB839", 1263 | "value": 50 1264 | }, 1265 | { 1266 | "color": "red", 1267 | "value": 100 1268 | } 1269 | ] 1270 | } 1271 | }, 1272 | "overrides": [ 1273 | { 1274 | "matcher": { 1275 | "id": "byName", 1276 | "options": "Failed" 1277 | }, 1278 | "properties": [ 1279 | { 1280 | "id": "color", 1281 | "value": { 1282 | "fixedColor": "dark-red", 1283 | "mode": "fixed" 1284 | } 1285 | } 1286 | ] 1287 | } 1288 | ] 1289 | }, 1290 | "gridPos": { 1291 | "h": 7, 1292 | "w": 11, 1293 | "x": 0, 1294 | "y": 18 1295 | }, 1296 | "id": 18, 1297 | "options": { 1298 | "legend": { 1299 | "calcs": [ 1300 | "last" 1301 | ], 1302 | "displayMode": "table", 1303 | "placement": "right", 1304 | "showLegend": true 1305 | }, 1306 | "tooltip": { 1307 | "mode": "single", 1308 | "sort": "none" 1309 | } 1310 | }, 1311 | "targets": [ 1312 | { 1313 | "datasource": { 1314 | "type": "prometheus", 1315 | "uid": "${DS_PROMETHEUS}" 1316 | }, 1317 | "editorMode": "code", 1318 | "exemplar": false, 1319 | "expr": "sidekiq_busy_workers", 1320 | "interval": "", 1321 | "legendFormat": "Busy", 1322 | "range": true, 1323 | "refId": "A" 1324 | }, 1325 | { 1326 | "datasource": { 1327 | "type": "prometheus", 1328 | "uid": "${DS_PROMETHEUS}" 1329 | }, 1330 | "editorMode": "code", 1331 | "expr": "sidekiq_enqueued_jobs", 1332 | "hide": false, 1333 | "legendFormat": "Queue", 1334 | "range": true, 1335 | "refId": "B" 1336 | }, 1337 | { 1338 | "datasource": { 1339 | "type": "prometheus", 1340 | "uid": "${DS_PROMETHEUS}" 1341 | }, 1342 | "editorMode": "code", 1343 | "expr": "rate(sidekiq_failed_jobs_total[1m])", 1344 | "hide": false, 1345 | "legendFormat": "Failed", 1346 | "range": true, 1347 | "refId": "C" 1348 | } 1349 | ], 1350 | "title": "Workers", 1351 | "type": "timeseries" 1352 | }, 1353 | { 1354 | "datasource": {}, 1355 | "fieldConfig": { 1356 | "defaults": { 1357 | "color": { 1358 | "mode": "palette-classic" 1359 | }, 1360 | "custom": { 1361 | "axisCenteredZero": false, 1362 | "axisColorMode": "text", 1363 | "axisLabel": "", 1364 | "axisPlacement": "auto", 1365 | "axisSoftMin": 0, 1366 | "barAlignment": 0, 1367 | "drawStyle": "line", 1368 | "fillOpacity": 9, 1369 | "gradientMode": "none", 1370 | "hideFrom": { 1371 | "legend": false, 1372 | "tooltip": false, 1373 | "viz": false 1374 | }, 1375 | "lineInterpolation": "smooth", 1376 | "lineWidth": 1, 1377 | "pointSize": 5, 1378 | "scaleDistribution": { 1379 | "type": "linear" 1380 | }, 1381 | "showPoints": "auto", 1382 | "spanNulls": false, 1383 | "stacking": { 1384 | "group": "A", 1385 | "mode": "none" 1386 | }, 1387 | "thresholdsStyle": { 1388 | "mode": "off" 1389 | } 1390 | }, 1391 | "mappings": [], 1392 | "thresholds": { 1393 | "mode": "absolute", 1394 | "steps": [ 1395 | { 1396 | "color": "green", 1397 | "value": null 1398 | }, 1399 | { 1400 | "color": "#EAB839", 1401 | "value": 50 1402 | }, 1403 | { 1404 | "color": "red", 1405 | "value": 100 1406 | } 1407 | ] 1408 | } 1409 | }, 1410 | "overrides": [ 1411 | { 1412 | "matcher": { 1413 | "id": "byName", 1414 | "options": "Failed" 1415 | }, 1416 | "properties": [ 1417 | { 1418 | "id": "color", 1419 | "value": { 1420 | "fixedColor": "dark-red", 1421 | "mode": "fixed" 1422 | } 1423 | } 1424 | ] 1425 | } 1426 | ] 1427 | }, 1428 | "gridPos": { 1429 | "h": 7, 1430 | "w": 11, 1431 | "x": 11, 1432 | "y": 18 1433 | }, 1434 | "id": 22, 1435 | "options": { 1436 | "legend": { 1437 | "calcs": [ 1438 | "last", 1439 | "mean" 1440 | ], 1441 | "displayMode": "table", 1442 | "placement": "right", 1443 | "showLegend": true 1444 | }, 1445 | "tooltip": { 1446 | "mode": "single", 1447 | "sort": "none" 1448 | } 1449 | }, 1450 | "targets": [ 1451 | { 1452 | "datasource": { 1453 | "type": "prometheus", 1454 | "uid": "${DS_PROMETHEUS}" 1455 | }, 1456 | "editorMode": "code", 1457 | "exemplar": false, 1458 | "expr": "sidekiq_queue_busy_workers", 1459 | "interval": "", 1460 | "legendFormat": "{{name}}", 1461 | "range": true, 1462 | "refId": "A" 1463 | } 1464 | ], 1465 | "title": "Queue Workers", 1466 | "type": "timeseries" 1467 | } 1468 | ], 1469 | "refresh": "10s", 1470 | "schemaVersion": 37, 1471 | "style": "dark", 1472 | "tags": [], 1473 | "templating": { 1474 | "list": [] 1475 | }, 1476 | "time": { 1477 | "from": "now-30m", 1478 | "to": "now" 1479 | }, 1480 | "timepicker": { 1481 | "refresh_intervals": [ 1482 | "10s", 1483 | "30s", 1484 | "1m", 1485 | "5m", 1486 | "15m", 1487 | "30m", 1488 | "1h", 1489 | "2h", 1490 | "1d" 1491 | ], 1492 | "time_options": [ 1493 | "5m", 1494 | "15m", 1495 | "1h", 1496 | "6h", 1497 | "12h", 1498 | "24h", 1499 | "2d", 1500 | "7d", 1501 | "30d" 1502 | ] 1503 | }, 1504 | "timezone": "", 1505 | "title": "Sidekiq Dashboard", 1506 | "uid": "SwCwV7qkz", 1507 | "version": 13, 1508 | "weekStart": "" 1509 | } -------------------------------------------------------------------------------- /monitoring/redis.json: -------------------------------------------------------------------------------- 1 | { 2 | "annotations": { 3 | "list": [ 4 | { 5 | "builtIn": 1, 6 | "datasource": { 7 | "type": "datasource", 8 | "uid": "grafana" 9 | }, 10 | "enable": true, 11 | "hide": true, 12 | "iconColor": "rgba(0, 211, 255, 1)", 13 | "name": "Annotations & Alerts", 14 | "target": { 15 | "limit": 100, 16 | "matchAny": false, 17 | "tags": [], 18 | "type": "dashboard" 19 | }, 20 | "type": "dashboard" 21 | } 22 | ] 23 | }, 24 | "description": "", 25 | "editable": true, 26 | "fiscalYearStartMonth": 0, 27 | "gnetId": 763, 28 | "graphTooltip": 1, 29 | "id": 18, 30 | "links": [], 31 | "liveNow": false, 32 | "panels": [ 33 | { 34 | "datasource": {}, 35 | "fieldConfig": { 36 | "defaults": { 37 | "color": { 38 | "fixedColor": "rgb(31, 120, 193)", 39 | "mode": "fixed" 40 | }, 41 | "decimals": 0, 42 | "mappings": [ 43 | { 44 | "options": { 45 | "match": "null", 46 | "result": { 47 | "text": "N/A" 48 | } 49 | }, 50 | "type": "special" 51 | } 52 | ], 53 | "thresholds": { 54 | "mode": "absolute", 55 | "steps": [ 56 | { 57 | "color": "green", 58 | "value": null 59 | }, 60 | { 61 | "color": "red", 62 | "value": 80 63 | } 64 | ] 65 | }, 66 | "unit": "s" 67 | }, 68 | "overrides": [] 69 | }, 70 | "gridPos": { 71 | "h": 7, 72 | "w": 3, 73 | "x": 0, 74 | "y": 0 75 | }, 76 | "id": 9, 77 | "links": [], 78 | "maxDataPoints": 100, 79 | "options": { 80 | "colorMode": "none", 81 | "graphMode": "area", 82 | "justifyMode": "auto", 83 | "orientation": "horizontal", 84 | "reduceOptions": { 85 | "calcs": [ 86 | "lastNotNull" 87 | ], 88 | "fields": "", 89 | "values": false 90 | }, 91 | "textMode": "auto" 92 | }, 93 | "pluginVersion": "9.2.4", 94 | "targets": [ 95 | { 96 | "datasource": { 97 | "type": "prometheus", 98 | "uid": "${DS_PROMETHEUS}" 99 | }, 100 | "editorMode": "code", 101 | "expr": "max(max_over_time(redis_uptime_in_seconds{instance=~\"$instance\"}[$__interval]))", 102 | "format": "time_series", 103 | "interval": "", 104 | "intervalFactor": 2, 105 | "legendFormat": "", 106 | "metric": "", 107 | "range": true, 108 | "refId": "A", 109 | "step": 1800 110 | } 111 | ], 112 | "title": "Max Uptime", 113 | "type": "stat" 114 | }, 115 | { 116 | "datasource": {}, 117 | "fieldConfig": { 118 | "defaults": { 119 | "color": { 120 | "fixedColor": "rgb(31, 120, 193)", 121 | "mode": "fixed" 122 | }, 123 | "decimals": 0, 124 | "mappings": [ 125 | { 126 | "options": { 127 | "match": "null", 128 | "result": { 129 | "text": "N/A" 130 | } 131 | }, 132 | "type": "special" 133 | } 134 | ], 135 | "thresholds": { 136 | "mode": "absolute", 137 | "steps": [ 138 | { 139 | "color": "green", 140 | "value": null 141 | }, 142 | { 143 | "color": "red", 144 | "value": 80 145 | } 146 | ] 147 | }, 148 | "unit": "none" 149 | }, 150 | "overrides": [] 151 | }, 152 | "gridPos": { 153 | "h": 7, 154 | "w": 2, 155 | "x": 3, 156 | "y": 0 157 | }, 158 | "hideTimeOverride": true, 159 | "id": 12, 160 | "links": [], 161 | "maxDataPoints": 100, 162 | "options": { 163 | "colorMode": "none", 164 | "graphMode": "area", 165 | "justifyMode": "auto", 166 | "orientation": "horizontal", 167 | "reduceOptions": { 168 | "calcs": [ 169 | "lastNotNull" 170 | ], 171 | "fields": "", 172 | "values": false 173 | }, 174 | "textMode": "auto" 175 | }, 176 | "pluginVersion": "9.2.4", 177 | "targets": [ 178 | { 179 | "datasource": { 180 | "type": "prometheus", 181 | "uid": "${DS_PROMETHEUS}" 182 | }, 183 | "editorMode": "code", 184 | "expr": "sum(redis_connected_clients{instance=~\"$instance\"})", 185 | "format": "time_series", 186 | "intervalFactor": 2, 187 | "legendFormat": "", 188 | "metric": "", 189 | "range": true, 190 | "refId": "A", 191 | "step": 2 192 | } 193 | ], 194 | "timeFrom": "1m", 195 | "title": "Clients", 196 | "type": "stat" 197 | }, 198 | { 199 | "datasource": {}, 200 | "fieldConfig": { 201 | "defaults": { 202 | "color": { 203 | "mode": "thresholds" 204 | }, 205 | "decimals": 0, 206 | "mappings": [ 207 | { 208 | "options": { 209 | "match": "null", 210 | "result": { 211 | "text": "N/A" 212 | } 213 | }, 214 | "type": "special" 215 | } 216 | ], 217 | "min": 0, 218 | "thresholds": { 219 | "mode": "absolute", 220 | "steps": [ 221 | { 222 | "color": "rgba(50, 172, 45, 0.97)", 223 | "value": null 224 | }, 225 | { 226 | "color": "rgba(237, 129, 40, 0.89)", 227 | "value": 80 228 | }, 229 | { 230 | "color": "rgba(245, 54, 54, 0.9)", 231 | "value": 95 232 | } 233 | ] 234 | }, 235 | "unit": "decbytes" 236 | }, 237 | "overrides": [] 238 | }, 239 | "gridPos": { 240 | "h": 7, 241 | "w": 3, 242 | "x": 5, 243 | "y": 0 244 | }, 245 | "hideTimeOverride": true, 246 | "id": 11, 247 | "links": [], 248 | "maxDataPoints": 100, 249 | "options": { 250 | "colorMode": "value", 251 | "graphMode": "area", 252 | "justifyMode": "auto", 253 | "orientation": "auto", 254 | "reduceOptions": { 255 | "calcs": [ 256 | "lastNotNull" 257 | ], 258 | "fields": "", 259 | "values": false 260 | }, 261 | "textMode": "auto" 262 | }, 263 | "pluginVersion": "9.2.4", 264 | "targets": [ 265 | { 266 | "datasource": { 267 | "type": "prometheus", 268 | "uid": "${DS_PROMETHEUS}" 269 | }, 270 | "editorMode": "code", 271 | "exemplar": false, 272 | "expr": "redis_memory_used_bytes{instance=\"$instance\"}", 273 | "format": "time_series", 274 | "instant": true, 275 | "intervalFactor": 2, 276 | "legendFormat": "__auto", 277 | "metric": "", 278 | "range": false, 279 | "refId": "A", 280 | "step": 2 281 | } 282 | ], 283 | "timeFrom": "1m", 284 | "title": "Memory Usage", 285 | "type": "stat" 286 | }, 287 | { 288 | "datasource": {}, 289 | "fieldConfig": { 290 | "defaults": { 291 | "color": { 292 | "mode": "palette-classic" 293 | }, 294 | "custom": { 295 | "axisCenteredZero": false, 296 | "axisColorMode": "text", 297 | "axisLabel": "", 298 | "axisPlacement": "auto", 299 | "axisSoftMin": 0, 300 | "barAlignment": 0, 301 | "drawStyle": "line", 302 | "fillOpacity": 80, 303 | "gradientMode": "none", 304 | "hideFrom": { 305 | "legend": false, 306 | "tooltip": false, 307 | "viz": false 308 | }, 309 | "lineInterpolation": "linear", 310 | "lineWidth": 1, 311 | "pointSize": 5, 312 | "scaleDistribution": { 313 | "type": "linear" 314 | }, 315 | "showPoints": "never", 316 | "spanNulls": true, 317 | "stacking": { 318 | "group": "A", 319 | "mode": "normal" 320 | }, 321 | "thresholdsStyle": { 322 | "mode": "off" 323 | } 324 | }, 325 | "links": [], 326 | "mappings": [], 327 | "thresholds": { 328 | "mode": "absolute", 329 | "steps": [ 330 | { 331 | "color": "green", 332 | "value": null 333 | }, 334 | { 335 | "color": "red", 336 | "value": 80 337 | } 338 | ] 339 | }, 340 | "unit": "short" 341 | }, 342 | "overrides": [] 343 | }, 344 | "gridPos": { 345 | "h": 7, 346 | "w": 8, 347 | "x": 8, 348 | "y": 0 349 | }, 350 | "id": 18, 351 | "links": [], 352 | "options": { 353 | "legend": { 354 | "calcs": [], 355 | "displayMode": "list", 356 | "placement": "bottom", 357 | "showLegend": false 358 | }, 359 | "tooltip": { 360 | "mode": "multi", 361 | "sort": "desc" 362 | } 363 | }, 364 | "pluginVersion": "9.1.1", 365 | "targets": [ 366 | { 367 | "datasource": { 368 | "type": "prometheus", 369 | "uid": "${DS_PROMETHEUS}" 370 | }, 371 | "editorMode": "code", 372 | "expr": "sum(rate(redis_commands_total{instance=~\"$instance\"} [1m])) by (cmd)", 373 | "format": "time_series", 374 | "interval": "", 375 | "intervalFactor": 2, 376 | "legendFormat": "{{ cmd }}", 377 | "metric": "redis_command_calls_total", 378 | "range": true, 379 | "refId": "A", 380 | "step": 240 381 | } 382 | ], 383 | "title": "Total Commands / sec", 384 | "type": "timeseries" 385 | }, 386 | { 387 | "datasource": { 388 | "type": "prometheus", 389 | "uid": "PBFA97CFB590B2093" 390 | }, 391 | "fieldConfig": { 392 | "defaults": { 393 | "color": { 394 | "mode": "palette-classic" 395 | }, 396 | "custom": { 397 | "axisCenteredZero": false, 398 | "axisColorMode": "text", 399 | "axisLabel": "", 400 | "axisPlacement": "auto", 401 | "axisSoftMin": 0, 402 | "barAlignment": 0, 403 | "drawStyle": "line", 404 | "fillOpacity": 10, 405 | "gradientMode": "none", 406 | "hideFrom": { 407 | "legend": false, 408 | "tooltip": false, 409 | "viz": false 410 | }, 411 | "lineInterpolation": "linear", 412 | "lineWidth": 2, 413 | "pointSize": 5, 414 | "scaleDistribution": { 415 | "type": "linear" 416 | }, 417 | "showPoints": "never", 418 | "spanNulls": true, 419 | "stacking": { 420 | "group": "A", 421 | "mode": "none" 422 | }, 423 | "thresholdsStyle": { 424 | "mode": "off" 425 | } 426 | }, 427 | "links": [], 428 | "mappings": [], 429 | "min": 0, 430 | "thresholds": { 431 | "mode": "absolute", 432 | "steps": [ 433 | { 434 | "color": "green", 435 | "value": null 436 | }, 437 | { 438 | "color": "red", 439 | "value": 80 440 | } 441 | ] 442 | }, 443 | "unit": "short" 444 | }, 445 | "overrides": [] 446 | }, 447 | "gridPos": { 448 | "h": 7, 449 | "w": 8, 450 | "x": 16, 451 | "y": 0 452 | }, 453 | "id": 1, 454 | "links": [], 455 | "options": { 456 | "legend": { 457 | "calcs": [], 458 | "displayMode": "list", 459 | "placement": "bottom", 460 | "showLegend": false 461 | }, 462 | "tooltip": { 463 | "mode": "multi", 464 | "sort": "none" 465 | } 466 | }, 467 | "pluginVersion": "9.1.1", 468 | "targets": [ 469 | { 470 | "datasource": { 471 | "type": "prometheus", 472 | "uid": "${DS_PROMETHEUS}" 473 | }, 474 | "editorMode": "code", 475 | "expr": "irate(redis_keyspace_hits_total{instance=~\"$instance\"}[5m])", 476 | "format": "time_series", 477 | "hide": false, 478 | "interval": "", 479 | "intervalFactor": 2, 480 | "legendFormat": "hits, {{ instance }}", 481 | "metric": "", 482 | "range": true, 483 | "refId": "A", 484 | "step": 240, 485 | "target": "" 486 | }, 487 | { 488 | "datasource": { 489 | "type": "prometheus", 490 | "uid": "${DS_PROMETHEUS}" 491 | }, 492 | "editorMode": "code", 493 | "expr": "irate(redis_keyspace_misses_total{instance=~\"$instance\"}[5m])", 494 | "format": "time_series", 495 | "hide": false, 496 | "interval": "", 497 | "intervalFactor": 2, 498 | "legendFormat": "misses, {{ instance }}", 499 | "metric": "", 500 | "range": true, 501 | "refId": "B", 502 | "step": 240, 503 | "target": "" 504 | } 505 | ], 506 | "title": "Hits / Misses per Sec", 507 | "type": "timeseries" 508 | }, 509 | { 510 | "datasource": {}, 511 | "fieldConfig": { 512 | "defaults": { 513 | "color": { 514 | "mode": "palette-classic" 515 | }, 516 | "custom": { 517 | "axisCenteredZero": false, 518 | "axisColorMode": "text", 519 | "axisLabel": "", 520 | "axisPlacement": "auto", 521 | "axisSoftMin": 0, 522 | "barAlignment": 0, 523 | "drawStyle": "line", 524 | "fillOpacity": 10, 525 | "gradientMode": "none", 526 | "hideFrom": { 527 | "legend": false, 528 | "tooltip": false, 529 | "viz": false 530 | }, 531 | "lineInterpolation": "linear", 532 | "lineWidth": 2, 533 | "pointSize": 5, 534 | "scaleDistribution": { 535 | "type": "linear" 536 | }, 537 | "showPoints": "never", 538 | "spanNulls": false, 539 | "stacking": { 540 | "group": "A", 541 | "mode": "none" 542 | }, 543 | "thresholdsStyle": { 544 | "mode": "off" 545 | } 546 | }, 547 | "links": [], 548 | "mappings": [], 549 | "min": 0, 550 | "thresholds": { 551 | "mode": "absolute", 552 | "steps": [ 553 | { 554 | "color": "green", 555 | "value": null 556 | }, 557 | { 558 | "color": "red", 559 | "value": 80 560 | } 561 | ] 562 | }, 563 | "unit": "bytes" 564 | }, 565 | "overrides": [ 566 | { 567 | "matcher": { 568 | "id": "byName", 569 | "options": "max" 570 | }, 571 | "properties": [ 572 | { 573 | "id": "color", 574 | "value": { 575 | "fixedColor": "#BF1B00", 576 | "mode": "fixed" 577 | } 578 | } 579 | ] 580 | } 581 | ] 582 | }, 583 | "gridPos": { 584 | "h": 7, 585 | "w": 12, 586 | "x": 0, 587 | "y": 7 588 | }, 589 | "id": 7, 590 | "links": [], 591 | "options": { 592 | "legend": { 593 | "calcs": [], 594 | "displayMode": "list", 595 | "placement": "bottom", 596 | "showLegend": true 597 | }, 598 | "tooltip": { 599 | "mode": "multi", 600 | "sort": "none" 601 | } 602 | }, 603 | "pluginVersion": "9.1.1", 604 | "targets": [ 605 | { 606 | "datasource": { 607 | "type": "prometheus", 608 | "uid": "${DS_PROMETHEUS}" 609 | }, 610 | "expr": "redis_memory_used_bytes{instance=~\"$instance\"}", 611 | "format": "time_series", 612 | "intervalFactor": 2, 613 | "legendFormat": "used, {{ instance }}", 614 | "metric": "", 615 | "refId": "A", 616 | "step": 240, 617 | "target": "" 618 | }, 619 | { 620 | "datasource": { 621 | "type": "prometheus", 622 | "uid": "${DS_PROMETHEUS}" 623 | }, 624 | "editorMode": "code", 625 | "expr": "redis_memory_max_bytes{instance=~\"$instance\"}", 626 | "format": "time_series", 627 | "hide": false, 628 | "intervalFactor": 2, 629 | "legendFormat": "max, {{ instance }}", 630 | "range": true, 631 | "refId": "B", 632 | "step": 240 633 | } 634 | ], 635 | "title": "Total Memory Usage", 636 | "type": "timeseries" 637 | }, 638 | { 639 | "datasource": {}, 640 | "fieldConfig": { 641 | "defaults": { 642 | "color": { 643 | "mode": "palette-classic" 644 | }, 645 | "custom": { 646 | "axisCenteredZero": false, 647 | "axisColorMode": "text", 648 | "axisLabel": "", 649 | "axisPlacement": "auto", 650 | "axisSoftMin": 0, 651 | "barAlignment": 0, 652 | "drawStyle": "line", 653 | "fillOpacity": 10, 654 | "gradientMode": "none", 655 | "hideFrom": { 656 | "legend": false, 657 | "tooltip": false, 658 | "viz": false 659 | }, 660 | "lineInterpolation": "linear", 661 | "lineWidth": 2, 662 | "pointSize": 5, 663 | "scaleDistribution": { 664 | "type": "linear" 665 | }, 666 | "showPoints": "never", 667 | "spanNulls": true, 668 | "stacking": { 669 | "group": "A", 670 | "mode": "none" 671 | }, 672 | "thresholdsStyle": { 673 | "mode": "off" 674 | } 675 | }, 676 | "links": [], 677 | "mappings": [], 678 | "thresholds": { 679 | "mode": "absolute", 680 | "steps": [ 681 | { 682 | "color": "green", 683 | "value": null 684 | }, 685 | { 686 | "color": "red", 687 | "value": 80 688 | } 689 | ] 690 | }, 691 | "unit": "bytes" 692 | }, 693 | "overrides": [] 694 | }, 695 | "gridPos": { 696 | "h": 7, 697 | "w": 12, 698 | "x": 12, 699 | "y": 7 700 | }, 701 | "id": 10, 702 | "links": [], 703 | "options": { 704 | "legend": { 705 | "calcs": [], 706 | "displayMode": "list", 707 | "placement": "bottom", 708 | "showLegend": true 709 | }, 710 | "tooltip": { 711 | "mode": "multi", 712 | "sort": "none" 713 | } 714 | }, 715 | "pluginVersion": "9.1.1", 716 | "targets": [ 717 | { 718 | "datasource": { 719 | "type": "prometheus", 720 | "uid": "${DS_PROMETHEUS}" 721 | }, 722 | "editorMode": "code", 723 | "expr": "sum(rate(redis_net_input_bytes_total{instance=~\"$instance\"}[5m]))", 724 | "format": "time_series", 725 | "intervalFactor": 2, 726 | "legendFormat": "{{ input }}", 727 | "range": true, 728 | "refId": "A", 729 | "step": 240 730 | }, 731 | { 732 | "datasource": { 733 | "type": "prometheus", 734 | "uid": "${DS_PROMETHEUS}" 735 | }, 736 | "expr": "sum(rate(redis_net_output_bytes_total{instance=~\"$instance\"}[5m]))", 737 | "format": "time_series", 738 | "interval": "", 739 | "intervalFactor": 2, 740 | "legendFormat": "{{ output }}", 741 | "refId": "B", 742 | "step": 240 743 | } 744 | ], 745 | "title": "Network I/O", 746 | "type": "timeseries" 747 | }, 748 | { 749 | "datasource": {}, 750 | "fieldConfig": { 751 | "defaults": { 752 | "color": { 753 | "mode": "palette-classic" 754 | }, 755 | "custom": { 756 | "axisCenteredZero": false, 757 | "axisColorMode": "text", 758 | "axisLabel": "", 759 | "axisPlacement": "auto", 760 | "axisSoftMin": 0, 761 | "barAlignment": 0, 762 | "drawStyle": "line", 763 | "fillOpacity": 70, 764 | "gradientMode": "none", 765 | "hideFrom": { 766 | "legend": false, 767 | "tooltip": false, 768 | "viz": false 769 | }, 770 | "lineInterpolation": "linear", 771 | "lineWidth": 2, 772 | "pointSize": 5, 773 | "scaleDistribution": { 774 | "type": "linear" 775 | }, 776 | "showPoints": "never", 777 | "spanNulls": true, 778 | "stacking": { 779 | "group": "A", 780 | "mode": "normal" 781 | }, 782 | "thresholdsStyle": { 783 | "mode": "off" 784 | } 785 | }, 786 | "links": [], 787 | "mappings": [], 788 | "thresholds": { 789 | "mode": "absolute", 790 | "steps": [ 791 | { 792 | "color": "green", 793 | "value": null 794 | }, 795 | { 796 | "color": "red", 797 | "value": 80 798 | } 799 | ] 800 | }, 801 | "unit": "none" 802 | }, 803 | "overrides": [] 804 | }, 805 | "gridPos": { 806 | "h": 7, 807 | "w": 12, 808 | "x": 0, 809 | "y": 14 810 | }, 811 | "id": 5, 812 | "links": [], 813 | "options": { 814 | "legend": { 815 | "calcs": [ 816 | "lastNotNull" 817 | ], 818 | "displayMode": "table", 819 | "placement": "right", 820 | "showLegend": true 821 | }, 822 | "tooltip": { 823 | "mode": "multi", 824 | "sort": "none" 825 | } 826 | }, 827 | "pluginVersion": "9.1.1", 828 | "targets": [ 829 | { 830 | "datasource": { 831 | "type": "prometheus", 832 | "uid": "${DS_PROMETHEUS}" 833 | }, 834 | "editorMode": "code", 835 | "expr": "sum (redis_db_keys{instance=~\"$instance\"}) by (db, instance)", 836 | "format": "time_series", 837 | "interval": "", 838 | "intervalFactor": 2, 839 | "legendFormat": "{{ db }}, {{ instance }}", 840 | "range": true, 841 | "refId": "A", 842 | "step": 240, 843 | "target": "" 844 | } 845 | ], 846 | "title": "Total Items per DB", 847 | "type": "timeseries" 848 | }, 849 | { 850 | "datasource": { 851 | "type": "prometheus", 852 | "uid": "PBFA97CFB590B2093" 853 | }, 854 | "fieldConfig": { 855 | "defaults": { 856 | "color": { 857 | "mode": "palette-classic" 858 | }, 859 | "custom": { 860 | "axisCenteredZero": false, 861 | "axisColorMode": "text", 862 | "axisLabel": "", 863 | "axisPlacement": "auto", 864 | "barAlignment": 0, 865 | "drawStyle": "line", 866 | "fillOpacity": 70, 867 | "gradientMode": "none", 868 | "hideFrom": { 869 | "legend": false, 870 | "tooltip": false, 871 | "viz": false 872 | }, 873 | "lineInterpolation": "linear", 874 | "lineWidth": 2, 875 | "pointSize": 5, 876 | "scaleDistribution": { 877 | "type": "linear" 878 | }, 879 | "showPoints": "never", 880 | "spanNulls": true, 881 | "stacking": { 882 | "group": "A", 883 | "mode": "normal" 884 | }, 885 | "thresholdsStyle": { 886 | "mode": "off" 887 | } 888 | }, 889 | "links": [], 890 | "mappings": [], 891 | "min": 0, 892 | "thresholds": { 893 | "mode": "absolute", 894 | "steps": [ 895 | { 896 | "color": "green", 897 | "value": null 898 | }, 899 | { 900 | "color": "red", 901 | "value": 80 902 | } 903 | ] 904 | }, 905 | "unit": "short" 906 | }, 907 | "overrides": [] 908 | }, 909 | "gridPos": { 910 | "h": 7, 911 | "w": 12, 912 | "x": 12, 913 | "y": 14 914 | }, 915 | "id": 13, 916 | "links": [], 917 | "options": { 918 | "legend": { 919 | "calcs": [], 920 | "displayMode": "list", 921 | "placement": "bottom", 922 | "showLegend": true 923 | }, 924 | "tooltip": { 925 | "mode": "multi", 926 | "sort": "none" 927 | } 928 | }, 929 | "pluginVersion": "9.1.1", 930 | "targets": [ 931 | { 932 | "datasource": { 933 | "type": "prometheus", 934 | "uid": "${DS_PROMETHEUS}" 935 | }, 936 | "editorMode": "code", 937 | "expr": "sum (redis_db_keys{instance=~\"$instance\"}) by (instance) - sum (redis_db_keys_expiring{instance=~\"$instance\"}) by (instance)", 938 | "format": "time_series", 939 | "interval": "", 940 | "intervalFactor": 2, 941 | "legendFormat": "not expiring, {{ instance }}", 942 | "range": true, 943 | "refId": "A", 944 | "step": 240, 945 | "target": "" 946 | }, 947 | { 948 | "datasource": { 949 | "type": "prometheus", 950 | "uid": "${DS_PROMETHEUS}" 951 | }, 952 | "editorMode": "code", 953 | "expr": "sum (redis_db_keys_expiring{instance=~\"$instance\"}) by (instance)", 954 | "format": "time_series", 955 | "interval": "", 956 | "intervalFactor": 2, 957 | "legendFormat": "expiring, {{ instance }}", 958 | "metric": "", 959 | "range": true, 960 | "refId": "B", 961 | "step": 240 962 | } 963 | ], 964 | "title": "Expiring vs Not-Expiring Keys", 965 | "type": "timeseries" 966 | }, 967 | { 968 | "datasource": { 969 | "type": "prometheus", 970 | "uid": "PBFA97CFB590B2093" 971 | }, 972 | "fieldConfig": { 973 | "defaults": { 974 | "color": { 975 | "mode": "palette-classic" 976 | }, 977 | "custom": { 978 | "axisCenteredZero": false, 979 | "axisColorMode": "text", 980 | "axisLabel": "", 981 | "axisPlacement": "auto", 982 | "axisSoftMin": 0, 983 | "barAlignment": 0, 984 | "drawStyle": "line", 985 | "fillOpacity": 10, 986 | "gradientMode": "none", 987 | "hideFrom": { 988 | "legend": false, 989 | "tooltip": false, 990 | "viz": false 991 | }, 992 | "lineInterpolation": "linear", 993 | "lineWidth": 2, 994 | "pointSize": 5, 995 | "scaleDistribution": { 996 | "type": "linear" 997 | }, 998 | "showPoints": "never", 999 | "spanNulls": true, 1000 | "stacking": { 1001 | "group": "A", 1002 | "mode": "none" 1003 | }, 1004 | "thresholdsStyle": { 1005 | "mode": "off" 1006 | } 1007 | }, 1008 | "links": [], 1009 | "mappings": [], 1010 | "thresholds": { 1011 | "mode": "absolute", 1012 | "steps": [ 1013 | { 1014 | "color": "green", 1015 | "value": null 1016 | }, 1017 | { 1018 | "color": "red", 1019 | "value": 80 1020 | } 1021 | ] 1022 | }, 1023 | "unit": "short" 1024 | }, 1025 | "overrides": [ 1026 | { 1027 | "matcher": { 1028 | "id": "byName", 1029 | "options": "evicts" 1030 | }, 1031 | "properties": [ 1032 | { 1033 | "id": "color", 1034 | "value": { 1035 | "fixedColor": "#890F02", 1036 | "mode": "fixed" 1037 | } 1038 | } 1039 | ] 1040 | }, 1041 | { 1042 | "matcher": { 1043 | "id": "byName", 1044 | "options": "memcached_items_evicted_total{instance=\"172.17.0.1:9150\",job=\"prometheus\"}" 1045 | }, 1046 | "properties": [ 1047 | { 1048 | "id": "color", 1049 | "value": { 1050 | "fixedColor": "#890F02", 1051 | "mode": "fixed" 1052 | } 1053 | } 1054 | ] 1055 | }, 1056 | { 1057 | "matcher": { 1058 | "id": "byName", 1059 | "options": "reclaims" 1060 | }, 1061 | "properties": [ 1062 | { 1063 | "id": "color", 1064 | "value": { 1065 | "fixedColor": "#3F6833", 1066 | "mode": "fixed" 1067 | } 1068 | } 1069 | ] 1070 | } 1071 | ] 1072 | }, 1073 | "gridPos": { 1074 | "h": 7, 1075 | "w": 12, 1076 | "x": 0, 1077 | "y": 21 1078 | }, 1079 | "id": 8, 1080 | "links": [], 1081 | "options": { 1082 | "legend": { 1083 | "calcs": [], 1084 | "displayMode": "list", 1085 | "placement": "bottom", 1086 | "showLegend": true 1087 | }, 1088 | "tooltip": { 1089 | "mode": "multi", 1090 | "sort": "none" 1091 | } 1092 | }, 1093 | "pluginVersion": "9.1.1", 1094 | "targets": [ 1095 | { 1096 | "datasource": { 1097 | "type": "prometheus", 1098 | "uid": "${DS_PROMETHEUS}" 1099 | }, 1100 | "editorMode": "code", 1101 | "expr": "sum(rate(redis_expired_keys_total{instance=~\"$instance\"}[5m])) by (instance)", 1102 | "format": "time_series", 1103 | "hide": false, 1104 | "interval": "", 1105 | "intervalFactor": 2, 1106 | "legendFormat": "expired, {{ instance }}", 1107 | "metric": "", 1108 | "range": true, 1109 | "refId": "A", 1110 | "step": 240, 1111 | "target": "" 1112 | }, 1113 | { 1114 | "datasource": { 1115 | "type": "prometheus", 1116 | "uid": "${DS_PROMETHEUS}" 1117 | }, 1118 | "editorMode": "code", 1119 | "expr": "sum(rate(redis_evicted_keys_total{instance=~\"$instance\"}[5m])) by (instance)", 1120 | "format": "time_series", 1121 | "interval": "", 1122 | "intervalFactor": 2, 1123 | "legendFormat": "evicted, {{ instance }}", 1124 | "range": true, 1125 | "refId": "B", 1126 | "step": 240 1127 | } 1128 | ], 1129 | "title": "Expired/Evicted Keys", 1130 | "type": "timeseries" 1131 | }, 1132 | { 1133 | "datasource": { 1134 | "type": "prometheus", 1135 | "uid": "PBFA97CFB590B2093" 1136 | }, 1137 | "fieldConfig": { 1138 | "defaults": { 1139 | "color": { 1140 | "mode": "palette-classic" 1141 | }, 1142 | "custom": { 1143 | "axisCenteredZero": false, 1144 | "axisColorMode": "text", 1145 | "axisLabel": "", 1146 | "axisPlacement": "auto", 1147 | "axisSoftMin": 0, 1148 | "barAlignment": 0, 1149 | "drawStyle": "line", 1150 | "fillOpacity": 10, 1151 | "gradientMode": "none", 1152 | "hideFrom": { 1153 | "legend": false, 1154 | "tooltip": false, 1155 | "viz": false 1156 | }, 1157 | "lineInterpolation": "linear", 1158 | "lineWidth": 1, 1159 | "pointSize": 5, 1160 | "scaleDistribution": { 1161 | "type": "linear" 1162 | }, 1163 | "showPoints": "never", 1164 | "spanNulls": false, 1165 | "stacking": { 1166 | "group": "A", 1167 | "mode": "none" 1168 | }, 1169 | "thresholdsStyle": { 1170 | "mode": "off" 1171 | } 1172 | }, 1173 | "links": [], 1174 | "mappings": [], 1175 | "thresholds": { 1176 | "mode": "absolute", 1177 | "steps": [ 1178 | { 1179 | "color": "green", 1180 | "value": null 1181 | }, 1182 | { 1183 | "color": "red", 1184 | "value": 80 1185 | } 1186 | ] 1187 | }, 1188 | "unit": "short" 1189 | }, 1190 | "overrides": [] 1191 | }, 1192 | "gridPos": { 1193 | "h": 7, 1194 | "w": 12, 1195 | "x": 12, 1196 | "y": 21 1197 | }, 1198 | "id": 16, 1199 | "links": [], 1200 | "options": { 1201 | "legend": { 1202 | "calcs": [], 1203 | "displayMode": "list", 1204 | "placement": "bottom", 1205 | "showLegend": true 1206 | }, 1207 | "tooltip": { 1208 | "mode": "multi", 1209 | "sort": "none" 1210 | } 1211 | }, 1212 | "pluginVersion": "9.1.1", 1213 | "targets": [ 1214 | { 1215 | "datasource": { 1216 | "type": "prometheus", 1217 | "uid": "${DS_PROMETHEUS}" 1218 | }, 1219 | "editorMode": "code", 1220 | "expr": "sum(redis_connected_clients{instance=~\"$instance\"})", 1221 | "format": "time_series", 1222 | "intervalFactor": 1, 1223 | "legendFormat": "connected", 1224 | "range": true, 1225 | "refId": "A" 1226 | }, 1227 | { 1228 | "datasource": { 1229 | "type": "prometheus", 1230 | "uid": "${DS_PROMETHEUS}" 1231 | }, 1232 | "editorMode": "code", 1233 | "expr": "sum(redis_blocked_clients{instance=~\"$instance\"})", 1234 | "format": "time_series", 1235 | "intervalFactor": 1, 1236 | "legendFormat": "blocked", 1237 | "range": true, 1238 | "refId": "B" 1239 | } 1240 | ], 1241 | "title": "Connected/Blocked Clients", 1242 | "type": "timeseries" 1243 | }, 1244 | { 1245 | "datasource": {}, 1246 | "fieldConfig": { 1247 | "defaults": { 1248 | "color": { 1249 | "mode": "palette-classic" 1250 | }, 1251 | "custom": { 1252 | "axisCenteredZero": false, 1253 | "axisColorMode": "text", 1254 | "axisLabel": "", 1255 | "axisPlacement": "auto", 1256 | "axisSoftMin": 0, 1257 | "barAlignment": 0, 1258 | "drawStyle": "line", 1259 | "fillOpacity": 20, 1260 | "gradientMode": "none", 1261 | "hideFrom": { 1262 | "legend": false, 1263 | "tooltip": false, 1264 | "viz": false 1265 | }, 1266 | "lineInterpolation": "linear", 1267 | "lineWidth": 1, 1268 | "pointSize": 5, 1269 | "scaleDistribution": { 1270 | "type": "linear" 1271 | }, 1272 | "showPoints": "never", 1273 | "spanNulls": true, 1274 | "stacking": { 1275 | "group": "A", 1276 | "mode": "none" 1277 | }, 1278 | "thresholdsStyle": { 1279 | "mode": "off" 1280 | } 1281 | }, 1282 | "links": [], 1283 | "mappings": [], 1284 | "thresholds": { 1285 | "mode": "absolute", 1286 | "steps": [ 1287 | { 1288 | "color": "green" 1289 | }, 1290 | { 1291 | "color": "red", 1292 | "value": 80 1293 | } 1294 | ] 1295 | }, 1296 | "unit": "s" 1297 | }, 1298 | "overrides": [] 1299 | }, 1300 | "gridPos": { 1301 | "h": 7, 1302 | "w": 12, 1303 | "x": 0, 1304 | "y": 28 1305 | }, 1306 | "id": 20, 1307 | "links": [], 1308 | "options": { 1309 | "legend": { 1310 | "calcs": [ 1311 | "last" 1312 | ], 1313 | "displayMode": "table", 1314 | "placement": "right", 1315 | "showLegend": true 1316 | }, 1317 | "tooltip": { 1318 | "mode": "multi", 1319 | "sort": "desc" 1320 | } 1321 | }, 1322 | "pluginVersion": "9.1.1", 1323 | "targets": [ 1324 | { 1325 | "datasource": { 1326 | "type": "prometheus", 1327 | "uid": "${DS_PROMETHEUS}" 1328 | }, 1329 | "editorMode": "code", 1330 | "expr": "sum(irate(redis_commands_duration_seconds_total{instance =~ \"$instance\"}[1m])) by (cmd)\n /\nsum(irate(redis_commands_total{instance =~ \"$instance\"}[1m])) by (cmd)\n", 1331 | "format": "time_series", 1332 | "interval": "", 1333 | "intervalFactor": 2, 1334 | "legendFormat": "{{ cmd }}", 1335 | "metric": "redis_command_calls_total", 1336 | "range": true, 1337 | "refId": "A", 1338 | "step": 240 1339 | } 1340 | ], 1341 | "title": "Average Time Spent by Command / sec", 1342 | "type": "timeseries" 1343 | }, 1344 | { 1345 | "datasource": {}, 1346 | "fieldConfig": { 1347 | "defaults": { 1348 | "color": { 1349 | "mode": "palette-classic" 1350 | }, 1351 | "custom": { 1352 | "axisCenteredZero": false, 1353 | "axisColorMode": "text", 1354 | "axisLabel": "", 1355 | "axisPlacement": "auto", 1356 | "axisSoftMin": 0, 1357 | "barAlignment": 0, 1358 | "drawStyle": "line", 1359 | "fillOpacity": 80, 1360 | "gradientMode": "none", 1361 | "hideFrom": { 1362 | "legend": false, 1363 | "tooltip": false, 1364 | "viz": false 1365 | }, 1366 | "lineInterpolation": "linear", 1367 | "lineWidth": 1, 1368 | "pointSize": 5, 1369 | "scaleDistribution": { 1370 | "type": "linear" 1371 | }, 1372 | "showPoints": "never", 1373 | "spanNulls": true, 1374 | "stacking": { 1375 | "group": "A", 1376 | "mode": "normal" 1377 | }, 1378 | "thresholdsStyle": { 1379 | "mode": "off" 1380 | } 1381 | }, 1382 | "links": [], 1383 | "mappings": [], 1384 | "thresholds": { 1385 | "mode": "absolute", 1386 | "steps": [ 1387 | { 1388 | "color": "green" 1389 | }, 1390 | { 1391 | "color": "red", 1392 | "value": 80 1393 | } 1394 | ] 1395 | }, 1396 | "unit": "s" 1397 | }, 1398 | "overrides": [] 1399 | }, 1400 | "gridPos": { 1401 | "h": 7, 1402 | "w": 12, 1403 | "x": 12, 1404 | "y": 28 1405 | }, 1406 | "id": 14, 1407 | "links": [], 1408 | "options": { 1409 | "legend": { 1410 | "calcs": [ 1411 | "last" 1412 | ], 1413 | "displayMode": "table", 1414 | "placement": "right", 1415 | "showLegend": true 1416 | }, 1417 | "tooltip": { 1418 | "mode": "multi", 1419 | "sort": "desc" 1420 | } 1421 | }, 1422 | "pluginVersion": "9.1.1", 1423 | "targets": [ 1424 | { 1425 | "datasource": { 1426 | "type": "prometheus", 1427 | "uid": "${DS_PROMETHEUS}" 1428 | }, 1429 | "editorMode": "code", 1430 | "expr": "sum(irate(redis_commands_duration_seconds_total{instance=~\"$instance\"}[1m])) by (cmd) != 0", 1431 | "format": "time_series", 1432 | "interval": "", 1433 | "intervalFactor": 2, 1434 | "legendFormat": "{{ cmd }}", 1435 | "metric": "redis_command_calls_total", 1436 | "range": true, 1437 | "refId": "A", 1438 | "step": 240 1439 | } 1440 | ], 1441 | "title": "Total Time Spent by Command / sec", 1442 | "type": "timeseries" 1443 | } 1444 | ], 1445 | "refresh": "10s", 1446 | "schemaVersion": 37, 1447 | "style": "dark", 1448 | "tags": [ 1449 | "prometheus", 1450 | "redis" 1451 | ], 1452 | "templating": { 1453 | "list": [ 1454 | { 1455 | "current": { 1456 | "selected": false, 1457 | "text": "mastodon_redis_metrics:9121", 1458 | "value": "mastodon_redis_metrics:9121" 1459 | }, 1460 | "datasource": { 1461 | "type": "prometheus", 1462 | "uid": "PBFA97CFB590B2093" 1463 | }, 1464 | "definition": "label_values(redis_up, instance)", 1465 | "hide": 0, 1466 | "includeAll": false, 1467 | "multi": true, 1468 | "name": "instance", 1469 | "options": [], 1470 | "query": { 1471 | "query": "label_values(redis_up, instance)", 1472 | "refId": "Prometheus-instance-Variable-Query" 1473 | }, 1474 | "refresh": 2, 1475 | "regex": "", 1476 | "skipUrlSync": false, 1477 | "sort": 1, 1478 | "tagValuesQuery": "", 1479 | "tagsQuery": "", 1480 | "type": "query", 1481 | "useTags": false 1482 | } 1483 | ] 1484 | }, 1485 | "time": { 1486 | "from": "now-1h", 1487 | "to": "now" 1488 | }, 1489 | "timepicker": { 1490 | "refresh_intervals": [ 1491 | "5s", 1492 | "10s", 1493 | "30s", 1494 | "1m", 1495 | "5m", 1496 | "15m", 1497 | "30m", 1498 | "1h", 1499 | "2h", 1500 | "1d" 1501 | ], 1502 | "time_options": [ 1503 | "5m", 1504 | "15m", 1505 | "1h", 1506 | "6h", 1507 | "12h", 1508 | "24h", 1509 | "2d", 1510 | "7d", 1511 | "30d" 1512 | ] 1513 | }, 1514 | "timezone": "browser", 1515 | "title": "Redis Dashboard", 1516 | "uid": "7LB50WdVk", 1517 | "version": 1, 1518 | "weekStart": "" 1519 | } --------------------------------------------------------------------------------