Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
kurokobo committed Feb 26, 2021
0 parents commit 883eff2
Show file tree
Hide file tree
Showing 28 changed files with 3,314 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
original
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 kurokobo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Examples of AutoMuteUs deployments

This repository provides examples of how to use [Self-Hosted AutoMuteUs](https://github.com/denverquane/automuteus) in combination with other useful tools like Grafana dashboard, Let's Encrypt certficate, etc.

![image](https://user-images.githubusercontent.com/2920259/109378149-82290d00-7913-11eb-889e-83eb091d83e9.png)

## Contents

### 🚀 [AutoMuteUs with Grafana Dashboard](grafana-dashboard)

📁 [**grafana-dashboard**](grafana-dashboard)

This is an example of how to use AutoMuteUs with Grafana dashboard in easy way. All information will be aggregated in Prometheus automatically and will also be visualized in a pre-configured dashboard.

![image](https://user-images.githubusercontent.com/2920259/109378149-82290d00-7913-11eb-889e-83eb091d83e9.png)

### 🚀 [AutoMuteUs over SSL](reverse-proxy-with-ssl-cert)

📁 [**reverse-proxy-with-ssl-cert**](reverse-proxy-with-ssl-cert)

By default, WebSocket communication between AmongUsCapture and Galactus is not encrypted. This is an example of encrypting the communication by using a reverse proxy and a certificate issued by Let's Encrypt. Of course, the certificate will be renewed automatically on a regular basis.

![image](https://user-images.githubusercontent.com/2920259/109382377-6ded0c00-7923-11eb-8be2-68a89bd83dad.png)

### 🚀 Tips and Tricks

Some tips and tricks for someone in the future.

* 📋 [**Minimal bot permissions**](tips/minimal-bot-permissions.md)
* This introduces the minimum privileges required for your bots on discord.
* 📋 [**Backup and Restore**](tips/backup-and-restore.md)
* How to backup and restore your AutoMuteUs.
* 📋 [**Secure Redis**](tips/secure-redis.md)
* This introduces the way to secure your Redis by password authentication.

## Contribution

Contributions are welcome! If you have a good implementation, please feel free to create a new PR.
147 changes: 147 additions & 0 deletions grafana-dashboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# AutoMuteUs with Grafana Dashboard using Prometheus

This is an example of AutoMuteUs with pre-configured Grafana dashboard in easy way. All information will be aggregated in Prometheus automatically.

![image](https://user-images.githubusercontent.com/2920259/109378149-82290d00-7913-11eb-889e-83eb091d83e9.png)

## Installation

Create your `.env` file using `sample.env` in this repository as in the official procedure. This `sample.env` contains additional configuration for Grafana and Prometheus.

```bash
# Change these for prometheus and grafana dashboard.
# For the *_TAG, refer followings and specify the latest versions without the leading "v".
# Note that Node exporter and cAdvisor are required only for full-featured version.
# - Grafana: https://github.com/grafana/grafana/releases
# - Prometheus: https://github.com/prometheus/prometheus/releases
# - Json exporter (used as Galactus exporter): https://github.com/prometheus-community/json_exporter/releases
# - Node exporter: https://github.com/prometheus/node_exporter/releases
# - cAdvisor: https://github.com/google/cadvisor/releases
GRAFANA_TAG=7.4.3
PROMETHEUS_TAG=2.25.0
PROMETHEUS_GALACTUS_EXPORTER_TAG=0.3.0
PROMETHEUS_DOCKER_NODE_EXPORTER_TAG=1.1.1
PROMETHEUS_CADVISOR_TAG=0.37.5

# Specify default username and password for Grafana
GRAFANA_USER=
GRAFANA_PASS=
GRAFANA_EXTERNAL_PORT=3000
```

Now all you have to do is just start it. If you want to use full-featured version that includes the information from your Docker host (i.e. CPU load per Container, etc.), use `docker-compose.full.yml` instead.

```bash
# Start standard version.
docker-compose up -d

# Start full-featured version.
# To use this, you need to specify the name of the compose file by -f option
# not only when invoke "up" but also any other operations i.e. "ps", "logs", "down", etc.
docker-compose -f docker-compose.full.yml up -d
```

Within a few minutes, you can view Grafana at the following URL:

```
http://<your-docker-host>:3000/
```

Once you logged in, now you can access pre-configured dashboard named **AutoMuteUs** from the `Dashboards` > `Manage` menu on the left. It may take a few minutes for the values to actually start showing up.

### Troubleshoot

If you are using full-featured version on the Docker running on CentOS, Fedora, or RHEL, there is a possibility that it will fail to start. This is due to the limitations of cAdvisor, which is used to gather information about your container host.

If this happens, uncomment the following lines for the `prometheus-cadvisor` service in the `docker-compose.yml` file.

```bash
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
# If you want to run this container on CentOS, Fedora, or RHEL,
# an additional mount for /cgroup is required.
- /cgroup:/cgroup:ro
# And privileged mode is also reqired for CentOS, Fedora, or RHEL.
privileged: true
```

## Architecture

### Data persistence

The collected data will be stored in a time series database in Prometheus. The data will be retained for 15 days according to Prometheus default.

The data will be persisted in the persistent volume named `prometheus-data`.

### Data gathering

To reduce unnecessary resource consumption, data is collected every 60 seconds, more spaced out than the default.

### Gather from AutoMuteUs

AutoMuteUs has built-in Prometheus collector using port `2112` by default. So we can simply scrape this endpoint.

```yaml
- job_name: discord_stats
static_configs:
- targets:
- automuteus:2112
metrics_path: /metrics
```
This provides some values about Discord API requests like which types of bots has used to mute / deafen users.
### Gather from Galactus
By querying Galactus broker using HTTP, we can get a JSON strings including some statistics. So we can scrape this JSON strings using Json exporter.
```yaml
- job_name: automuteus_stats
metrics_path: /probe
static_configs:
- targets:
- http://galactus:8123/
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: prometheus-galactus-exporter:7979
```
### Gather from Docker host
This is achieved by Node exporter and cAdvisor.
```yaml
- job_name: docker_node_stats
static_configs:
- targets:
- prometheus-docker-node-exporter:9100

- job_name: docker_container_stats
static_configs:
- targets:
- prometheus-cadvisor:8080
```
The Node exporter needs to have access to a different namespace to get all the information, but allowing this may unintentionally expose ports to the outside world.
For this reason, in this Compose file, lots of metrics are disabled to limit the permissions to the same level as normal containers.
```yaml
prometheus-docker-node-exporter:
image: quay.io/prometheus/node-exporter:v${PROMETHEUS_DOCKER_NODE_EXPORTER_TAG:?err}
command:
- --path.rootfs=/host
- --collector.disable-defaults
- --collector.cpu
- --collector.filesystem
- --collector.meminfo
volumes:
- /:/host:ro,rslave
```
144 changes: 144 additions & 0 deletions grafana-dashboard/docker-compose.full.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
version: "3"

services:
automuteus:
# Either:
# - Use a prebuilt image
image: denverquane/amongusdiscord:${AUTOMUTEUS_TAG:?err}
# - Build image from local source
#build: .
# - Build image from github directly
#build: http://github.com/denverquane/automuteus.git
restart: always
environment:
# These are required and will fail if not present
- DISCORD_BOT_TOKEN=${DISCORD_BOT_TOKEN:?err}
- HOST=${GALACTUS_HOST:?err}
- POSTGRES_USER=${POSTGRES_USER:?err}
- POSTGRES_PASS=${POSTGRES_PASS:?err}

# These Variables are optional
- WORKER_BOT_TOKENS=${WORKER_BOT_TOKENS:-}
- EMOJI_GUILD_ID=${EMOJI_GUILD_ID:-}
- CAPTURE_TIMEOUT=${CAPTURE_TIMEOUT:-}
- AUTOMUTEUS_LISTENING=${AUTOMUTEUS_LISTENING:-}

# Do **NOT** change this
- REDIS_ADDR=${AUTOMUTEUS_REDIS_ADDR}
- GALACTUS_ADDR=${GALACTUS_ADDR}
- POSTGRES_ADDR=${POSTGRES_ADDR}
depends_on:
- redis
- galactus
- postgres
volumes:
- "bot-logs:/app/logs"

galactus:
ports:
# See sample.env for details, but in general, match the GALACTUS_EXTERNAL_PORT w/ the GALACTUS_HOST's port
- ${GALACTUS_EXTERNAL_PORT:-8123}:${BROKER_PORT}
image: automuteus/galactus:${GALACTUS_TAG:?err}
restart: always
environment:
# Do **NOT** change these
- DISCORD_BOT_TOKEN=${DISCORD_BOT_TOKEN:?err}
- BROKER_PORT=${BROKER_PORT}
- REDIS_ADDR=${GALACTUS_REDIS_ADDR}
- GALACTUS_PORT=${GALACTUS_PORT}
depends_on:
- redis

redis:
image: redis:alpine
restart: always
volumes:
- "redis-data:/data"

postgres:
image: postgres:12-alpine
restart: always
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASS}
volumes:
- "postgres-data:/var/lib/postgresql/data"

grafana:
image: grafana/grafana:${GRAFANA_TAG:?err}
restart: always
environment:
- GF_INSTALL_PLUGINS=petrslavotinek-carpetplot-panel, grafana-piechart-panel
- GF_SECURITY_ADMIN_USER=${GRAFANA_USER:?err}
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASS:?err}
ports:
- ${GRAFANA_EXTERNAL_PORT:-3000}:3000
volumes:
- ./grafana/datasource.yml:/etc/grafana/provisioning/datasources/datasource.yml
- ./grafana/dashboard.yml:/etc/grafana/provisioning/dashboards/dashboard.yml
- ./grafana/dashboard.full.json:/etc/grafana/provisioning/dashboards/dashboard.json
- grafana-data:/var/lib/grafana

prometheus:
image: prom/prometheus:v${PROMETHEUS_TAG:?err}
restart: always
# should not be exported externally; uncomment for debugging / testing purposes only.
#ports:
# - 9090:9090
volumes:
- ./prometheus/prometheus.full.yml:/etc/prometheus/prometheus.yml
- prometheus-data:/prometheus

prometheus-galactus-exporter:
image: quay.io/prometheuscommunity/json-exporter:v${PROMETHEUS_GALACTUS_EXPORTER_TAG:?err}
restart: always
# should not be exported externally; uncomment for debugging / testing purposes only.
#ports:
# - 7979:7979
command:
- --config.file=/config.yml
volumes:
- ./json-exporter/config.yml:/config.yml

prometheus-docker-node-exporter:
image: quay.io/prometheus/node-exporter:v${PROMETHEUS_DOCKER_NODE_EXPORTER_TAG:?err}
# should not be exported externally; uncomment for debugging / testing purposes only.
#ports:
# - 9100:9100
command:
- --path.rootfs=/host
- --collector.disable-defaults
- --collector.cpu
- --collector.filesystem
- --collector.meminfo
volumes:
- /:/host:ro,rslave

prometheus-cadvisor:
image: gcr.io/cadvisor/cadvisor:v${PROMETHEUS_CADVISOR_TAG:?err}
restart: always
# should not be exported externally; uncomment for debugging / testing purposes only.
#ports:
# - 8080:8080
command:
- --store_container_labels=false
- --docker_only=false
- --disable_root_cgroup_stats=false
- --disable_metrics=tcp,advtcp,udp,sched,process,hugetlb,disk
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
# If you want to run this container on CentOS, Fedora, or RHEL,
# an additional mount for /cgroup is required.
#- /cgroup:/cgroup:ro
# And privileged mode is also reqired for CentOS, Fedora, or RHEL.
#privileged: true

volumes:
bot-logs:
redis-data:
postgres-data:
grafana-data:
prometheus-data:
Loading

0 comments on commit 883eff2

Please sign in to comment.