91 lines
2.1 KiB
Bash
Executable file
91 lines
2.1 KiB
Bash
Executable file
#!/bin/bash
|
|
# Promtail auf CT600 wp-mirror (pve-mu-3) — wie CT101, Loki via Tailscale
|
|
set -euo pipefail
|
|
apt-get update && apt-get install -y wget unzip curl systemd-journal-remote 2>/dev/null || apt-get install -y wget unzip curl
|
|
cd /tmp
|
|
wget -q https://github.com/grafana/loki/releases/download/v3.0.0/promtail-linux-amd64.zip
|
|
unzip -o promtail-linux-amd64.zip
|
|
chmod +x promtail-linux-amd64
|
|
mv promtail-linux-amd64 /usr/local/bin/promtail
|
|
cat > /etc/promtail-config.yml << 'EOF'
|
|
server:
|
|
http_listen_port: 9080
|
|
grpc_listen_port: 0
|
|
|
|
positions:
|
|
filename: /tmp/positions.yaml
|
|
|
|
clients:
|
|
- url: http://100.109.206.43:3100/loki/api/v1/push
|
|
|
|
scrape_configs:
|
|
- job_name: journal
|
|
journal:
|
|
max_age: 12h
|
|
labels:
|
|
job: systemd
|
|
host: wp-mirror
|
|
relabel_configs:
|
|
- source_labels: [__journal__systemd_unit]
|
|
target_label: unit
|
|
|
|
- job_name: system
|
|
static_configs:
|
|
- targets:
|
|
- localhost
|
|
labels:
|
|
job: varlogs
|
|
host: wp-mirror
|
|
__path__: /var/log/*log
|
|
|
|
- job_name: docker
|
|
static_configs:
|
|
- targets:
|
|
- localhost
|
|
labels:
|
|
job: dockerlogs
|
|
host: wp-mirror
|
|
__path__: /var/lib/docker/containers/*/*.log
|
|
pipeline_stages:
|
|
- json:
|
|
expressions:
|
|
output: log
|
|
stream: stream
|
|
attrs:
|
|
- json:
|
|
expressions:
|
|
tag:
|
|
source: attrs
|
|
- regex:
|
|
expression: (?P<container_name>(?:[^|]*[^|]))
|
|
source: tag
|
|
- timestamp:
|
|
format: RFC3339Nano
|
|
source: time
|
|
- labels:
|
|
tag:
|
|
stream:
|
|
container_name:
|
|
- output:
|
|
source: output
|
|
EOF
|
|
cat > /etc/systemd/system/promtail.service << 'EOF'
|
|
[Unit]
|
|
Description=Promtail Log Agent
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=root
|
|
ExecStart=/usr/local/bin/promtail -config.file=/etc/promtail-config.yml
|
|
Restart=always
|
|
RestartSec=10
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
systemctl daemon-reload
|
|
systemctl enable promtail
|
|
systemctl restart promtail
|
|
systemctl is-active promtail
|