feat: 支持环境变量控制 Prometheus metrics
All checks were successful
itom-platform auto build image / build (push) Successful in 3m17s

This commit is contained in:
kim.dev.6789
2026-01-16 23:21:11 +08:00
parent 59aa8c4fce
commit e018f742ad
5 changed files with 73 additions and 0 deletions

View File

@@ -24,8 +24,10 @@ 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"
"strings"
)
type Config struct {
@@ -75,6 +77,24 @@ func Start(ctx context.Context, index int, cfg *Config) error {
}
c.Next()
})
// 可选的 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()))
}
SetBotRoute(engine, botApi, mwApi)
var (