Parcourir la source

fix:redis配置修改

duxin il y a 1 an
Parent
commit
4b95fdf63e
2 fichiers modifiés avec 18 ajouts et 19 suppressions
  1. 9 12
      config.yaml
  2. 9 7
      internal/service/manager.go

+ 9 - 12
config.yaml

@@ -3,22 +3,22 @@ server:
   readTimeout: 60s                  # 请求读取超时时间,一般不需要配置。默认为60秒
   graceful: true                    # 是否开启平滑重启特性,开启时将会在本地增加10000的本地TCP端口用于进程间通信。默认false
   gracefulTimeout: 10               # 平滑重启父进程最大存活时间。默认2秒
-
+  redisPrefix: "es"
 elasticSearch:
   address:
-    - "http://192.168.3.241:9205"
+    - "http://192.168.3.149:9201"
+    - "http://192.168.3.241:9206"
   pool:
-    simple: 5
+    simple: 50
     aggs: 2
     complex: 2
-  waitTime: 5 #单位秒
+  waitTime: 5000 #单位秒
   complexQueryLen: 200 #查询条件复杂长度
-
   threshold: 13
 
   reverseProxy:
-    timeout: 15
-    keepAlive: 60
+    timeout: 150
+    keepAlive: 600
     maxIdleConns: 100
     idleConnTimeout: 60
     tLSHandshakeTimeout: 15
@@ -27,7 +27,7 @@ elasticSearch:
 
   queryState:
     cron: "*/10 * * * * *"
-    curlAddr: "http://192.168.3.241:9205/_nodes/stats?pretty&human&filter_path=nodes.*.thread_pool.search"
+    curlAddr: "http://192.168.3.241:9206/_nodes/stats?pretty&human&filter_path=nodes.*.thread_pool.search"
 
     #elasticsearch: #查询es状态携带账户密码
     #  username: aaa
@@ -48,7 +48,4 @@ logger:
   rotateBackupCompress: 0                     # 滚动切分文件的压缩比(0-9)。默认为0,表示不压缩
   rotateCheckInterval: "1h"                  # 滚动切分的时间检测间隔,一般不需要设置。默认为1小时
   stdoutColorDisabled: false                 # 关闭终端的颜色打印。默认开启
-  writerColorEnable: false                 # 日志文件是否带上颜色。默认false,表示不带颜色
-
-logTime: 1
-logEquity: false
+  writerColorEnable: false                 # 日志文件是否带上颜色。默认false,表示不带颜色

+ 9 - 7
internal/service/manager.go

@@ -22,6 +22,7 @@ type esProxyManager struct {
 	esStatus                                         consts.EsStatus
 	proxyPool                                        chan *httputil.ReverseProxy
 	simpleQueryPool, aggsQueryPool, complexQueryPool chan struct{}
+	redisPrefix                                      string
 }
 
 // initManager 初始化代理Manager
@@ -50,6 +51,7 @@ func initManager(ctx context.Context) *esProxyManager {
 		simpleQueryPool:  makeEmptyChan(g.Cfg().MustGet(ctx, "elasticSearch.pool.simple", 10).Int()),
 		aggsQueryPool:    makeEmptyChan(g.Cfg().MustGet(ctx, "elasticSearch.pool.aggs", 10).Int()),
 		complexQueryPool: makeEmptyChan(g.Cfg().MustGet(ctx, "elasticSearch.pool.complex", 10).Int()),
+		redisPrefix:      g.Cfg().MustGet(ctx, "server.redisPrefix", "es").String(),
 	}
 
 	go emp.UpdateEsStatus(ctx)
@@ -70,7 +72,7 @@ func (epm *esProxyManager) UpdateEsStatus(ctx context.Context) {
 		err := EsStatusQuery.GetEsStatusRunning(cron, func(ctx context.Context) {
 			finalStatus := EsStatusQuery.GetEsStatus(ctx)
 			epm.esStatus = finalStatus
-			_, _ = g.Redis().Set(ctx, "es_status", finalStatus)
+			_, _ = g.Redis().Set(ctx, fmt.Sprintf("%s_status", epm.redisPrefix), finalStatus)
 			g.Log().Debugf(ctx, "当前 epm.esStatus:%v", epm.esStatus)
 		})
 		if err != nil {
@@ -82,7 +84,7 @@ func (epm *esProxyManager) UpdateEsStatus(ctx context.Context) {
 // GetProxy 获取代理对象
 func (epm *esProxyManager) GetProxy(ctx context.Context, queryLevel int) (*httputil.ReverseProxy, error) {
 	if queryLevel+int(epm.esStatus) > 2 {
-		go RejectedIncrement(ctx) //程序拒绝数
+		go RejectedIncrement(ctx, epm.redisPrefix) //程序拒绝数
 		return nil, fmt.Errorf("server is busy")
 	}
 	g.Log().Debugf(ctx, "esProxyManager pool %+v", epm.Status())
@@ -94,7 +96,7 @@ func (epm *esProxyManager) GetProxy(ctx context.Context, queryLevel int) (*httpu
 		epm.proxyPool <- c
 		return c, nil
 	case <-time.After(time.Second * time.Duration(g.Cfg().MustGet(ctx, "elasticSearch.queryState.waitTime", 5).Int())):
-		go OvertimeIncrement(ctx) //超时退出数
+		go OvertimeIncrement(ctx, epm.redisPrefix) //超时退出数
 		return nil, fmt.Errorf("wait time out")
 	}
 }
@@ -146,17 +148,17 @@ func InformationNumber(ctx context.Context) map[string]interface{} {
 }
 
 // RejectedIncrement queryLevel+int(epm.esStatus) > 2拒绝数
-func RejectedIncrement(ctx context.Context) {
+func RejectedIncrement(ctx context.Context, redisPrefix string) {
 	sy.Lock()
 	defer sy.Unlock()
-	_, _ = g.Redis().Incr(ctx, "es_rejected_count")
+	_, _ = g.Redis().Incr(ctx, fmt.Sprintf("%s_rejected_count", redisPrefix))
 }
 
 // OvertimeIncrement 超时断开数
-func OvertimeIncrement(ctx context.Context) {
+func OvertimeIncrement(ctx context.Context, redisPrefix string) {
 	sn.Lock()
 	defer sn.Unlock()
-	_, _ = g.Redis().Incr(ctx, "es_timeout_count")
+	_, _ = g.Redis().Incr(ctx, fmt.Sprintf("%s_timeout_count", redisPrefix))
 }
 
 // Increment 程序等待数