feat: 支持环境变量控制 Prometheus metrics
All checks were successful
itom-platform auto build image / build (push) Successful in 3m17s
All checks were successful
itom-platform auto build image / build (push) Successful in 3m17s
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@@ -25,6 +26,7 @@ import (
|
||||
"github.com/openimsdk/tools/system/program"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
"github.com/openimsdk/tools/utils/runtimeenv"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
@@ -74,6 +76,24 @@ func Start(ctx context.Context, index int, cfg *Config) error {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
engine := gin.New()
|
||||
engine.Use(gin.Recovery(), mw.CorsHandler(), mw.GinParseOperationID())
|
||||
|
||||
// 可选的 Prometheus metrics 端点
|
||||
// 支持配置文件或环境变量控制(环境变量优先)
|
||||
prometheusEnable := cfg.ApiConfig.Prometheus.Enable
|
||||
if envEnable := os.Getenv("PROMETHEUS_ENABLE"); envEnable != "" {
|
||||
prometheusEnable = strings.ToLower(envEnable) == "true" || envEnable == "1"
|
||||
}
|
||||
if prometheusEnable {
|
||||
metricsPath := cfg.ApiConfig.Prometheus.Path
|
||||
if envPath := os.Getenv("PROMETHEUS_PATH"); envPath != "" {
|
||||
metricsPath = envPath
|
||||
}
|
||||
if metricsPath == "" {
|
||||
metricsPath = "/metrics"
|
||||
}
|
||||
engine.GET(metricsPath, gin.WrapH(promhttp.Handler()))
|
||||
}
|
||||
|
||||
SetChatRoute(engine, adminApi, mwApi)
|
||||
|
||||
var (
|
||||
|
||||
Reference in New Issue
Block a user