Files
tailscale-tools/README.md
alf 11f01df528 Add tailscale-api.py: HTTP-API für Homepage
- Python-HTTP-Server stellt Tailscale-Traffic als JSON bereit
- Pro Gerät: Upload/Download in Mbit/s, Online-Status
- Gesamtwerte und Peer-Statistik
- systemd-Service-Datei inklusive
- Homepage Widget Beispiel-Konfiguration
- Läuft direkt auf dem Exit-Node (kein Docker nötig)

Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-10-28 13:54:31 +01:00

142 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# tailscale-tools
Scripts für Tailscale Exit-Node Monitoring und mehr.
## tailscale-api.py – HTTP-API für Homepage
Stellt Tailscale-Traffic-Daten als JSON über HTTP bereit. Ideal für [Homepage](https://github.com/gethomepage/homepage) oder andere Dashboards.
### JSON-Ausgabe
```json
{
"devices": [
{"name": "PC7-77", "upload_mbit": 1.23, "download_mbit": 4.56, "online": true, "type": "self"},
{"name": "S22 von Alf", "upload_mbit": 0.12, "download_mbit": 0.34, "online": true, "type": "peer"}
],
"total": {"upload_mbit": 1.35, "download_mbit": 4.90},
"peers_online": 15,
"peers_total": 28,
"self_name": "heimathafen"
}
```
### Installation auf dem Exit-Node
```bash
# 1. Script installieren
sudo cp tailscale-api.py /usr/local/bin/
sudo chmod +x /usr/local/bin/tailscale-api.py
# 2. systemd-Service einrichten
sudo cp tailscale-api.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now tailscale-api
# 3. Testen
curl http://localhost:8080/tailscale
```
### Homepage Widget
Siehe `homepage-widget.yaml` für Beispiel-Konfiguration.
```yaml
- Tailscale Exit-Node:
icon: tailscale.png
widget:
type: customapi
url: http://100.87.87.105:8080/tailscale
refreshInterval: 10000
mappings:
- label: Upload gesamt
field: total.upload_mbit
suffix: Mbit/s
- label: Download gesamt
field: total.download_mbit
suffix: Mbit/s
```
### Konfiguration
Im Script anpassbar:
```python
PORT = 8080 # HTTP-Port
MEASURE_INTERVAL = 1 # Sekunden zwischen Messungen (für Rate)
MAX_DEVICES = 10 # Max. Geräte in der Ausgabe
```
---
## exitnode-bw.sh
Zeigt die Up-/Download-Bandbreite ausgewählter Geräte an, die über einen Tailscale Exit-Node verbunden sind.
### Vorschau
```
⇅ Exit-Node Traffic 12:45:30
● PC7-77 ↑ ████████████████████ 12.34 Mbit/s ↓ ██████ 3.21 Mbit/s
● s22-von-alf ↑ ██ 0.45 Mbit/s ↓ █ 0.12 Mbit/s
Interval: 5s | Geräte: PC7-77 s22 | Strg+C zum Beenden
```
### Voraussetzungen
```bash
# Tailscale CLI
curl -fsSL https://tailscale.com/install.sh | sh
# jq (JSON-Prozessor)
sudo apt install jq # Debian/Ubuntu
sudo pacman -S jq # Arch
brew install jq # macOS
# gum (für hübsche Terminal-Ausgabe)
# https://github.com/charmbracelet/gum
```
### Installation
```bash
git clone gitea:alf/tailscale-tools.git
cd tailscale-tools
chmod +x exitnode-bw.sh
```
### Benutzung
```bash
./exitnode-bw.sh
```
### Konfiguration
Im Script anpassen:
```bash
INTERVAL=5 # Aktualisierungsintervall in Sekunden
BARWIDTH=40 # Breite der Balken in Zeichen
MIN_BAR=1 # Mindest-Balkenlänge bei Aktivität
DEVICES=("PC7-77" "s22") # Geräte (Partial-Match, case-insensitive)
```
### Funktionsweise
1. Erfasst alle 5 Sekunden den Status von `tailscale status --json`
2. Berechnet die Differenz der übertragenen Bytes (Tx/Rx) zwischen zwei Messungen
3. Zeigt Upload (↑) und Download (↓) als Balkendiagramm an
4. Skaliert die Balken relativ zum Gerät mit der höchsten Bandbreite
### Legende
| Symbol | Bedeutung |
|--------|-----------|
| ● | Gerät ist online im Tailnet |
| ○ | Gerät ist offline |
| ↑ | Upload (Tx) |
| ↓ | Download (Rx) |