metrics: make it possible to spin up Grafana using docker-compose (#2383)

* metrics: make it possible to spin up Grafana using docker-compose

* Update dashboards/README.md

Co-authored-by: Prithvi Shahi <shahi.prithvi@gmail.com>

* disable Grafana authentication

* add holepunch dashboard

---------

Co-authored-by: Prithvi Shahi <shahi.prithvi@gmail.com>
This commit is contained in:
Marten Seemann
2023-06-21 12:23:35 +02:00
committed by GitHub
parent d3004eaf3c
commit 139af10806
13 changed files with 196 additions and 2 deletions
+31
View File
@@ -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
View File
@@ -691,6 +691,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
+10
View File
@@ -1034,6 +1034,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
+12
View File
@@ -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
View File
@@ -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
editable: false
+28
View File
@@ -0,0 +1,28 @@
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
- ./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
+10
View File
@@ -515,6 +515,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
+11 -1
View File
@@ -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)",
@@ -1123,4 +1133,4 @@
"uid": "Ao24vOBVk",
"version": 6,
"weekStart": ""
}
}
+10
View File
@@ -838,6 +838,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
+30
View File
@@ -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
+10
View File
@@ -1190,6 +1190,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
@@ -1782,6 +1782,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
+11 -1
View File
@@ -3033,6 +3033,16 @@
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"label": "datasource",
"name": "DS_PROMETHEUS",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"current": {},
"datasource": {
@@ -3067,4 +3077,4 @@
"uid": "a15PyhO4z",
"version": 6,
"weekStart": ""
}
}