diff --git a/Dockerfile.webhost b/Dockerfile.webhost index 3e0f9cd..48d9d3a 100644 --- a/Dockerfile.webhost +++ b/Dockerfile.webhost @@ -3,5 +3,6 @@ FROM debian:stable RUN apt-get update RUN apt-get install curl nginx -y RUN curl -s https://install.zerotier.com | bash +COPY ./webhost-init.sh / -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +CMD ["/webhost-init.sh"] diff --git a/README.md b/README.md index e24c046..3007811 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,18 @@ # ZeroTier Observability Metrics Tutorial +This repository has an example docker-compose configuration and setup scripts to run a ZeroTier network along with an observability stack based on Prometheus and Grafana. + +To run this locally, you'll need the following tools installed: + +- Docker + docker-compose +- jq + +We've tested this demo on MacOS and Linux; on Windows, you'll need to use WSL2 for a local Linux environment. (Note: pull requests to add PowerShell support for the setup script are welcome!) + +You can use this type of monitoring pipeline to measure the health and activity of your networks, whether you're using our [managed environment](https://my.zerotier.com) or hosting your own controller. For this example, we're running a standalone controller, which allows us to avoid capturing and injecting a valid ZeroTier Central API token into the demo environment, but the same observability tools and configuration methods will work for managed networks as well. + +For more information on the full set of metrics we expose and how to configure your own Prometheus instance to extract them for visualization and alerting, see the [ZeroTierOne README](https://github.com/zerotier/ZeroTierOne#prometheus-metrics). + ## Preparation ``` @@ -13,12 +26,14 @@ $ ./setup.sh Next, open `http://localhost:3000/` in your browser and follow the steps below to configure dashboards. +TODO: add screenshots for each step below + 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. +6. Select 'zt_packet' in the 'Metric' dropdown, then 'Last 15 minutes' in the range picker in the upper-right. Click 'Run query' and the graph will be populated in the bottom half of the screen. ## Cleanup @@ -26,4 +41,15 @@ Next, open `http://localhost:3000/` in your browser and follow the steps below t $ ./cleanup.sh -``` \ No newline at end of file +``` + +## Next Steps + +Now that you've set up a basic pipeline, you can try creating a custom dashboard reporting ZeroTier metrics. + +TODO: find good Grafana setup tutorial + +The following metrics in particular may prove useful for general health + activity monitoring: + +- zt_packet (labeled by rx/tx direction, peer node ID, network ID, etc.) +- zt_peer_path (active paths to known network peers) diff --git a/docker-compose.yaml b/docker-compose.yaml index 5c6638d..3ddea8f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -29,6 +29,7 @@ services: - internal webhost: + privileged: true build: dockerfile: ./Dockerfile.webhost ports: @@ -37,6 +38,8 @@ services: - webhost-data:/var/lib/zerotier-one networks: - internal + devices: + - /dev/net/tun volumes: zerotier-data: diff --git a/setup.sh b/setup.sh index de50532..5f7cb1a 100755 --- a/setup.sh +++ b/setup.sh @@ -1,20 +1,43 @@ #!/bin/bash -set -euxo pipefail +set -euo pipefail -ZT_CONTAINER=metrics-tutorial-zerotier-1 +_=$(jq --version) +if [ $? != 0 ]; then + echo "Missing 'jq' in path; exiting" +fi + +CTRL_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) +get_zt_node_id() { + CONTAINER=$1 + echo $(docker exec $CONTAINER zerotier-cli info | cut -d ' ' -f 3) +} -export ZT_ADMIN_TOKEN=$(docker exec $ZT_CONTAINER \ - cat /var/lib/zerotier-one/authtoken.secret) +get_zt_token() { + CONTAINER=$1 + TOKEN_KIND=${2:='metrics'} + TOKEN_PATH="/var/lib/zerotier-one/${TOKEN_KIND}token.secret" -export ZT_NODE_ID=$(docker exec $ZT_CONTAINER \ - zerotier-cli info | cut -d ' ' -f 3) + echo $(docker exec $CONTAINER cat $TOKEN_PATH) +} + +get_zt_ipaddr() { + CONTAINER=$1 + NWID=$2 + + echo $(docker exec $CONTAINER zerotier-cli get $NWID ip | egrep '^\d\d\d.') +} + +export CTRL_NODE_ID=$(get_zt_node_id $CTRL_CONTAINER) +export WEB_NODE_ID=$(get_zt_node_id $WEB_CONTAINER) + +export CTRL_METRICS_TOKEN=$(get_zt_token $CTRL_CONTAINER 'metrics') +export CTRL_ADMIN_TOKEN=$(get_zt_token $CTRL_CONTAINER 'auth') +export WEB_METRICS_TOKEN=$(get_zt_token $WEB_CONTAINER 'metrics') 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 + +HOST_INFO=$(cat <