feat: reporting basic metrics to prometheus
This commit is contained in:
13
main.go
13
main.go
@@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
||||
"sunshine.industries/some-automoderation/rooms"
|
||||
@@ -19,10 +20,20 @@ var ctx = context.Background()
|
||||
func main() {
|
||||
var port int
|
||||
flag.IntVar(&port, "port", 8080, "Port on which the server should start")
|
||||
var metricsPort int
|
||||
flag.IntVar(&metricsPort, "metricsPort", 8081, "Port on which the server expose metrics")
|
||||
var redisPort int
|
||||
flag.IntVar(&redisPort, "redisPort", 7777, "Port on which server should connect to redis db")
|
||||
flag.Parse()
|
||||
|
||||
promHandler := promhttp.Handler()
|
||||
promMux := http.NewServeMux()
|
||||
promMux.Handle("/metrics", promHandler)
|
||||
|
||||
go func() {
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", metricsPort), promMux))
|
||||
}()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: fmt.Sprintf("localhost:%d", redisPort),
|
||||
Password: "",
|
||||
@@ -32,7 +43,7 @@ func main() {
|
||||
roomsM := rooms.RedisRM { Rdb: rdb, }
|
||||
sessions := sessions.RedisSM{ Rdb: rdb, }
|
||||
|
||||
log.Printf("Server will start on port: %d; listening to redis on: %d\n", port, redisPort)
|
||||
log.Printf("Server will start on port: %d; /metrics on %d; listening to redis on: %d\n", port, metricsPort, redisPort)
|
||||
routes.RegisterRoutes(sessions, roomsM)
|
||||
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
|
||||
|
||||
Reference in New Issue
Block a user