/
monitoring.go
32 lines (29 loc) · 884 Bytes
/
monitoring.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package bundler
import (
"github.com/gin-gonic/gin"
"github.com/orchestd/dependencybundler/constructors/monitoring"
"github.com/orchestd/dependencybundler/interfaces/configuration"
monitoring2 "github.com/orchestd/monitoring"
"github.com/orchestd/monitoring/bprometheus"
"github.com/orchestd/sharedlib/consts"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/fx"
)
func MonitoringFxOption() fx.Option {
return fx.Options(
fx.Provide(func(config configuration.Config) (monitoring2.Builder, error) {
name, err := config.Get(consts.ServiceNameEnv).String()
if err != nil {
return nil, err
}
return bprometheus.Builder().SetNamespace(name), nil
}),
fx.Provide(monitoring.DefaultMonitor),
)
}
func PrometheusHandler() gin.HandlerFunc {
h := promhttp.Handler()
return func(c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request)
}
}