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: make it possible to spin up Grafana using docker-compose #2383

Merged
merged 4 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
31 changes: 31 additions & 0 deletions dashboards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,34 @@

This directory contains prebuilt dashboards (provided as JSON files) for various components.
For steps on how to import and use them [please read the official Grafana documentation.](https://grafana.com/docs/grafana/latest/dashboards/export-import/#import-dashboard)

## Using locally

For local development and debugging, it can be useful to spin up a local Prometheus and Grafana instance.

To expose metrics, we first need to expose a metrics collection endpoint. Add this to your code:

```go
import "github.com/prometheus/client_golang/prometheus/promhttp"

go func() {
http.Handle("/debug/metrics/prometheus", promhttp.Handler())
log.Fatal(http.ListenAndServe(":5001", nil))
}()
```

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.

Dashboards can be inspected locally by running
```bash
docker-compose up
```

and opening Grafana at http://localhost:3000.


### Making Dashboards usable with Provisioning

The following section is only relevant for creators of dashboards.

Due to a bug in Grafana, it's not possible to provision dashboards shared for external use directly. We need to apply the workaround described in https://github.com/grafana/grafana/issues/10786#issuecomment-568788499 (adding the a few lines in the dashboard JSON file).
10 changes: 10 additions & 0 deletions dashboards/autonat/autonat.json
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,16 @@
"tags": [],
"templating": {
"list": [
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn’t know you could do this. Cool!

"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
Expand Down
10 changes: 10 additions & 0 deletions dashboards/autorelay/autorelay.json
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
Expand Down
12 changes: 12 additions & 0 deletions dashboards/dashboard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: 1

providers:
- name: "libp2p dashboard provider"
orgId: 1
type: file
disableDeletion: false
updateIntervalSeconds: 10
allowUiUpdates: false
options:
path: /var/lib/grafana/dashboards
foldersFromFilesStructure: true
13 changes: 13 additions & 0 deletions dashboards/datasources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: 1

deleteDatasources:
- name: Prometheus
orgId: 1

datasources:
- name: Prometheus
orgId: 1
type: prometheus
access: proxy
url: http://host.docker.internal:9090
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be prometheus:9090

editable: false
27 changes: 27 additions & 0 deletions dashboards/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3.7"
services:
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
grafana:
image: grafana/grafana:latest
depends_on:
- prometheus
ports:
- "3000:3000"
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
- ./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
marten-seemann marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 10 additions & 0 deletions dashboards/eventbus/eventbus.json
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
Expand Down
12 changes: 11 additions & 1 deletion dashboards/holepunch/holepunch.json
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"definition": "label_values(instance)",
Expand Down Expand Up @@ -1123,4 +1133,4 @@
"uid": "Ao24vOBVk",
"version": 6,
"weekStart": ""
}
}
10 changes: 10 additions & 0 deletions dashboards/identify/identify.json
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
Expand Down
30 changes: 30 additions & 0 deletions dashboards/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
global:
scrape_interval: 15s
scrape_timeout: 10s
evaluation_interval: 15s
alerting:
alertmanagers:
- scheme: http
timeout: 10s
api_version: v1
static_configs:
- targets: []
scrape_configs:
- job_name: prometheus
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- localhost:9090
- job_name: libp2p
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /debug/metrics/prometheus
scheme: http
static_configs:
- targets:
- host.docker.internal:5001
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works on macos. This will fail on linux

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would this work on Linux?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no easy way unfortunately. You can use https://github.com/qoomon/docker-host but that requires binding the host thing to 0.0.0.0 (or at least the bridge interface).

You can do network_mode=host, but then that doesn't work for MacOS environmnets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #2387.

10 changes: 10 additions & 0 deletions dashboards/relaysvc/relaysvc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
Expand Down
10 changes: 10 additions & 0 deletions dashboards/resource-manager/resource-manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
Expand Down
12 changes: 11 additions & 1 deletion dashboards/swarm/swarm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3033,6 +3033,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
Expand Down Expand Up @@ -3067,4 +3077,4 @@
"uid": "a15PyhO4z",
"version": 6,
"weekStart": ""
}
}