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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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