intial checkin

This commit is contained in:
Lennon Day-Reynolds
2023-09-13 08:06:44 -07:00
commit de4ac6eae3
7 changed files with 152 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
config/**/*
+7
View File
@@ -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;"]
+29
View File
@@ -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
```
Executable
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
set -euxo pipefail
docker-compose down -v
rm -f config/prometheus/prometheus.yml
View File
+48
View File
@@ -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:
Executable
+60
View File
@@ -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 <<END
{
"name": "metrics-demo",
"private": false,
"ipAssignmentPools": [
{
"ipRangeStart": "10.10.0.1",
"ipRangeEnd": "10.10.0.254"
}
],
"v4AssignMode": true
}
END)
NETWORK_INFO=$(docker exec $ZT_CONTAINER curl -H "X-ZT1-Auth: $ZT_ADMIN_TOKEN" \
-d "$NETWORK_CONFIG_JSON" \
http://localhost:9993/controller/network/${ZT_NODE_ID}______)
NETWORK_ID=$(echo "$NETWORK_INFO" | jq -r .nwid)
docker exec $ZT_CONTAINER zerotier-cli join $NETWORK_ID
docker exec $WEB_CONTAINER zerotier-cli join $NETWORK_ID
PROM_CONFIG=$(cat <<END
scrape_configs:
- job_name: zerotier-one
honor_labels: true
scrape_interval: 15s
metrics_path: /metrics
static_configs:
- targets:
- $ZT_CONTAINER:9993
labels:
group: zerotier-one
node_id: $ZT_NODE_ID
authorization:
credentials: $ZT_METRICS_TOKEN
END)
echo "$PROM_CONFIG" > $PROM_CONFIG_PATH
docker cp $PROM_CONFIG_PATH metrics-tutorial-prometheus-1:/prometheus/prometheus.yml
sleep 1
docker-compose restart prometheus