We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Service Metrics

Now that Prometheus and Grafana are configured and monitoring the operating system, let's configure Linko to expose application-specific metrics. Prometheus provides official Go support via github.com/prometheus/client_golang/prometheus.

Configuring a Go web app to export Prometheus metrics is straightforward. We'll use the github.com/prometheus/client_golang/prometheus/promhttp package, which provides an HTTP handler we can register on an endpoint of our choice. /metrics is the common convention.

mux.Handle("GET /metrics", promhttp.Handler())

That line registers the promhttp.Handler() to respond to GET requests on /metrics.

Assignment

Update Prometheus and Grafana to monitor Linko's application metrics.

  1. go run .
    
  2. - job_name: linko
      static_configs:
        - targets: ["host.docker.internal:8899"]
    

    for Windows (WSL2) users

    If you're on WSL2 and the linko target stays DOWN, replace host.docker.internal with your WSL IP from hostname -I.

  3. extra_hosts:
      - "host.docker.internal:host-gateway"
    
  4. docker compose up
    
  5. go_gc_duration_seconds_sum{job="linko"}
    

Run and submit the CLI tests from the root of the Linko repo.