5 ms·
Include the client library if you want, but the wire format is ridiculously simple. I'll implement it from memory in a HN comment. http.HandleFunc("/metri
by jrockway 5y ago
Include the client library if you want, but the wire format is ridiculously simple. I'll implement it from memory in a HN comment.
http.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
w.Header().Add("content-type", "text/plain")
w.Write([]byte("# HELP foo_bar The numbers of foos barred.\n# TYPE foo_bar counter\nfoo_bar 42\n"))
})
The client library is largely to keep track of running counters (and gauges, histograms, etc.), with a small amount of code to actually report those metrics when scraped. It's a very simple format.
- morelisp 5y agoA good example of it looking simple but having annoying corner cases. The content type MUST be: application/openmetrics-text; version=1.0.0; charset=utf-8