mirror of
https://github.com/libp2p/go-libp2p.git
synced 2025-09-26 20:21:26 +08:00
metrics: deduplicate code in examples (#2404)
* Dedup code in metrics examples * Readme tweaks * Remove unused code * Remove unused code * Use extra_hosts for grafana on linux
This commit is contained in:
@@ -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.
|
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:
|
|
||||||
```bash
|
|
||||||
docker-compose -f docker-compose-linux.yml up
|
|
||||||
```
|
|
||||||
On macOS:
|
On macOS:
|
||||||
```bash
|
```bash
|
||||||
docker-compose -f docker-compose-osx.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
|
||||||
```
|
```
|
||||||
|
|
||||||
and opening Grafana at http://localhost:3000.
|
and opening Grafana at http://localhost:3000.
|
||||||
|
@@ -9,5 +9,5 @@ datasources:
|
|||||||
orgId: 1
|
orgId: 1
|
||||||
type: prometheus
|
type: prometheus
|
||||||
access: proxy
|
access: proxy
|
||||||
url: http://host.docker.internal:9090
|
url: http://prometheus:9090
|
||||||
editable: false
|
editable: false
|
||||||
|
@@ -1,34 +1,12 @@
|
|||||||
version: "3.7"
|
version: "3.7"
|
||||||
services:
|
services:
|
||||||
prometheus:
|
prometheus:
|
||||||
image: prom/prometheus:latest
|
|
||||||
ports:
|
|
||||||
- "9090:9090"
|
|
||||||
volumes:
|
|
||||||
- ./prometheus.yml:/etc/prometheus/prometheus.yml
|
|
||||||
network_mode: "host"
|
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"
|
- "host.docker.internal:127.0.0.1"
|
||||||
grafana:
|
grafana:
|
||||||
image: grafana/grafana:latest
|
|
||||||
depends_on:
|
|
||||||
- prometheus
|
|
||||||
ports:
|
|
||||||
- "3000:3000"
|
|
||||||
network_mode: "host"
|
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:
|
||||||
- "host.docker.internal:127.0.0.1"
|
# define a prometheus alias, so we can use the same datasources.yml on Linux and macOS
|
||||||
environment:
|
- "prometheus:127.0.0.1"
|
||||||
- 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
|
|
||||||
|
@@ -7,7 +7,7 @@ small go-libp2p dummy application is included to emit metrics.
|
|||||||
Run it with:
|
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.
|
Go to http://localhost:3000/dashboards to see the dashboards.
|
||||||
|
@@ -1,41 +1,15 @@
|
|||||||
services:
|
services:
|
||||||
|
prometheus:
|
||||||
prometheus-server:
|
|
||||||
image: prom/prometheus:latest
|
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:
|
ports:
|
||||||
- 9090:9090
|
- "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:
|
volumes:
|
||||||
- ./grafana-config/grafana.ini:/etc/grafana/grafana.ini
|
- ../examples/metrics-and-dashboards/prometheus.yml:/etc/prometheus/prometheus.yml
|
||||||
- ./grafana-config/provisioning:/etc/grafana/provisioning
|
|
||||||
ports:
|
|
||||||
- 3000:3000
|
|
||||||
|
|
||||||
go-libp2p-node:
|
go-libp2p-node:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: ../examples/metrics-and-dashboards/
|
||||||
dockerfile: go-libp2p-node.Dockerfile
|
dockerfile: go-libp2p-node.Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- 2112:2112
|
- 5001:5001
|
||||||
expose:
|
expose:
|
||||||
- 2112
|
- 5001
|
||||||
|
@@ -1,5 +0,0 @@
|
|||||||
[paths]
|
|
||||||
provisioning = /etc/grafana/provisioning
|
|
||||||
|
|
||||||
[server]
|
|
||||||
enable_gzip = true
|
|
@@ -1,25 +0,0 @@
|
|||||||
# config file version
|
|
||||||
apiVersion: 1
|
|
||||||
|
|
||||||
providers:
|
|
||||||
# <string> an unique provider name
|
|
||||||
- name: My Dashboard
|
|
||||||
# <int> org id. will default to orgId 1 if not specified
|
|
||||||
org_id: 1
|
|
||||||
# <string, required> name of the dashboard folder. Required
|
|
||||||
folder: ""
|
|
||||||
# <string, required> provider type. Required
|
|
||||||
type: "file"
|
|
||||||
# <bool> disable dashboard deletion
|
|
||||||
disableDeletion: false
|
|
||||||
# <bool> enable dashboard editing
|
|
||||||
editable: true
|
|
||||||
# <int> how often Grafana will scan for changed dashboards
|
|
||||||
updateIntervalSeconds: 5
|
|
||||||
# <bool> allow updating provisioned dashboards from the UI
|
|
||||||
allowUiUpdates: true
|
|
||||||
options:
|
|
||||||
# <string, required> path to dashboard files on disk. Required
|
|
||||||
path: /etc/grafana/dashboards
|
|
||||||
# <bool> use folder names from filesystem to create folders in Grafana
|
|
||||||
foldersFromFilesStructure: true
|
|
@@ -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
|
|
@@ -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
|
|
@@ -24,7 +24,8 @@ const ClientCount = 32
|
|||||||
func main() {
|
func main() {
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
http.Handle("/metrics", promhttp.Handler())
|
||||||
go func() {
|
go func() {
|
||||||
http.ListenAndServe(":2112", nil)
|
http.Handle("/debug/metrics/prometheus", promhttp.Handler())
|
||||||
|
log.Fatal(http.ListenAndServe(":5001", nil))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
rcmgrObs.MustRegisterWith(prometheus.DefaultRegisterer)
|
rcmgrObs.MustRegisterWith(prometheus.DefaultRegisterer)
|
||||||
|
@@ -11,5 +11,6 @@ scrape_configs:
|
|||||||
static_configs:
|
static_configs:
|
||||||
- targets: ["node-exporter:9100"]
|
- targets: ["node-exporter:9100"]
|
||||||
- job_name: "go-libp2p"
|
- job_name: "go-libp2p"
|
||||||
|
metrics_path: /debug/metrics/prometheus
|
||||||
static_configs:
|
static_configs:
|
||||||
- targets: ["go-libp2p-node:2112"]
|
- targets: ["go-libp2p-node:5001"]
|
||||||
|
Reference in New Issue
Block a user