move promethgeus init in metrics package
This commit is contained in:
parent
b49cc6f729
commit
4d287568b6
2 changed files with 21 additions and 13 deletions
14
main.go
14
main.go
|
|
@ -12,7 +12,6 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
ginlogrus "github.com/toorop/gin-logrus"
|
||||
"jonasled.dev/jonasled/hostware-vnc-proxy/encryption"
|
||||
"jonasled.dev/jonasled/hostware-vnc-proxy/log"
|
||||
|
|
@ -155,18 +154,7 @@ func main() {
|
|||
metrics.Sessions.WithLabelValues(vncConfig.NodeName, vncConfig.VmID).Set(0)
|
||||
})
|
||||
|
||||
if os.Getenv("PROMETHEUS_METRICS") == "true" {
|
||||
if os.Getenv("PROMETHEUS_AUTH_USERNAME") != "" {
|
||||
log.Log.Info("Prometheus metrics are available at /metrics")
|
||||
authorized := r.Group("/metrics", gin.BasicAuth(gin.Accounts{
|
||||
os.Getenv("PROMETHEUS_AUTH_USERNAME"): os.Getenv("PROMETHEUS_AUTH_PASSWORD"),
|
||||
}))
|
||||
authorized.GET("/", gin.WrapH(promhttp.Handler()))
|
||||
} else {
|
||||
log.Log.Warn("You've enabled the prometheus endpoint without authentication.")
|
||||
r.GET("/metrics", gin.WrapH(promhttp.Handler()))
|
||||
}
|
||||
}
|
||||
metrics.InitPrometheus(r)
|
||||
|
||||
log.Log.Info("Start listening on port 8080")
|
||||
if os.Getenv("TLS_CERT") == "" {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"jonasled.dev/jonasled/hostware-vnc-proxy/log"
|
||||
)
|
||||
|
||||
var VncSessionsHandled = promauto.NewCounter(prometheus.CounterOpts{
|
||||
|
|
@ -22,3 +27,18 @@ var Sessions = promauto.NewGaugeVec(
|
|||
},
|
||||
[]string{"node", "vmid"},
|
||||
)
|
||||
|
||||
func InitPrometheus(r *gin.Engine) {
|
||||
if os.Getenv("PROMETHEUS_METRICS") == "true" {
|
||||
if os.Getenv("PROMETHEUS_AUTH_USERNAME") != "" {
|
||||
log.Log.Info("Prometheus metrics are available at /metrics")
|
||||
authorized := r.Group("/metrics", gin.BasicAuth(gin.Accounts{
|
||||
os.Getenv("PROMETHEUS_AUTH_USERNAME"): os.Getenv("PROMETHEUS_AUTH_PASSWORD"),
|
||||
}))
|
||||
authorized.GET("/", gin.WrapH(promhttp.Handler()))
|
||||
} else {
|
||||
log.Log.Warn("You've enabled the prometheus endpoint without authentication.")
|
||||
r.GET("/metrics", gin.WrapH(promhttp.Handler()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue