Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Building an Observability D | Go Programming Bootcamp lesson | BraveProgrammer
  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 58 of 60

·Go

Building an Observability Dashboard with Prometheus & Grafana

25 minutes

Course progress97%

Prometheus Exporter

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

Expose metrics via /metrics endpoint.

import (
    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/client_golang/prometheus/promhttp"
)

var (
    requestCount = prometheus.NewCounterVec(prometheus.CounterOpts{Name: , Help: }, []{})
)

 { prometheus.MustRegister(requestCount) }

 http.Handler {
     http.HandlerFunc( {
        requestCount.WithLabelValues(r.URL.Path).Inc()
        next.ServeHTTP(w, r)
    })
}

 {
    mux := http.NewServeMux()
    
    mux.Handle(, promhttp.Handler())
    log.Fatal(http.ListenAndServe(, metricsMiddleware(mux))
}
"http_requests_total"
"Total HTTP requests"
string
"handler"
func init()
func metricsMiddleware(next http.Handler)
return
func(w http.ResponseWriter, r *http.Request)
func main()
// … register app handlers …
"/metrics"
":8080"

Grafana

  • Add Prometheus as a data source (http://localhost:9090).
  • Create a dashboard visualizing http_requests_total.

Info

Exporter libraries exist for many Go metrics (runtime, DB, custom). Use promauto.NewGauge for gauges.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from Go Programming BootcampBrowse activities
Previous lessonTesting HTTP Handlers – Table‑Driven ApproachContinue to lesson 59Deploying a gRPC Service on Google Cloud RunBack to Go Programming Bootcamp curriculum