instrumentation.go 1.1 KB
Newer Older
1 2
package node

ale's avatar
ale committed
3 4 5 6 7 8
import (
	"net/http"

	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

var (
	streamSentBytes = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "bytes_sent",
			Help: "Bytes proxied to the client, by stream.",
		},
		[]string{"stream"},
	)
	streamRcvdBytes = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "bytes_received",
			Help: "Bytes received from the client, by stream.",
		},
		[]string{"stream"},
	)
	streamListeners = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "listeners",
			Help: "Number of current listeners.",
		},
		[]string{"stream"},
	)
ale's avatar
ale committed
32 33 34 35 36 37 38
	proxyConnectErrs = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "proxy_connect_errors",
			Help: "Proxy connection errors (client-side).",
		},
		[]string{"stream", "upstream"},
	)
39 40 41 42 43 44 45
)

func init() {
	prometheus.MustRegister(
		streamSentBytes,
		streamRcvdBytes,
		streamListeners,
ale's avatar
ale committed
46
		proxyConnectErrs,
47 48
	)
}
ale's avatar
ale committed
49 50 51 52 53 54

func newMetricsHandler() http.Handler {
	mux := http.NewServeMux()
	mux.Handle("/metrics", promhttp.Handler())
	return mux
}