feat(observability): BIT-21258 — Promtail sidecar for Loki log shipping #19
No files matched your search
+87
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install Promtail sidecar on CT 223 (ai-news-writer-dev).
|
||||
# Ships logs to Loki on CT 224; exposes metrics on :9080 for CT 224 Prometheus.
|
||||
# BIT-21258 / BIT-3601
|
||||
#
|
||||
# Usage (run as root on CT 223):
|
||||
# bash tools/observability/install-promtail-sidecar.sh
|
||||
#
|
||||
# After install, add 10.10.50.23:9080 to CT 224 file_sd:
|
||||
# paperclip/tools/network-monitoring/prometheus/file_sd/promtail_ai_platform_targets.json
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
PROMTAIL_VERSION="${PROMTAIL_VERSION:-3.4.3}"
|
||||
INSTALL_DIR="/usr/local/bin"
|
||||
CONFIG_DIR="/etc/promtail"
|
||||
POSITIONS_DIR="/var/lib/promtail"
|
||||
SERVICE_NAME="promtail-ai-news-writer"
|
||||
REPO_ROOT="/opt/bitreport/ai-news-writer"
|
||||
ARCH="$(dpkg --print-architecture 2>/dev/null || uname -m)"
|
||||
|
||||
# Map arch to Promtail release filename suffix
|
||||
case "$ARCH" in
|
||||
amd64|x86_64) ARCH_SUFFIX="amd64" ;;
|
||||
arm64|aarch64) ARCH_SUFFIX="arm64" ;;
|
||||
*) echo "Unsupported arch: $ARCH"; exit 1 ;;
|
||||
esac
|
||||
|
||||
echo "==> Installing Promtail $PROMTAIL_VERSION ($ARCH_SUFFIX) on CT 223"
|
||||
|
||||
# Download binary
|
||||
if [[ ! -f "$INSTALL_DIR/promtail" ]]; then
|
||||
TMP="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
DOWNLOAD_URL="https://github.com/grafana/loki/releases/download/v${PROMTAIL_VERSION}/promtail-linux-${ARCH_SUFFIX}.zip"
|
||||
echo "==> Downloading $DOWNLOAD_URL"
|
||||
curl -fsSL "$DOWNLOAD_URL" -o "$TMP/promtail.zip"
|
||||
unzip -q "$TMP/promtail.zip" -d "$TMP"
|
||||
install -m 755 "$TMP/promtail-linux-$ARCH_SUFFIX" "$INSTALL_DIR/promtail"
|
||||
echo "==> Installed $INSTALL_DIR/promtail"
|
||||
else
|
||||
echo "==> $INSTALL_DIR/promtail already present, skipping download"
|
||||
fi
|
||||
|
||||
# Directories
|
||||
mkdir -p "$CONFIG_DIR" "$POSITIONS_DIR"
|
||||
|
||||
# Config
|
||||
install -m 640 "$REPO_ROOT/tools/observability/promtail-config.yml" "$CONFIG_DIR/promtail.yml"
|
||||
echo "==> Config written to $CONFIG_DIR/promtail.yml"
|
||||
|
||||
# Systemd unit
|
||||
cat > "/etc/systemd/system/${SERVICE_NAME}.service" <<EOF
|
||||
[Unit]
|
||||
Description=Promtail sidecar for ai-news-writer (BIT-21258)
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=$INSTALL_DIR/promtail -config.file=$CONFIG_DIR/promtail.yml
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=promtail-ai-news-writer
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now "$SERVICE_NAME"
|
||||
echo "==> $SERVICE_NAME enabled and started"
|
||||
|
||||
# Smoke check
|
||||
sleep 3
|
||||
if curl -fsS "http://127.0.0.1:9080/ready" | grep -q "ready"; then
|
||||
echo "==> Promtail ready"
|
||||
else
|
||||
echo "WARNING: /ready did not return 'ready' — check: journalctl -u $SERVICE_NAME -n 30"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Next steps on CT 224:"
|
||||
echo " Add { \"targets\": [\"10.10.50.23:9080\"], \"labels\": { ... } } to"
|
||||
echo " paperclip/tools/network-monitoring/prometheus/file_sd/promtail_ai_platform_targets.json"
|
||||
echo " and reload Prometheus (docker compose exec prometheus kill -HUP 1)."
|
||||
@@ -0,0 +1,65 @@
|
||||
# Promtail sidecar config for CT 223 (ai-news-writer-dev, 10.10.50.23).
|
||||
# Ships Winston logs to Loki on CT 224 (10.10.50.24:3100).
|
||||
# Install: tools/observability/install-promtail-sidecar.sh
|
||||
# BIT-21258 / BIT-3601
|
||||
|
||||
server:
|
||||
http_listen_port: 9080
|
||||
log_level: info
|
||||
|
||||
positions:
|
||||
filename: /var/lib/promtail/positions.yaml
|
||||
|
||||
clients:
|
||||
- url: http://10.10.50.24:3100/loki/api/v1/push
|
||||
|
||||
scrape_configs:
|
||||
- job_name: ai_news_writer_combined
|
||||
static_configs:
|
||||
- targets:
|
||||
- localhost
|
||||
labels:
|
||||
job: ai_news_writer
|
||||
env: dev
|
||||
service: ai_news_writer
|
||||
ct: "223"
|
||||
log_level: combined
|
||||
__path__: /opt/bitreport/ai-news-writer/logs/combined.log
|
||||
pipeline_stages:
|
||||
- json:
|
||||
expressions:
|
||||
level: level
|
||||
message: message
|
||||
service: service
|
||||
timestamp: timestamp
|
||||
on_error: keep
|
||||
- labels:
|
||||
level:
|
||||
service:
|
||||
- output:
|
||||
source: message
|
||||
|
||||
- job_name: ai_news_writer_error
|
||||
static_configs:
|
||||
- targets:
|
||||
- localhost
|
||||
labels:
|
||||
job: ai_news_writer
|
||||
env: dev
|
||||
service: ai_news_writer
|
||||
ct: "223"
|
||||
log_level: error
|
||||
__path__: /opt/bitreport/ai-news-writer/logs/error.log
|
||||
pipeline_stages:
|
||||
- json:
|
||||
expressions:
|
||||
level: level
|
||||
message: message
|
||||
service: service
|
||||
timestamp: timestamp
|
||||
on_error: keep
|
||||
- labels:
|
||||
level:
|
||||
service:
|
||||
- output:
|
||||
source: message
|
||||
Reference in new issue
Block a user