hwt/cmd/hwtd/main.go

35 lines
698 B
Go
Raw Normal View History

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"
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()
sm.Handle("/", th)
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)
}
}