scripts for loki clients

This commit is contained in:
coesensbert committed 2024-06-19 14:55:41 +02:00
1 parent cf961a5a1f
commit 72eb0f30a3
2 files changed
+90

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
#!/bin/sh -e
# This script will setup docker to push all newly created container logs to https://int.loki.grid.tf
# NOTE: existing containers will need to be recreated to send their logs to Loki
### Install docker plugin
docker plugin install grafana/loki-docker-driver:2.9.2 --alias loki --grant-all-permissions
### Edit docker daemon config file
cat << EOF > /etc/docker/daemon.json
{
"debug" : true,
"log-driver": "loki",
"log-opts": {
"loki-url": "https://int.loki.grid.tf/loki/api/v1/push",
"loki-batch-size": "400"
}
}
EOF
### Restart docker
systemctl restart docker
echo "Don't forget to recreate all containers that should send their logs to Loki! This config does not apply to existing containers"
+68
View File
@@ -0,0 +1,68 @@
#/bin/bash
# This script will setup Promtail to push to https://int.loki.grid.tf
### Install Promtail
mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor > /etc/apt/keyrings/grafana.gpg
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | tee /etc/apt/sources.list.d/grafana.list
apt update && apt install promtail -y
usermod -a -G adm promtail
### Set config
cat << EOF > /etc/promtail/config.yml
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: https://int.loki.grid.tf/loki/api/v1/push
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
host: ${HOSTNAME}
job: varlogs
__path__: /var/log/*log
- job_name: journal
journal:
json: false
max_age: 24h
path: /var/log/journal
labels:
host: ${HOSTNAME}
job: systemd-journal
relabel_configs:
- source_labels: ['__journal__systemd_unit']
target_label: 'unit'
EOF
### Edit service
cat << EOF > /etc/systemd/system/promtail.service
[Unit]
Description=Promtail service
After=network.target
[Service]
Type=simple
User=promtail
Environment="HOSTNAME=%H"
ExecStart=/usr/bin/promtail -config.file /etc/promtail/config.yml -config.expand-env=true
# Give a reasonable amount of time for promtail to start up/shut down
TimeoutSec = 60
Restart = on-failure
RestartSec = 2
[Install]
WantedBy=multi-user.target
EOF
### Reload and restart
systemctl daemon-reload
systemctl restart promtail
systemctl status promtail