metrics: add a basic setup, collect metrics for the server

This commit is contained in:
Marten Seemann
2024-01-13 11:47:37 +07:00
parent 459a6f3df9
commit e66a925d64
9 changed files with 261 additions and 8 deletions

View File

@@ -0,0 +1,25 @@
# quic-go Prometheus / Grafana setup
Expose a Grafana endpoint on `http://localhost:5001/prometheus`:
```go
import "github.com/prometheus/client_golang/prometheus/promhttp"
go func() {
http.Handle("/prometheus", promhttp.Handler())
log.Fatal(http.ListenAndServe(":5001", nil))
}()
```
Set a metrics tracer on the `Transport`:
```go
quic.Transport{
Tracer: metrics.NewTracer(),
}
```
When using multiple `Transport`s, it is recommended to use the metrics tracer struct for all of them.
Running:
```shell
docker-compose up
```

View File

@@ -0,0 +1,13 @@
apiVersion: 1
deleteDatasources:
- name: Prometheus
orgId: 1
datasources:
- name: Prometheus
orgId: 1
type: prometheus
access: proxy
url: http://prometheus:9090
editable: false

View File

@@ -0,0 +1,25 @@
version: '3.8'
volumes:
prometheus_data: {}
grafana_data: {}
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
expose:
- 9090
grafana:
image: grafana/grafana:latest
container_name: grafana
volumes:
- grafana_data:/var/lib/grafana
- ./datasources.yml:/etc/grafana/provisioning/datasources/prom.yml
ports:
- "3000:3000"

View File

@@ -0,0 +1,9 @@
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'quic-go'
scrape_interval: 15s
static_configs:
- targets: ['host.docker.internal:5001']
metrics_path: '/prometheus'