--- title: description: date: 2023-04-20 lang: zh-tw tags: - 樹莓派 - Linux - docker --- # 樹莓派筆記- Grafana儀表板+系統監控 ## docker compose `docker compose` ```yml= version: '3.3' networks: default: name: ${DOCKER_MY_NETWORK} external: true services: grafana: container_name: grafana image: grafana/grafana:9.4.7 restart: unless-stopped user: root env_file: - stack.env volumes: - ${HOME_PATH}/grafana:/var/lib/grafana - ${HOME_PATH}/grafana/grafana.ini:/etc/grafana/grafana.ini - ${HOME_PATH}/grafana/ldap.toml:/etc/grafana/ldap.toml expose: - 3000 prometheus: container_name: prometheus image: prom/prometheus:v2.43.0 restart: unless-stopped user: root command: - '--config.file=/etc/prometheus/prometheus.yml' - '--storage.tsdb.path=/prometheus' - '--web.console.libraries=/etc/prometheus/console_libraries' - '--web.console.templates=/etc/prometheus/consoles' - '--storage.tsdb.retention.time=240h' - '--web.enable-lifecycle' env_file: - stack.env volumes: - ${HOME_PATH}/prometheus/prometheus:/prometheus - ${HOME_PATH}/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml expose: - 9090 nodeexporter: image: prom/node-exporter:v1.5.0 container_name: nodeexporter restart: unless-stopped command: - '--path.procfs=/host/proc' - '--path.rootfs=/rootfs' - '--path.sysfs=/host/sys' - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)' volumes: - /proc:/host/proc:ro - /sys:/host/sys:ro - /:/rootfs:ro env_file: - stack.env expose: - 9100 cadvisor: image: gcr.io/cadvisor/cadvisor:v0.47.1 container_name: cadvisor restart: unless-stopped privileged: true devices: - /dev/kmsg:/dev/kmsg volumes: - /:/rootfs:ro - /var/run:/var/run:ro - /sys:/sys:ro - /var/lib/docker:/var/lib/docker:ro - /cgroup:/cgroup:ro #doesn't work on MacOS only for Linux env_file: - stack.env expose: - 3000 ``` ## env `stack.env` ```env= DOCKER_MY_NETWORK=caddy_net HOME_PATH=<your path> TZ=Asia/Taipei GF_SECURITY_ADMIN_USER=admin GF_SECURITY_ADMIN_PASSWORD=<隨機密碼> GF_USERS_ALLOW_SIGN_UP=false GF_SMTP_ENABLED=true GF_SMTP_HOST=smtp.sendgrid.net:587 GF_SMTP_USER=apikey GF_SMTP_PASSWORD=<YOUR_API_KEY> ``` > 免費方案1天可以送100封 > 先驗證發送人 https://app.sendgrid.com/settings/sender_auth > 可以使用"域名認證" > 在依照 https://app.sendgrid.com/guide/integrate 創建 > sender@後面就填他給你的DOMAIN ## Caddyfile 添加以下 `Caddyfile` ```Caddyfile= grafana.{$MY_DOMAIN} { log { output file /var/log/caddy/access.log } forward_auth authelia:9091 { uri /api/verify?rd=https://auth.{$MY_DOMAIN}/ copy_headers Remote-User Remote-Groups Remote-Name Remote-Email ## This import needs to be included if you're relying on a trusted proxies configuration. import trusted_proxy_list } reverse_proxy grafana:3000 { ## This import needs to be included if you're relying on a trusted proxies configuration. import trusted_proxy_list } } ``` ## 使用 只要依照這篇操作即可 https://github.com/DoTheEvo/selfhosted-apps-docker/blob/master/prometheus_grafana_loki/readme.md#first-run-and-grafana-configuration ## Ref * https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/prometheus_grafana_loki * https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/ * https://dbt3ch.com/books/prometheus-grafana-dashboard * https://www.authelia.com/integration/openid-connect/grafana/ * https://github.com/stefanprodan/dockprom