SiaFoundation / walletd

A new Sia wallet
https://sia.tech/software/walletd
MIT License
14 stars 9 forks source link

Add API endpoints for Prometheus metrics collection #40

Closed bustedware closed 9 months ago

bustedware commented 9 months ago

This effort is part of grant project

Added various GET endpoints to return metrics formatted for Prometheus.

Prometheus metrics endpoint is disabled by default and runs on its own port.

lukechampine commented 9 months ago

There's an unfortunate degree of duplication here. Is it possible to do something like this instead?

func (s *server) consensusNetworkHandler(jc jape.Context) {
    if jc.Request.Header.Get("Content-Type") == "prometheus" {
        fmt.Fprintf(jc.ResponseWriter, `walletd_consensus_network{network="%s"} 1`, s.cm.TipState().Network.Name)
        return
    }
    jc.Encode(*s.cm.TipState().Network)
 }

That way, we wouldn't need separate endpoints, a separate server, etc. How exactly we branch within the handler isn't important -- it could be the Content-Type, or a query param, etc. I suppose it depends on what Prometheus supports.