Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: deduplicate code in examples #2404

Merged
merged 5 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dashboards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion dashboards/datasources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ datasources:
orgId: 1
type: prometheus
access: proxy
url: http://host.docker.internal:9090
url: http://prometheus:9090
MarcoPolo marked this conversation as resolved.
Show resolved Hide resolved
editable: false
32 changes: 5 additions & 27 deletions dashboards/docker-compose-linux.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
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 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
extra_hosts:
# define a prometheus alias, so we can use the same datasources.yml on Linux and macOS
- "prometheus:127.0.0.1"
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/metrics-and-dashboards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
38 changes: 6 additions & 32 deletions examples/metrics-and-dashboards/compose.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,15 @@
services:

prometheus-server:
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
5 changes: 0 additions & 5 deletions examples/metrics-and-dashboards/grafana-config/grafana.ini

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions examples/metrics-and-dashboards/grafana.Dockerfile

This file was deleted.

3 changes: 2 additions & 1 deletion examples/metrics-and-dashboards/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion examples/metrics-and-dashboards/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]