arl / statsviz

🚀 Visualise your Go program runtime metrics in real time in the browser
MIT License
3.19k stars 121 forks source link

Dynamic graphs registration #118

Open AlekSi opened 8 months ago

AlekSi commented 8 months ago

It would be nice to be able to add graphs dynamically. For example, we wanted to convert Prometheus metrics to Statsviz graphs, with one graph per Prometheus label value. But the full set of values is not known in advance, so it is not possible to pass all options to statsviz.Register.

It is almost possible to do now by creating Statsviz HTTP handler on the fly in the other HTTP handler:

// pseudocode
http.HandleFunc("/debug/graphs", func(rw http.ResponseWriter, req *http.Request) {
    s, _ := statsviz.NewServer()
    s.Index().ServeHTTP(rw, req)
})

Unfortunately, there are two handlers: Index() and Ws(). Maybe it is possible to create a single handler that would route to one or another based on, say, HTTP headers?

AlekSi commented 8 months ago

@arl WDYT?

arl commented 8 months ago

Hi. I understand the use case but can you detail a bit the technical solution you'd use?