ghostream/internal/monitoring/monitoring.go

32 lines
812 B
Go
Raw Normal View History

2020-09-21 19:33:32 +00:00
package monitoring
import (
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
2020-09-22 09:42:57 +00:00
// Options holds web package configuration
type Options struct {
ListenAddress string
}
2020-09-21 19:33:32 +00:00
var (
// ViewerServed is the total amount of viewer page served
ViewerServed = promauto.NewCounter(prometheus.CounterOpts{
Name: "ghostream_viewer_served_total",
Help: "The total amount of viewer served",
})
)
// ServeHTTP server that expose prometheus metrics
2020-09-22 09:42:57 +00:00
func ServeHTTP(cfg *Options) {
2020-09-21 19:33:32 +00:00
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
2020-09-22 09:42:57 +00:00
log.Printf("Monitoring HTTP server listening on %s", cfg.ListenAddress)
log.Fatal(http.ListenAndServe(cfg.ListenAddress, mux))
2020-09-21 19:33:32 +00:00
}