diff --git a/README.md b/README.md index 3c4a619..eb54d31 100644 --- a/README.md +++ b/README.md @@ -25,12 +25,108 @@ sudo systemctl status towerd sudo journalctl -u towerd -f ``` -## Config +## Metrics -Edit in `/etc/towerd/env` +Originally I was going to write to my influxdb server over the network but I learned that influxdb can be configured +to save locally and drain when network is up, which would be pretty awesome for edge computing like the tower. So, +new architecture is to run locally and configure it to replicate. +### Local Config + +Create `/opt/towerd/.env` + +```shell +INFLUXDB_INIT_PASSWORD=change-me +INFLUXDB_INIT_ADMIN_TOKEN=change-me-to-a-long-random-token +INFLUXDB_INIT_ORG=tower +INFLUXDB_INIT_BUCKET=tower ``` -TOWERD_INFLUX_TOKEN= -TOWERD_INFLUX_ORG= -TOWERD_INFLUX_BUCKET= -``` \ No newline at end of file + +then + +```shell +cd /opt/towerd +docker compose up -d +``` + +Init vars only matter once + +InfluxDB listens on `127.0.0.1:8086` only. + +### Configure towerd + +Create `/etc/towerd/env`: + +```shell +TOWERD_INFLUX_URL=http://127.0.0.1:8086 +TOWERD_INFLUX_ORG=tower +TOWERD_INFLUX_BUCKET=tower +TOWERD_INFLUX_TOKEN= +TOWERD_INFLUX_HOST=kw1fox-1 + +# optional +# TOWERD_INFLUX_INTERVAL_S=30 +``` + +Restart towerd after editing: + +```shell +sudo systemctl restart towerd +``` + +### Replicate to remote InfluxDB + +Need influx cli + +```shell +# register the remote server +influx remote create \ + --host http://127.0.0.1:8086 \ + --token "$TOWERD_INFLUX_TOKEN" \ + --name kitsune-remote \ + --remote-url http://influx.kitsunehosting.net:8086 \ + --remote-api-token \ + --remote-org-id + +# list remotes to get the ID from the previous step +influx remote list \ + --host http://127.0.0.1:8086 \ + --token "$TOWERD_INFLUX_TOKEN" + +# replicate the local bucket to the remote bucket +influx replication create \ + --host http://127.0.0.1:8086 \ + --token "$TOWERD_INFLUX_TOKEN" \ + --name tower-to-kitsune \ + --remote-id \ + --local-bucket-id \ + --remote-bucket +``` + +Find the local bucket ID: + +```shell +influx bucket list \ + --host http://127.0.0.1:8086 \ + --token "$TOWERD_INFLUX_TOKEN" +``` + +Check replication queue health: + +```shell +influx replication list \ + --host http://127.0.0.1:8086 \ + --token "$TOWERD_INFLUX_TOKEN" +``` + +## systemd + +`towerd` loads `/etc/towerd/env` via `EnvironmentFile`. If using Docker for InfluxDB, ensure Docker starts before towerd: + +```ini +[Unit] +After=docker.service +Wants=docker.service +``` + +Add those lines to `/etc/systemd/system/towerd.service` under `[Unit]`. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7b0925b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +services: + influxdb: + image: influxdb:2.7 + restart: unless-stopped + ports: + - "127.0.0.1:8086:8086" + volumes: + - influx-data:/var/lib/influxdb2 + environment: + DOCKER_INFLUXDB_INIT_MODE: setup + DOCKER_INFLUXDB_INIT_USERNAME: admin + DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_INIT_PASSWORD} + DOCKER_INFLUXDB_INIT_ORG: ${INFLUXDB_INIT_ORG:-tower} + DOCKER_INFLUXDB_INIT_BUCKET: ${INFLUXDB_INIT_BUCKET:-tower} + DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: ${INFLUXDB_INIT_ADMIN_TOKEN} + +volumes: + influx-data: diff --git a/src/config.rs b/src/config.rs index 5a8e865..5c97411 100644 --- a/src/config.rs +++ b/src/config.rs @@ -41,7 +41,7 @@ impl InfluxConfig { Some(Self { url: std::env::var("TOWERD_INFLUX_URL") - .unwrap_or_else(|_| "http://influx.kitsunehosting.net:8086".into()), + .unwrap_or_else(|_| "http://127.0.0.1:8086".into()), org, bucket, token, diff --git a/systemd/towerd.service b/systemd/towerd.service index 276c68c..19ee70f 100644 --- a/systemd/towerd.service +++ b/systemd/towerd.service @@ -1,6 +1,7 @@ [Unit] Description=Tower Daemon -After=multi-user.target +After=multi-user.target docker.service +Wants=docker.service [Service] Type=simple