Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package main
import (
"fmt"
"net/http"
)
var requests = 0
func metricsHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "http_requests_total %d", requests)
}
func apiHandler(w http.ResponseWriter, r *http.Request) {
requests++
fmt.Fprintln(w, "API Response")
}
func main() {
http.HandleFunc("/api", apiHandler)
http.HandleFunc("/metrics", metricsHandler)
fmt.Println("Monitoring server running on :8080")
http.ListenAndServe(":8080", nil)
}Coding works best on desktop or with an external keyboard.