Files
buryan-infra/ops/monitoring/2026-10-19-exportarr/01-exportarr.sh
T
buryan-agent 794adc438b Seerr вместо Overseerr + метрики медиасервисов и правила оповещений
Seerr (преемник Overseerr и Jellyseerr): поднят на CT 121, настроен на
Jellyfin, подключены Sonarr и Radarr, домен ombi переведён. Старый
Overseerr удалён.

Тонкости, на которые потратил время: настройки медиасервера требуют уже
открытой сессии (правится только через settings.json), первый вход требует
serverType в теле, Sonarr/Radarr ждут обязательные поля профиля.

Мониторинг: 4 экспортёра exportarr (Sonarr/Radarr/Prowlarr/Bazarr) в
Prometheus, адреса целей — на узел, а не 127.0.0.1 (Prometheus в контейнере).
Добавлены 3 правила: ошибка сбора, очередь, место. Всего 10 правил.

Карта интеграций и план по волнам — docs/INTEGRATIONS-2026-10-19.md.
2026-10-19 15:19:59 +03:00

74 lines
3.2 KiB
Bash
Raw 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.
#!/bin/bash
# ============================================================
# МОНИТОРИНГ: метрики медиасервисов (exportarr)
# ============================================================
# Раньше Prometheus видел только сам себя и один узел. Теперь —
# очередь, библиотеки, диски и ошибки Sonarr/Radarr/Prowlarr/Bazarr.
# ============================================================
set -uo pipefail
CT=134
deploy() {
local name=$1 app=$2 port=$3 url=$4 key=$5
pct exec $CT -- docker rm -f "$name" >/dev/null 2>&1
pct exec $CT -- docker run -d --name "$name" --restart unless-stopped \
-p "$port:$port" \
-e PORT="$port" -e URL="$url" -e API_KEY="$key" -e LOG_LEVEL=info \
ghcr.io/onedr0p/exportarr:latest "$app" >/dev/null 2>&1
sleep 6
local code
code=$(curl -s -o /tmp/m.txt -w '%{http_code}' --max-time 20 "http://192.168.1.134:$port/metrics" 2>/dev/null)
printf ' %-18s %-12s порт %-5s метрик: %s\n' "$name" "$app" "$port" "$(grep -c '^[a-z]' /tmp/m.txt 2>/dev/null)"
}
echo "=== 1. РАЗВЁРТЫВАЮ ЭКСПОРТЁРЫ ==="
deploy exportarr-sonarr sonarr 9707 http://192.168.1.117:8989 7ff2c05ca6cf4b669d1f6f7d3345f1cb
deploy exportarr-radarr radarr 9708 http://192.168.1.118:7878 f5da223e81244144bb5a14683e415b9f
deploy exportarr-prowlarr prowlarr 9709 http://192.168.1.119:9696 284d2086b6454d27a848d2bf81bb9055
BAZKEY=$(pct exec 120 -- bash -c "grep -oE '<ApiKey>[^<]+' /opt/bazarr/config/config/config.yaml 2>/dev/null | head -1" 2>/dev/null | tr -d '\r')
if [ -z "$BAZKEY" ]; then
BAZKEY=$(pct exec 120 -- bash -c "grep -rhoE 'apikey: .*' /opt/bazarr/config/config/config.yaml 2>/dev/null | head -1 | cut -d' ' -f2" 2>/dev/null | tr -d '\r')
fi
echo " ключ Bazarr: ${BAZKEY:0:8}…"
deploy exportarr-bazarr bazarr 9710 http://192.168.1.120:6767 "$BAZKEY"
echo
echo "=== 2. ДОБАВЛЯЮ ЦЕЛИ В PROMETHEUS ==="
pct exec $CT -- bash -c "cp /opt/prometheus/prometheus.yml /opt/prometheus/prometheus.yml.bak-\$(date +%H%M%S)"
pct pull $CT /opt/prometheus/prometheus.yml /tmp/prom.yml 2>/dev/null
python3 - <<'PY'
import re
p = "/tmp/prom.yml"
t = open(p, encoding="utf-8").read()
if "exportarr" not in t:
jobs = """
- job_name: exportarr
scrape_interval: 60s
static_configs:
- targets:
- 127.0.0.1:9707
labels: {app: sonarr}
- targets:
- 127.0.0.1:9708
labels: {app: radarr}
- targets:
- 127.0.0.1:9709
labels: {app: prowlarr}
- targets:
- 127.0.0.1:9710
labels: {app: bazarr}
"""
# вставляю перед rule_files или scrape_configs концом
if "rule_files:" in t:
t = t.replace("rule_files:", jobs.strip("\n") + "\n\nrule_files:", 1)
else:
t = t.rstrip() + "\n" + jobs
print(" цели добавлены")
else:
print(" цели уже есть")
open(p, "w", encoding="utf-8").write(t)
PY
pct push $CT /tmp/prom.yml /opt/prometheus/prometheus.yml --perms 644 2>/dev/null
pct exec $CT -- bash -c "docker exec prometheus promtool check config /etc/prometheus/prometheus.yml 2>&1 | tail -3" | sed 's/^/ /'