2018-01-16 20:57:04 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
2018-01-20 09:07:57 -08:00
|
|
|
"os"
|
2018-01-16 20:57:04 -08:00
|
|
|
|
2018-01-21 13:57:31 -08:00
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
2018-01-21 14:50:32 -08:00
|
|
|
|
2018-01-16 20:57:04 -08:00
|
|
|
"mcquay.me/hwt"
|
2018-01-21 14:50:32 -08:00
|
|
|
"mcquay.me/hwt/metrics"
|
2018-01-20 08:38:58 -08:00
|
|
|
pb "mcquay.me/hwt/rpc/hwt"
|
2018-01-16 20:57:04 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-01-20 09:07:57 -08:00
|
|
|
hn, err := os.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("cannot get hostname: %v", err)
|
|
|
|
}
|
2018-01-21 14:50:32 -08:00
|
|
|
|
|
|
|
if err := metrics.RegisterPromMetrics(); err != nil {
|
|
|
|
log.Fatalf("registering prom metrics: %v", err)
|
|
|
|
}
|
|
|
|
|
2018-01-20 09:07:57 -08:00
|
|
|
s := &hwt.Server{hn}
|
2018-01-21 14:50:32 -08:00
|
|
|
hs := hwt.NewMetricsHooks(metrics.HTTPLatency)
|
|
|
|
th := pb.NewHelloWorldServer(s, hs)
|
2018-01-21 13:57:31 -08:00
|
|
|
sm := http.NewServeMux()
|
2018-01-21 20:18:28 -08:00
|
|
|
sm.HandleFunc("/", hwt.Auth(th.ServeHTTP))
|
2018-01-21 13:57:31 -08:00
|
|
|
sm.Handle("/metrics", promhttp.Handler())
|
|
|
|
if err := http.ListenAndServe(":8080", sm); err != nil {
|
2018-01-16 20:57:04 -08:00
|
|
|
log.Fatalf("listen and serve: %v", err)
|
|
|
|
}
|
|
|
|
}
|