Building a Go Application Monitoring Dashboard
Monitoring Go services requires exporting the right metrics. Here's how to build a dashboard that gives you real visibility.
Expose Prometheus Metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
httpRequestsTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "http_requests_total",
Help: "Total HTTP requests",
},
[]string{"method", "path", "status"},
)
httpRequestDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_request_duration_seconds",
Help: "HTTP request duration",
Buckets: []float64{0.01, 0.05, 0.1, 0.5, 1, 5},
},
[]string{"method", "path"},
)
)
func init() {
prometheus.MustRegister(httpRequestsTotal, httpRequestDuration)
}Instrumentation Middleware
func MetricsMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
wrapped := &statusWriter{ResponseWriter: w, status: 200}
next.ServeHTTP(wrapped, r)
duration := time.Since(start).Seconds()
httpRequestsTotal.WithLabelValues(
r.Method, r.URL.Path, fmt.Sprintf("%d", wrapped.status),
).Inc()
httpRequestDuration.WithLabelValues(r.Method, r.URL.Path).Observe(duration)
})
}Key Dashboard Panels
Build these Grafana panels for operational visibility:
- Request rate —
rate(http_requests_total[5m])by status code - Latency percentiles —
histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m])) - Error rate — requests with 5xx status / total requests
- Goroutine count —
go_goroutines(watch for leaks) - Memory usage —
go_memstats_alloc_bytes
Runtime Metrics
Go exposes runtime metrics automatically:
http.Handle("/metrics", promhttp.Handler())This includes GC pause duration, heap allocation, and goroutine counts without any custom code.
Alerting Rules
- Error rate > 1% for 5 minutes
- P95 latency > 2s for 10 minutes
- Goroutine count > 10,000 (likely leak)
- Memory growth > 50% in 1 hour
Complement your metrics dashboard with Bugsly for error tracking. Metrics show you something is wrong; Bugsly's stack traces tell you exactly what and where.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
Bugsly Integration Guide for Nuxt.js
Set up error monitoring for Nuxt.js using Bugsly. Quick installation, configuration, and verification steps included.
Read moreNext.js Session Replay: Complete Setup Guide
Add session replay to your Next.js app with Bugsly. Covers installation, SDK setup, and production best practices.
Read moreHow to Set Up Performance Monitoring in Gatsby
Learn how to set up performance monitoring in Gatsby with Bugsly. Step-by-step guide with code examples and best practices.
Read moreError Tracking for Vue.js: A Setup Guide
Add error tracking to your Vue.js app with Bugsly. Covers installation, SDK setup, and production best practices.
Read more