commit de4ac6eae3219ea3f49d8e898df135bb0697cc21 Author: Lennon Day-Reynolds Date: Fri Sep 8 14:25:03 2023 -0700 intial checkin diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66000c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config/**/* \ No newline at end of file diff --git a/Dockerfile.webhost b/Dockerfile.webhost new file mode 100644 index 0000000..3e0f9cd --- /dev/null +++ b/Dockerfile.webhost @@ -0,0 +1,7 @@ +FROM debian:stable + +RUN apt-get update +RUN apt-get install curl nginx -y +RUN curl -s https://install.zerotier.com | bash + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e24c046 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# ZeroTier Observability Metrics Tutorial + +## Preparation + +``` + +$ docker-compose up -d +$ ./setup.sh + +``` + +## Grafana Setup + +Next, open `http://localhost:3000/` in your browser and follow the steps below to configure dashboards. + +1. Login (admin/admin; set a new password or click 'skip') +2. Connections -> Data Sources -> New Data Source +3. Select 'Prometheus' (first option) +4. Set the prometheus server URL: `http://metrics-tutorial-prometheus-1:9090` +5. Click 'Save and test'; then 'Explore view' +6. + +## Cleanup + +``` + +$ ./cleanup.sh + +``` \ No newline at end of file diff --git a/cleanup.sh b/cleanup.sh new file mode 100755 index 0000000..58e0e84 --- /dev/null +++ b/cleanup.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -euxo pipefail + +docker-compose down -v + +rm -f config/prometheus/prometheus.yml diff --git a/config/prometheus/.gitkeep b/config/prometheus/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..5c6638d --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,48 @@ +services: + zerotier: + image: zerotier/zerotier:latest + privileged: true + volumes: + - zerotier-data:/var/lib/zerotier-one + networks: + - internal + devices: + - /dev/net/tun + + prometheus: + image: prom/prometheus + command: --log.level=debug + ports: + - 9090:9090 + volumes: + - prometheus-data:/prometheus + networks: + - internal + + grafana: + image: grafana/grafana-oss:latest + ports: + - 3000:3000 + volumes: + - grafana-data:/var/lib/grafana + networks: + - internal + + webhost: + build: + dockerfile: ./Dockerfile.webhost + ports: + - 8080:80 + volumes: + - webhost-data:/var/lib/zerotier-one + networks: + - internal + +volumes: + zerotier-data: + grafana-data: + prometheus-data: + webhost-data: + +networks: + internal: \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..de50532 --- /dev/null +++ b/setup.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +set -euxo pipefail + +ZT_CONTAINER=metrics-tutorial-zerotier-1 +WEB_CONTAINER=metrics-tutorial-webhost-1 + +PROM_CONFIG_PATH=./config/prometheus/prometheus.yml + +export ZT_METRICS_TOKEN=$(docker exec $ZT_CONTAINER \ + cat /var/lib/zerotier-one/metricstoken.secret) + +export ZT_ADMIN_TOKEN=$(docker exec $ZT_CONTAINER \ + cat /var/lib/zerotier-one/authtoken.secret) + +export ZT_NODE_ID=$(docker exec $ZT_CONTAINER \ + zerotier-cli info | cut -d ' ' -f 3) + +NETWORK_CONFIG_JSON=$(cat < $PROM_CONFIG_PATH +docker cp $PROM_CONFIG_PATH metrics-tutorial-prometheus-1:/prometheus/prometheus.yml +sleep 1 +docker-compose restart prometheus