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

@@ -7,6 +7,7 @@ import (
"net/http"
"os"
"os/signal"
"strings"
"syscall"
"time"
@@ -26,6 +27,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"
clientv3 "go.etcd.io/etcd/client/v3"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
@@ -81,6 +83,24 @@ func Start(ctx context.Context, index int, config *Config) error {
}
c.Next()
})
// 可选的 Prometheus metrics 端点
// 支持配置文件或环境变量控制(环境变量优先)
prometheusEnable := config.AdminAPI.Prometheus.Enable
if envEnable := os.Getenv("PROMETHEUS_ENABLE"); envEnable != "" {
prometheusEnable = strings.ToLower(envEnable) == "true" || envEnable == "1"
}
if prometheusEnable {
metricsPath := config.AdminAPI.Prometheus.Path
if envPath := os.Getenv("PROMETHEUS_PATH"); envPath != "" {
metricsPath = envPath
}
if metricsPath == "" {
metricsPath = "/metrics"
}
engine.GET(metricsPath, gin.WrapH(promhttp.Handler()))
}
SetAdminRoute(engine, adminApi, mwApi, config, client)
if config.Discovery.Enable == kdisc.ETCDCONST {