From 80df25930285148ef6f956d0decac2e26ce1ebad Mon Sep 17 00:00:00 2001 From: Iajrdev Date: Sun, 28 Jul 2024 23:11:26 +0330 Subject: [PATCH 01/10] Added Prometheus to project --- api/v2/echo.go | 5 +++++ benchmark.sh | 2 +- docker-compose.yml | 29 +++++++++++++++++++++++++++++ go.mod | 10 +++++++++- go.sum | 16 ++++++++++++++++ prometheus/prometheus.yml | 9 +++++++++ 6 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 docker-compose.yml create mode 100644 prometheus/prometheus.yml diff --git a/api/v2/echo.go b/api/v2/echo.go index 21b3205..5eae3c5 100644 --- a/api/v2/echo.go +++ b/api/v2/echo.go @@ -10,6 +10,7 @@ import ( "sync" "github.com/go-playground/validator" + "github.com/labstack/echo-contrib/echoprometheus" echo "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" ) @@ -63,6 +64,10 @@ func V2() (*echo.Echo, error) { e.Validator = &customValidator{validator: validator.New()} + // Prometheus middleware + e.Use(echoprometheus.NewMiddleware("myapp")) + e.GET("/metrics", echoprometheus.NewHandler()) + s := &server{} l := linkedlist.NewLinkedList() s.list = l diff --git a/benchmark.sh b/benchmark.sh index 1b9b20f..bad5e7d 100755 --- a/benchmark.sh +++ b/benchmark.sh @@ -15,7 +15,7 @@ trap cleanup EXIT SIGINT SIGTERM # Generate random numbers for insert and find operations INSERT_FILE="inserts.json" FIND_FILE="finds.txt" -NUM_ENTRIES=100000 +NUM_ENTRIES=10 # Create random insert JSON echo "[" > $INSERT_FILE diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2d1ca39 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +version: '3.8' + +services: + prometheus: + image: docker.arvancloud.ir/prom/prometheus:latest + container_name: prometheus + volumes: + - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml + - prometheus_data:/prometheus + ports: + - "9090:9090" + restart: unless-stopped + + grafana: + image: docker.arvancloud.ir/grafana/grafana-oss:latest + container_name: grafana + # environment: + # - GF_SECURITY_ADMIN_USER=admin + # - GF_SECURITY_ADMIN_PASSWORD=admin + volumes: + - grafana_data:/var/lib/grafana + ports: + - "3000:3000" + restart: unless-stopped + +volumes: + prometheus_data: + grafana_data: + diff --git a/go.mod b/go.mod index b9eba86..285ec49 100644 --- a/go.mod +++ b/go.mod @@ -9,13 +9,20 @@ require ( ) require ( + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect + github.com/labstack/echo-contrib v0.17.1 // indirect github.com/labstack/gommon v0.4.2 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect + github.com/prometheus/client_golang v1.19.0 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.53.0 // indirect + github.com/prometheus/procfs v0.13.0 // indirect github.com/stretchr/testify v1.9.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect @@ -24,5 +31,6 @@ require ( golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect + google.golang.org/protobuf v1.33.0 // indirect gopkg.in/go-playground/assert.v1 v1.2.1 // indirect -) \ No newline at end of file +) diff --git a/go.sum b/go.sum index baf06fc..90d7fdb 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,7 @@ +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -8,6 +12,8 @@ github.com/go-playground/validator v9.31.0+incompatible h1:UA72EPEogEnq76ehGdEDp github.com/go-playground/validator v9.31.0+incompatible/go.mod h1:yrEkQXlcI+PugkyDjY2bRrL/UBU4f3rvrgkN3V8JEig= github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/labstack/echo-contrib v0.17.1 h1:7I/he7ylVKsDUieaGRZ9XxxTYOjfQwVzHzUYrNykfCU= +github.com/labstack/echo-contrib v0.17.1/go.mod h1:SnsCZtwHBAZm5uBSAtQtXQHI3wqEA73hvTn0bYMKnZA= github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0= github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= @@ -21,6 +27,14 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= +github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.53.0 h1:U2pL9w9nmJwJDa4qqLQ3ZaePJ6ZTwt7cMD3AG3+aLCE= +github.com/prometheus/common v0.53.0/go.mod h1:BrxBKv3FWBIGXw89Mg1AeBq7FSyRzXWI3l3e7W3RN5U= +github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o= +github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= @@ -39,6 +53,8 @@ golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= diff --git a/prometheus/prometheus.yml b/prometheus/prometheus.yml new file mode 100644 index 0000000..b2b8a0a --- /dev/null +++ b/prometheus/prometheus.yml @@ -0,0 +1,9 @@ +global: + scrape_interval: 5s + +scrape_configs: + - job_name: 'myapp' + metrics_path: '/v2/metrics' + static_configs: + - targets: ['app:8080'] + From c6320629f149cab60d441ec80ebdee7102b5aeb4 Mon Sep 17 00:00:00 2001 From: Iajrdev Date: Sun, 28 Jul 2024 23:17:30 +0330 Subject: [PATCH 02/10] update readme --- README.md | Bin 5246 -> 5582 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/README.md b/README.md index f5a99274eb5e583c4b747a095d92ee02799a1b56..42ae6c4ad1db53cfaa7d69b82d81717b83b8f021 100644 GIT binary patch delta 292 zcmY*UI|{-;5Ph8>2o`oW3uy$2C>}wVF*{F9<+Cf&Yw zKa7z0KcgbsAcTV`$7+(Th^IKQcO|1zwS?ZIRxMGt>^sICQQ1&@+}vBidWx}H{J|}i fbtkgF*DN^EVylxZ@tT?mW5&s)-XcBWjflPhSv@rf delta 7 OcmX@7{ZC^ Date: Mon, 29 Jul 2024 10:46:35 +0330 Subject: [PATCH 03/10] reset benchmark entries number, add prometheus job to it's config --- benchmark.sh | 2 +- docker-compose.yml | 3 +-- prometheus/prometheus.yml | 6 +++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/benchmark.sh b/benchmark.sh index bad5e7d..1b9b20f 100755 --- a/benchmark.sh +++ b/benchmark.sh @@ -15,7 +15,7 @@ trap cleanup EXIT SIGINT SIGTERM # Generate random numbers for insert and find operations INSERT_FILE="inserts.json" FIND_FILE="finds.txt" -NUM_ENTRIES=10 +NUM_ENTRIES=100000 # Create random insert JSON echo "[" > $INSERT_FILE diff --git a/docker-compose.yml b/docker-compose.yml index 2d1ca39..7cf30bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,5 +25,4 @@ services: volumes: prometheus_data: - grafana_data: - + grafana_data: \ No newline at end of file diff --git a/prometheus/prometheus.yml b/prometheus/prometheus.yml index b2b8a0a..e1ff17e 100644 --- a/prometheus/prometheus.yml +++ b/prometheus/prometheus.yml @@ -2,8 +2,12 @@ global: scrape_interval: 5s scrape_configs: + - job_name: 'prometheus' + static_configs: + - targets: ['localhost:9090'] + - job_name: 'myapp' metrics_path: '/v2/metrics' static_configs: - - targets: ['app:8080'] + - targets: ['myapp:8080'] From e7e1098e6075be51bdc2db23a47b690e27926d96 Mon Sep 17 00:00:00 2001 From: Iajrdev Date: Thu, 1 Aug 2024 19:57:01 +0330 Subject: [PATCH 04/10] Add Grafana and Prometheus integration with auto-provisioning --- docker-compose.yml | 9 +- grafana/provisioning/dashboards/dashboard.yml | 11 +++ .../provisioning/dashboards/my_dashboard.json | 98 +++++++++++++++++++ .../provisioning/datasources/datasource.yml | 8 ++ prometheus/prometheus.yml | 6 +- 5 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 grafana/provisioning/dashboards/dashboard.yml create mode 100644 grafana/provisioning/dashboards/my_dashboard.json create mode 100644 grafana/provisioning/datasources/datasource.yml diff --git a/docker-compose.yml b/docker-compose.yml index 7cf30bc..d8971b2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,15 +14,16 @@ services: grafana: image: docker.arvancloud.ir/grafana/grafana-oss:latest container_name: grafana - # environment: - # - GF_SECURITY_ADMIN_USER=admin - # - GF_SECURITY_ADMIN_PASSWORD=admin + environment: + - GF_SECURITY_ADMIN_USER=admin + - GF_SECURITY_ADMIN_PASSWORD=admin volumes: - grafana_data:/var/lib/grafana + - ./grafana/provisioning:/etc/grafana/provisioning ports: - "3000:3000" restart: unless-stopped volumes: prometheus_data: - grafana_data: \ No newline at end of file + grafana_data: diff --git a/grafana/provisioning/dashboards/dashboard.yml b/grafana/provisioning/dashboards/dashboard.yml new file mode 100644 index 0000000..006b093 --- /dev/null +++ b/grafana/provisioning/dashboards/dashboard.yml @@ -0,0 +1,11 @@ +apiVersion: 1 + +providers: + - name: 'default' + orgId: 1 + folder: '' + type: file + disableDeletion: false + updateIntervalSeconds: 10 + options: + path: /etc/grafana/provisioning/dashboards diff --git a/grafana/provisioning/dashboards/my_dashboard.json b/grafana/provisioning/dashboards/my_dashboard.json new file mode 100644 index 0000000..50762ae --- /dev/null +++ b/grafana/provisioning/dashboards/my_dashboard.json @@ -0,0 +1,98 @@ +{ + "dashboard": { + "id": null, + "title": "My App Dashboard", + "tags": [], + "timezone": "browser", + "schemaVersion": 16, + "version": 0, + "refresh": "5s", + "panels": [ + { + "type": "timeseries", + "title": "HTTP Requests", + "datasource": "Prometheus", + "targets": [ + { + "expr": "myapp_request_duration_seconds_bucket", + "legendFormat": "{{handler}}", + "refId": "A", + "editorMode": "code", + "range": true + }, + { + "expr": "myapp_request_duration_seconds_count", + "legendFormat": "__auto", + "refId": "B", + "editorMode": "code", + "range": true + }, + { + "expr": "myapp_request_duration_seconds_sum", + "legendFormat": "__auto", + "refId": "C", + "editorMode": "builder", + "range": true + }, + { + "expr": "myapp_requests_total", + "legendFormat": "__auto", + "refId": "D", + "editorMode": "builder", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "value": null, + "color": "green" + }, + { + "value": 80, + "color": "red" + } + ] + }, + "unit": "short" + }, + "overrides": [] + }, + "options": { + "tooltip": { + "mode": "single", + "sort": "none", + "maxHeight": 600 + }, + "legend": { + "showLegend": true, + "displayMode": "list", + "placement": "bottom" + } + }, + "xaxis": { + "mode": "time", + "show": true + }, + "yaxes": [ + { + "format": "short", + "show": true + }, + { + "show": true + } + ] + } + ] + }, + "overwrite": false +} + diff --git a/grafana/provisioning/datasources/datasource.yml b/grafana/provisioning/datasources/datasource.yml new file mode 100644 index 0000000..86fd346 --- /dev/null +++ b/grafana/provisioning/datasources/datasource.yml @@ -0,0 +1,8 @@ +apiVersion: 1 + +datasources: + - name: Prometheus + type: prometheus + access: proxy + url: http://prometheus:9090 + isDefault: true diff --git a/prometheus/prometheus.yml b/prometheus/prometheus.yml index e1ff17e..e76d76f 100644 --- a/prometheus/prometheus.yml +++ b/prometheus/prometheus.yml @@ -2,12 +2,8 @@ global: scrape_interval: 5s scrape_configs: - - job_name: 'prometheus' - static_configs: - - targets: ['localhost:9090'] - job_name: 'myapp' metrics_path: '/v2/metrics' static_configs: - - targets: ['myapp:8080'] - + - targets: ['172.17.0.1:8080'] From 77626bd694fede62db808a8e03fc0872f3a42a66 Mon Sep 17 00:00:00 2001 From: Iajrdev Date: Fri, 2 Aug 2024 12:37:41 +0330 Subject: [PATCH 05/10] fix dashboard json issue --- .../provisioning/dashboards/my_dashboard.json | 178 +++++++++--------- 1 file changed, 87 insertions(+), 91 deletions(-) diff --git a/grafana/provisioning/dashboards/my_dashboard.json b/grafana/provisioning/dashboards/my_dashboard.json index 50762ae..fdc6a0b 100644 --- a/grafana/provisioning/dashboards/my_dashboard.json +++ b/grafana/provisioning/dashboards/my_dashboard.json @@ -1,98 +1,94 @@ { - "dashboard": { - "id": null, - "title": "My App Dashboard", - "tags": [], - "timezone": "browser", - "schemaVersion": 16, - "version": 0, - "refresh": "5s", - "panels": [ - { - "type": "timeseries", - "title": "HTTP Requests", - "datasource": "Prometheus", - "targets": [ - { - "expr": "myapp_request_duration_seconds_bucket", - "legendFormat": "{{handler}}", - "refId": "A", - "editorMode": "code", - "range": true - }, - { - "expr": "myapp_request_duration_seconds_count", - "legendFormat": "__auto", - "refId": "B", - "editorMode": "code", - "range": true - }, - { - "expr": "myapp_request_duration_seconds_sum", - "legendFormat": "__auto", - "refId": "C", - "editorMode": "builder", - "range": true + "id": null, + "title": "My App Dashboard", + "tags": [], + "timezone": "browser", + "schemaVersion": 16, + "version": 0, + "refresh": "5s", + "panels": [ + { + "type": "timeseries", + "title": "HTTP Requests", + "datasource": "Prometheus", + "targets": [ + { + "expr": "myapp_request_duration_seconds_bucket", + "legendFormat": "{{handler}}", + "refId": "A", + "editorMode": "code", + "range": true + }, + { + "expr": "myapp_request_duration_seconds_count", + "legendFormat": "__auto", + "refId": "B", + "editorMode": "code", + "range": true + }, + { + "expr": "myapp_request_duration_seconds_sum", + "legendFormat": "__auto", + "refId": "C", + "editorMode": "builder", + "range": true + }, + { + "expr": "myapp_requests_total", + "legendFormat": "__auto", + "refId": "D", + "editorMode": "builder", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" }, - { - "expr": "myapp_requests_total", - "legendFormat": "__auto", - "refId": "D", - "editorMode": "builder", - "range": true - } - ], - "fieldConfig": { - "defaults": { - "color": { - "mode": "palette-classic" - }, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "value": null, - "color": "green" - }, - { - "value": 80, - "color": "red" - } - ] - }, - "unit": "short" + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "value": null, + "color": "green" + }, + { + "value": 80, + "color": "red" + } + ] }, - "overrides": [] + "unit": "short" }, - "options": { - "tooltip": { - "mode": "single", - "sort": "none", - "maxHeight": 600 - }, - "legend": { - "showLegend": true, - "displayMode": "list", - "placement": "bottom" - } + "overrides": [] + }, + "options": { + "tooltip": { + "mode": "single", + "sort": "none", + "maxHeight": 600 }, - "xaxis": { - "mode": "time", + "legend": { + "showLegend": true, + "displayMode": "list", + "placement": "bottom" + } + }, + "xaxis": { + "mode": "time", + "show": true + }, + "yaxes": [ + { + "format": "short", "show": true }, - "yaxes": [ - { - "format": "short", - "show": true - }, - { - "show": true - } - ] - } - ] - }, - "overwrite": false -} - + { + "show": true + } + ] + } + ] +} \ No newline at end of file From 754d5f63fd58fb661bfcb5e048a903450059ee5a Mon Sep 17 00:00:00 2001 From: Iajrdev Date: Mon, 5 Aug 2024 00:12:35 +0330 Subject: [PATCH 06/10] Update hosts of prometheus --- docker-compose.yml | 2 ++ prometheus/prometheus.yml | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d8971b2..926bdd9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,6 +23,8 @@ services: ports: - "3000:3000" restart: unless-stopped + extra_hosts: + - "host.docker.internal:host-gateway" volumes: prometheus_data: diff --git a/prometheus/prometheus.yml b/prometheus/prometheus.yml index e76d76f..4297af0 100644 --- a/prometheus/prometheus.yml +++ b/prometheus/prometheus.yml @@ -2,8 +2,7 @@ global: scrape_interval: 5s scrape_configs: - - job_name: 'myapp' metrics_path: '/v2/metrics' static_configs: - - targets: ['172.17.0.1:8080'] + - targets: ['host.docker.internal:8080'] From d190a639a8ea1c3acf319841ea307a8c953603c4 Mon Sep 17 00:00:00 2001 From: Iajrdev Date: Mon, 5 Aug 2024 09:13:08 +0330 Subject: [PATCH 07/10] fix issue --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 926bdd9..e5288ce 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,8 @@ services: - prometheus_data:/prometheus ports: - "9090:9090" + extra_hosts: + - "host.docker.internal:host-gateway" restart: unless-stopped grafana: @@ -23,8 +25,6 @@ services: ports: - "3000:3000" restart: unless-stopped - extra_hosts: - - "host.docker.internal:host-gateway" volumes: prometheus_data: From caa2cca47d1aa6ef840d9e3f4600845f4af01f7a Mon Sep 17 00:00:00 2001 From: Iajrdev Date: Tue, 6 Aug 2024 16:46:27 +0330 Subject: [PATCH 08/10] Update docker-compose --- docker-compose.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e5288ce..0b11448 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: prometheus: image: docker.arvancloud.ir/prom/prometheus:latest @@ -11,6 +9,11 @@ services: - "9090:9090" extra_hosts: - "host.docker.internal:host-gateway" + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9090/-/ready"] + interval: 30s + timeout: 10s + retries: 3 restart: unless-stopped grafana: @@ -24,6 +27,11 @@ services: - ./grafana/provisioning:/etc/grafana/provisioning ports: - "3000:3000" + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"] + interval: 30s + timeout: 10s + retries: 3 restart: unless-stopped volumes: From 057bfd53fd172aa71acd59a9896d1b0c4d50c9e7 Mon Sep 17 00:00:00 2001 From: Iajrdev Date: Tue, 6 Aug 2024 16:54:41 +0330 Subject: [PATCH 09/10] fix issue of docker-compose --- docker-compose.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 0b11448..c5c4ebf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,6 +27,9 @@ services: - ./grafana/provisioning:/etc/grafana/provisioning ports: - "3000:3000" + depends_on: + prometheus: + condition: service_healthy healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"] interval: 30s From 8c4307a43f83166a2e9ab3fdf1629449f9ae334e Mon Sep 17 00:00:00 2001 From: Iajrdev Date: Tue, 6 Aug 2024 23:01:27 +0330 Subject: [PATCH 10/10] fix docker compose issue --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index c5c4ebf..6b9e87c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: extra_hosts: - "host.docker.internal:host-gateway" healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:9090/-/ready"] + test: ["CMD", "wget", "--spider", "--quiet", "http://localhost:9090/-/healthy"] interval: 30s timeout: 10s retries: 3