From 7d019bb4e31f0062abd5215dab2f8858e3656725 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 29 Jun 2023 13:37:06 -0700 Subject: [PATCH 1/5] Dedup code in metrics examples --- dashboards/README.md | 8 +-- dashboards/datasources.yml | 2 +- dashboards/docker-compose-linux.yml | 31 +-------- ...ompose-osx.yml => docker-compose.base.yml} | 0 examples/metrics-and-dashboards/compose.yml | 68 ++++++++++--------- examples/metrics-and-dashboards/main.go | 3 +- .../metrics-and-dashboards/prometheus.yml | 3 +- 7 files changed, 48 insertions(+), 67 deletions(-) rename dashboards/{docker-compose-osx.yml => docker-compose.base.yml} (100%) diff --git a/dashboards/README.md b/dashboards/README.md index a0307b68e6..04ccd528b6 100644 --- a/dashboards/README.md +++ b/dashboards/README.md @@ -20,13 +20,13 @@ go func() { This exposes a metrics collection endpoint at http://localhost:5001/debug/metrics/prometheus. Note that this is the same endpoint that [Kubo](https://github.com/ipfs/kubo) uses, so if you want to gather metrics from Kubo, you can skip this step. -On Linux, dashboards can be inspected locally by running: +On macOS: ```bash -docker-compose -f docker-compose-linux.yml up +docker-compose -f docker-compose.base.yml up ``` -On macOS: +On Linux, dashboards can be inspected locally by running: ```bash -docker-compose -f docker-compose-osx.yml up +docker-compose -f docker-compose.base.yml -f docker-compose-linux.yml up ``` and opening Grafana at http://localhost:3000. diff --git a/dashboards/datasources.yml b/dashboards/datasources.yml index ec9c1f28aa..ed47ec11a1 100644 --- a/dashboards/datasources.yml +++ b/dashboards/datasources.yml @@ -9,5 +9,5 @@ datasources: orgId: 1 type: prometheus access: proxy - url: http://host.docker.internal:9090 + url: http://prometheus:9090 editable: false diff --git a/dashboards/docker-compose-linux.yml b/dashboards/docker-compose-linux.yml index 3e016e5a68..9c79e3c04a 100644 --- a/dashboards/docker-compose-linux.yml +++ b/dashboards/docker-compose-linux.yml @@ -1,34 +1,7 @@ version: "3.7" services: prometheus: - image: prom/prometheus:latest - ports: - - "9090:9090" - volumes: - - ./prometheus.yml:/etc/prometheus/prometheus.yml network_mode: "host" - extra_hosts: # define a host.docker.internal alias, so we can use the same datasources.yml and prometheus.yml on Linux and OSX + extra_hosts: + # define a host.docker.internal alias, so we can use the same datasources.yml and prometheus.yml on Linux and macOS - "host.docker.internal:127.0.0.1" - grafana: - image: grafana/grafana:latest - depends_on: - - prometheus - ports: - - "3000:3000" - network_mode: "host" - extra_hosts: # define a host.docker.internal alias, so we can use the same datasources.yml and prometheus.yml on Linux and OSX - - "host.docker.internal:127.0.0.1" - environment: - - GF_AUTH_DISABLE_LOGIN_FORM=true - - GF_AUTH_ANONYMOUS_ENABLED=true - - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin - volumes: - - ./dashboard.yml:/etc/grafana/provisioning/dashboards/main.yml - - ./datasources.yml:/etc/grafana/provisioning/datasources/prom.yml - - ./autonat/autonat.json:/var/lib/grafana/dashboards/autonat.json - - ./autorelay/autorelay.json:/var/lib/grafana/dashboards/autorelay.json - - ./eventbus/eventbus.json:/var/lib/grafana/dashboards/eventbus.json - - ./holepunch/holepunch.json:/var/lib/grafana/dashboards/holepunch.json - - ./identify/identify.json:/var/lib/grafana/dashboards/identify.json - - ./relaysvc/relaysvc.json:/var/lib/grafana/dashboards/relaysvc.json - - ./swarm/swarm.json:/var/lib/grafana/dashboards/swarm.json diff --git a/dashboards/docker-compose-osx.yml b/dashboards/docker-compose.base.yml similarity index 100% rename from dashboards/docker-compose-osx.yml rename to dashboards/docker-compose.base.yml diff --git a/examples/metrics-and-dashboards/compose.yml b/examples/metrics-and-dashboards/compose.yml index f5a6751193..11dba2015d 100644 --- a/examples/metrics-and-dashboards/compose.yml +++ b/examples/metrics-and-dashboards/compose.yml @@ -1,41 +1,47 @@ services: - prometheus-server: + # prometheus-server: + # image: prom/prometheus:latest + # restart: unless-stopped + # volumes: + # - ./prometheus.yml:/etc/prometheus/prometheus.yml + # command: + # - '--config.file=/etc/prometheus/prometheus.yml' + # - '--storage.tsdb.path=/prometheus' + # - '--web.console.libraries=/etc/prometheus/console_libraries' + # - '--web.console.templates=/etc/prometheus/consoles' + # - '--web.enable-lifecycle' + # ports: + # - 9090:9090 + # expose: + # - 9090 + + # grafana: + # # image: sha256:b4cfd1a8f2d221019265ca75b20e066b5ddd34631210441d5877914a0af2fd67 + # build: + # dockerfile: examples/metrics-and-dashboards/grafana.Dockerfile + # context: ../../ + # environment: + # - GF_AUTH_DISABLE_LOGIN_FORM=true + # - GF_AUTH_ANONYMOUS_ENABLED=true + # - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin + # volumes: + # - ./grafana-config/grafana.ini:/etc/grafana/grafana.ini + # - ./grafana-config/provisioning:/etc/grafana/provisioning + # ports: + # - 3000:3000 + + prometheus: image: prom/prometheus:latest - restart: unless-stopped - volumes: - - ./prometheus.yml:/etc/prometheus/prometheus.yml - command: - - '--config.file=/etc/prometheus/prometheus.yml' - - '--storage.tsdb.path=/prometheus' - - '--web.console.libraries=/etc/prometheus/console_libraries' - - '--web.console.templates=/etc/prometheus/consoles' - - '--web.enable-lifecycle' ports: - - 9090:9090 - expose: - - 9090 - - grafana: - # image: sha256:b4cfd1a8f2d221019265ca75b20e066b5ddd34631210441d5877914a0af2fd67 - build: - dockerfile: examples/metrics-and-dashboards/grafana.Dockerfile - context: ../../ - environment: - - GF_AUTH_DISABLE_LOGIN_FORM=true - - GF_AUTH_ANONYMOUS_ENABLED=true - - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin + - "9090:9090" volumes: - - ./grafana-config/grafana.ini:/etc/grafana/grafana.ini - - ./grafana-config/provisioning:/etc/grafana/provisioning - ports: - - 3000:3000 - + - ../examples/metrics-and-dashboards/prometheus.yml:/etc/prometheus/prometheus.yml go-libp2p-node: build: - context: . + context: ../examples/metrics-and-dashboards/ dockerfile: go-libp2p-node.Dockerfile ports: - - 2112:2112 + - 5001:5001 expose: - - 2112 + - 5001 diff --git a/examples/metrics-and-dashboards/main.go b/examples/metrics-and-dashboards/main.go index 9ca0bcf062..85d78e4e49 100644 --- a/examples/metrics-and-dashboards/main.go +++ b/examples/metrics-and-dashboards/main.go @@ -24,7 +24,8 @@ const ClientCount = 32 func main() { http.Handle("/metrics", promhttp.Handler()) go func() { - http.ListenAndServe(":2112", nil) + http.Handle("/debug/metrics/prometheus", promhttp.Handler()) + log.Fatal(http.ListenAndServe(":5001", nil)) }() rcmgrObs.MustRegisterWith(prometheus.DefaultRegisterer) diff --git a/examples/metrics-and-dashboards/prometheus.yml b/examples/metrics-and-dashboards/prometheus.yml index a532a5fb2a..3f86ad0c26 100644 --- a/examples/metrics-and-dashboards/prometheus.yml +++ b/examples/metrics-and-dashboards/prometheus.yml @@ -11,5 +11,6 @@ scrape_configs: static_configs: - targets: ["node-exporter:9100"] - job_name: "go-libp2p" + metrics_path: /debug/metrics/prometheus static_configs: - - targets: ["go-libp2p-node:2112"] + - targets: ["go-libp2p-node:5001"] From b628c0671d881bacca7cee57847cca40eabbfc09 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 29 Jun 2023 13:40:23 -0700 Subject: [PATCH 2/5] Readme tweaks --- dashboards/README.md | 4 ++-- examples/metrics-and-dashboards/README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dashboards/README.md b/dashboards/README.md index 04ccd528b6..6080dc03f3 100644 --- a/dashboards/README.md +++ b/dashboards/README.md @@ -22,11 +22,11 @@ This exposes a metrics collection endpoint at http://localhost:5001/debug/metric On macOS: ```bash -docker-compose -f docker-compose.base.yml up +docker compose -f docker-compose.base.yml up ``` On Linux, dashboards can be inspected locally by running: ```bash -docker-compose -f docker-compose.base.yml -f docker-compose-linux.yml up +docker compose -f docker-compose.base.yml -f docker-compose-linux.yml up ``` and opening Grafana at http://localhost:3000. diff --git a/examples/metrics-and-dashboards/README.md b/examples/metrics-and-dashboards/README.md index 6a41fb4e84..9218994d2e 100644 --- a/examples/metrics-and-dashboards/README.md +++ b/examples/metrics-and-dashboards/README.md @@ -7,7 +7,7 @@ small go-libp2p dummy application is included to emit metrics. Run it with: ``` -docker compose up +docker compose -f ../../dashboards/docker-compose.base.yml -f ./compose.yml up ``` Go to http://localhost:3000/dashboards to see the dashboards. From 2f9176f0d582b3b1fe239167c68c63310def2411 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 29 Jun 2023 13:42:26 -0700 Subject: [PATCH 3/5] Remove unused code --- .../grafana-config/grafana.ini | 5 ---- .../provisioning/dashboards/dashboards.yml | 25 ------------------- .../provisioning/datasources/datasource.yml | 15 ----------- .../metrics-and-dashboards/grafana.Dockerfile | 10 -------- 4 files changed, 55 deletions(-) delete mode 100644 examples/metrics-and-dashboards/grafana-config/grafana.ini delete mode 100644 examples/metrics-and-dashboards/grafana-config/provisioning/dashboards/dashboards.yml delete mode 100644 examples/metrics-and-dashboards/grafana-config/provisioning/datasources/datasource.yml delete mode 100644 examples/metrics-and-dashboards/grafana.Dockerfile diff --git a/examples/metrics-and-dashboards/grafana-config/grafana.ini b/examples/metrics-and-dashboards/grafana-config/grafana.ini deleted file mode 100644 index 91bab4865f..0000000000 --- a/examples/metrics-and-dashboards/grafana-config/grafana.ini +++ /dev/null @@ -1,5 +0,0 @@ -[paths] -provisioning = /etc/grafana/provisioning - -[server] -enable_gzip = true diff --git a/examples/metrics-and-dashboards/grafana-config/provisioning/dashboards/dashboards.yml b/examples/metrics-and-dashboards/grafana-config/provisioning/dashboards/dashboards.yml deleted file mode 100644 index 27bbeef59e..0000000000 --- a/examples/metrics-and-dashboards/grafana-config/provisioning/dashboards/dashboards.yml +++ /dev/null @@ -1,25 +0,0 @@ -# config file version -apiVersion: 1 - -providers: - # an unique provider name - - name: My Dashboard - # org id. will default to orgId 1 if not specified - org_id: 1 - # name of the dashboard folder. Required - folder: "" - # provider type. Required - type: "file" - # disable dashboard deletion - disableDeletion: false - # enable dashboard editing - editable: true - # how often Grafana will scan for changed dashboards - updateIntervalSeconds: 5 - # allow updating provisioned dashboards from the UI - allowUiUpdates: true - options: - # path to dashboard files on disk. Required - path: /etc/grafana/dashboards - # use folder names from filesystem to create folders in Grafana - foldersFromFilesStructure: true diff --git a/examples/metrics-and-dashboards/grafana-config/provisioning/datasources/datasource.yml b/examples/metrics-and-dashboards/grafana-config/provisioning/datasources/datasource.yml deleted file mode 100644 index eed755880d..0000000000 --- a/examples/metrics-and-dashboards/grafana-config/provisioning/datasources/datasource.yml +++ /dev/null @@ -1,15 +0,0 @@ -# config file version -apiVersion: 1 - -datasources: - - name: Prometheus - type: prometheus - # Access mode - proxy (server in the UI) or direct (browser in the UI). - access: proxy - uid: "prometheusuid" - url: http://prometheus-server:9090 - jsonData: - httpMethod: POST - manageAlerts: true - prometheusType: Prometheus - prometheusVersion: 2.43.0 diff --git a/examples/metrics-and-dashboards/grafana.Dockerfile b/examples/metrics-and-dashboards/grafana.Dockerfile deleted file mode 100644 index f9d71e48e7..0000000000 --- a/examples/metrics-and-dashboards/grafana.Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM grafana/grafana - -COPY ./dashboards /etc/grafana/dashboards -USER root - -# Replace every instrance of ${DS_PROMETHEUS} with "prometheusuid" -# Grafana doesn't let us do this in provisioning, so we do it ourselves. -RUN sed -i 's/${DS_PROMETHEUS}/prometheusuid/g' /etc/grafana/dashboards/*/*.json -RUN cat /etc/grafana/dashboards/swarm/swarm.json -USER grafana From d0266def766857fb9b6014019e1308c9c29c8846 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 29 Jun 2023 13:44:32 -0700 Subject: [PATCH 4/5] Remove unused code --- examples/metrics-and-dashboards/compose.yml | 32 --------------------- 1 file changed, 32 deletions(-) diff --git a/examples/metrics-and-dashboards/compose.yml b/examples/metrics-and-dashboards/compose.yml index 11dba2015d..fb10b4a81a 100644 --- a/examples/metrics-and-dashboards/compose.yml +++ b/examples/metrics-and-dashboards/compose.yml @@ -1,36 +1,4 @@ services: - - # prometheus-server: - # image: prom/prometheus:latest - # restart: unless-stopped - # volumes: - # - ./prometheus.yml:/etc/prometheus/prometheus.yml - # command: - # - '--config.file=/etc/prometheus/prometheus.yml' - # - '--storage.tsdb.path=/prometheus' - # - '--web.console.libraries=/etc/prometheus/console_libraries' - # - '--web.console.templates=/etc/prometheus/consoles' - # - '--web.enable-lifecycle' - # ports: - # - 9090:9090 - # expose: - # - 9090 - - # grafana: - # # image: sha256:b4cfd1a8f2d221019265ca75b20e066b5ddd34631210441d5877914a0af2fd67 - # build: - # dockerfile: examples/metrics-and-dashboards/grafana.Dockerfile - # context: ../../ - # environment: - # - GF_AUTH_DISABLE_LOGIN_FORM=true - # - GF_AUTH_ANONYMOUS_ENABLED=true - # - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin - # volumes: - # - ./grafana-config/grafana.ini:/etc/grafana/grafana.ini - # - ./grafana-config/provisioning:/etc/grafana/provisioning - # ports: - # - 3000:3000 - prometheus: image: prom/prometheus:latest ports: From 703f35c779765aaef35aba01d54ab58512b727c3 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 29 Jun 2023 22:06:13 +0000 Subject: [PATCH 5/5] Use extra_hosts for grafana on linux --- dashboards/docker-compose-linux.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dashboards/docker-compose-linux.yml b/dashboards/docker-compose-linux.yml index 9c79e3c04a..da9293249e 100644 --- a/dashboards/docker-compose-linux.yml +++ b/dashboards/docker-compose-linux.yml @@ -3,5 +3,10 @@ services: prometheus: network_mode: "host" extra_hosts: - # define a host.docker.internal alias, so we can use the same datasources.yml and prometheus.yml on Linux and macOS + # define a host.docker.internal alias, so we can use the same prometheus.yml on Linux and macOS - "host.docker.internal:127.0.0.1" + grafana: + network_mode: "host" + extra_hosts: + # define a prometheus alias, so we can use the same datasources.yml on Linux and macOS + - "prometheus:127.0.0.1"