From d0adff33d777be4371caf692b4b27abac5c87ffd Mon Sep 17 00:00:00 2001 From: Alessio Zeni Date: Fri, 18 Oct 2024 14:26:34 +0200 Subject: [PATCH 1/2] backup --- docker/backup-volumes.sh | 20 +++++++++++++++++++ docker/db-insigno-grafana.yml | 2 +- .../datasources/prometheus.yaml | 1 + docker/prometheus.yml | 4 ++-- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 docker/backup-volumes.sh diff --git a/docker/backup-volumes.sh b/docker/backup-volumes.sh new file mode 100644 index 0000000..aa9eb26 --- /dev/null +++ b/docker/backup-volumes.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +backup(){ + sudo docker run -it --rm -v $1:/volume -v $(pwd):/backup --name dbstore ubuntu tar cf /backup/backup/backup-$1.tar /volume +} + +restore(){ + sudo docker run -it --rm -v $1:/volume -v $(pwd):/backup --name dbstore ubuntu tar xf /backup/backup/backup-$1.tar -C /volume +} +mkdir backup + +backup docker_db-vol +backup docker_grafana-vol +backup docker_media-vol +backup docker_prometheus-vol + +restore docker_db-vol +restore docker_grafana-vol +restore docker_media-vol +restore docker_prometheus-vol \ No newline at end of file diff --git a/docker/db-insigno-grafana.yml b/docker/db-insigno-grafana.yml index 1ab15d4..9c92cf9 100644 --- a/docker/db-insigno-grafana.yml +++ b/docker/db-insigno-grafana.yml @@ -40,7 +40,7 @@ services: volumes: - /proc:/host/proc:ro - /sys:/host/sys:ro - - /:/rootfs:ro + #- /:/rootfs:ro command: - '--path.procfs=/host/proc' - '--path.rootfs=/rootfs' diff --git a/docker/grafana-provisioning/datasources/prometheus.yaml b/docker/grafana-provisioning/datasources/prometheus.yaml index 16748e7..bcd7961 100644 --- a/docker/grafana-provisioning/datasources/prometheus.yaml +++ b/docker/grafana-provisioning/datasources/prometheus.yaml @@ -11,6 +11,7 @@ datasources: httpMethod: POST manageAlerts: true prometheusType: Prometheus + timeInterval: 1m #prometheusVersion: 2.44.0 #cacheLevel: 'High' #disableRecordingRules: false diff --git a/docker/prometheus.yml b/docker/prometheus.yml index c628d4f..c2367e5 100644 --- a/docker/prometheus.yml +++ b/docker/prometheus.yml @@ -1,7 +1,7 @@ global: - scrape_interval: 15s + scrape_interval: 1m scrape_timeout: 10s - evaluation_interval: 15s + evaluation_interval: 1m scrape_configs: - job_name: prometheus From e17e2e7c10ecd6d7bf4e3f2b37a83195fa39510f Mon Sep 17 00:00:00 2001 From: Alessio Zeni Date: Sat, 19 Oct 2024 15:47:39 +0200 Subject: [PATCH 2/2] caddy vs nginx --- .gitignore | 1 + .vscode/settings.json | 3 ++ docker/Caddyfile | 11 ++++ docker/backup-volumes.sh | 10 ++-- docker/db-insigno-grafana.yml | 50 +++++++++++-------- .../datasources/prometheus.yaml | 2 +- docker/prometheus.yml | 2 +- 7 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 docker/Caddyfile diff --git a/.gitignore b/.gitignore index 6bc7097..a41c57e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ tree nohup* dump.sql test.sql +**/backup # Created by https://www.toptal.com/developers/gitignore/api/django # Edit at https://www.toptal.com/developers/gitignore?templates=django diff --git a/.vscode/settings.json b/.vscode/settings.json index b598241..a3e2c36 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,4 +14,7 @@ "rust-analyzer.check.extraArgs": [ "--target-dir=target/analyzer" ], + "files.associations": { + "caddyfile": "cpp" + }, } \ No newline at end of file diff --git a/docker/Caddyfile b/docker/Caddyfile new file mode 100644 index 0000000..3fecaea --- /dev/null +++ b/docker/Caddyfile @@ -0,0 +1,11 @@ + +{$COMP_PROTOCOL}://{$COMP_HOST} { + + reverse_proxy /grafana* grafana:3000 + + reverse_proxy /grafana/api/live* grafana:3000/api/live + + reverse_proxy insigno:8000 + + +} diff --git a/docker/backup-volumes.sh b/docker/backup-volumes.sh index aa9eb26..da09bba 100644 --- a/docker/backup-volumes.sh +++ b/docker/backup-volumes.sh @@ -13,8 +13,10 @@ backup docker_db-vol backup docker_grafana-vol backup docker_media-vol backup docker_prometheus-vol +backup docker_caddy-data-vol -restore docker_db-vol -restore docker_grafana-vol -restore docker_media-vol -restore docker_prometheus-vol \ No newline at end of file +#restore docker_db-vol +#restore docker_grafana-vol +#restore docker_media-vol +#restore docker_caddy-data-vol +#restore docker_caddy-data-vol \ No newline at end of file diff --git a/docker/db-insigno-grafana.yml b/docker/db-insigno-grafana.yml index 9c92cf9..6fbc3c6 100644 --- a/docker/db-insigno-grafana.yml +++ b/docker/db-insigno-grafana.yml @@ -3,40 +3,36 @@ services: image: grafana/grafana:latest container_name: grafana restart: always - ports: - - '3000:3000' volumes: - grafana-vol:/var/lib/grafana - ./grafana-provisioning:/etc/grafana/provisioning - ./dashboards:/var/lib/grafana/dashboards - ./dalvany-image-panel:/var/lib/grafana/plugins/dalvany-image-panel - #command: sh -c "grafana cli plugins install dalvany-image-panel" + environment: GF_SECURITY_ADMIN_MAIL: "insigno@mindshub.it" GF_SECURITY_ADMIN_USER: "Mindshub" GF_SECURITY_ADMIN_PASSWORD: "test" GF_SERVER_DOMAIN: insigno.mindshub.it datasource: prometheus_uid - - GF_SERVER_ROOT_URL: localhost:3000 - #on production use this - #GF_SERVER_ROOT_URL =https://insigno.mindshub.it/grafana/ - GF_SERVER_SERVE_FROM_SUB_PATH: false + GF_SERVER_ROOT_URL: "${COMP_PROTOCOL}://${COMP_HOST}/grafana/" + GF_SERVER_SERVE_FROM_SUB_PATH: true prometheus: image: prom/prometheus:latest restart: always - ports: - - '9090:9090' volumes: - prometheus-vol:/prometheus - "./prometheus.yml:/etc/prometheus/prometheus.yml" + environment: + PROM_SCRAPE_TIME: ${PROM_SCRAPE_TIME} + # + command: ["--config.file=/etc/prometheus/prometheus.yml", "--storage.tsdb.path=/prometheus", "--storage.tsdb.retention.time=1y", "--storage.tsdb.retention.size=5GB", "--storage.tsdb.wal-compression", "--web.external-url=/prometheus/"] + node_exporter: image: prom/node-exporter:latest restart: always - ports: - - 9100:9100 volumes: - /proc:/host/proc:ro - /sys:/host/sys:ro @@ -50,21 +46,18 @@ services: postgresql_exporter: image: bitnami/postgres-exporter:latest restart: always - ports: - - 9187:9187 environment: - - DATA_SOURCE_NAME=postgres://root:test@postgresql:5432/root?sslmode=disable + - DATA_SOURCE_NAME=postgres://root:${POSTGRES_PASSWORD}@postgresql:5432/${POSTGRES_DB}?sslmode=disable postgresql: image: postgis/postgis #use tobi312/rpi-postgresql-postgis:16-3.4-alpine-arm on raspberry restart: always - ports: - - "5432:5432" + environment: - POSTGRES_USER=root - - POSTGRES_PASSWORD=test - - POSTGRES_DB=root + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} - PGDATA=/var/lib/postgresql/data/pgdata volumes: - db-vol:/var/lib/postgresql/data @@ -87,13 +80,26 @@ services: # source: ./templates # target: /templates - media-vol:/app/media - ports: - - "8000:8000" depends_on: postgresql: condition: service_healthy + caddy: + image: caddy:latest + restart: always + ports: + - "80:80" + - "443:443" + volumes: + - caddy-data:/data + - ./Caddyfile:/etc/caddy/Caddyfile + environment: + COMP_HOST: ${COMP_HOST} + COMP_PROTOCOL: ${COMP_PROTOCOL} + + volumes: db-vol: media-vol: prometheus-vol: - grafana-vol: \ No newline at end of file + grafana-vol: + caddy-data: \ No newline at end of file diff --git a/docker/grafana-provisioning/datasources/prometheus.yaml b/docker/grafana-provisioning/datasources/prometheus.yaml index bcd7961..e933dda 100644 --- a/docker/grafana-provisioning/datasources/prometheus.yaml +++ b/docker/grafana-provisioning/datasources/prometheus.yaml @@ -5,7 +5,7 @@ datasources: type: prometheus access: proxy # Access mode - proxy (server in the UI) or direct (browser in the UI). - url: http://prometheus:9090 + url: http://prometheus:9090/prometheus uid: "prometheus_uid" jsonData: httpMethod: POST diff --git a/docker/prometheus.yml b/docker/prometheus.yml index c2367e5..b3c7b60 100644 --- a/docker/prometheus.yml +++ b/docker/prometheus.yml @@ -5,7 +5,7 @@ global: scrape_configs: - job_name: prometheus - metrics_path: /metrics + metrics_path: /prometheus/metrics static_configs: - targets: - prometheus:9090