|
|
@ -2,38 +2,34 @@ package service |
|
|
|
|
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"os" |
|
|
|
"strconv" |
|
|
|
"time" |
|
|
|
|
|
|
|
"git.lowcodeplatform.net/fabric/models" |
|
|
|
"git.lowcodeplatform.net/packages/cache" |
|
|
|
"git.lowcodeplatform.net/packages/logger" |
|
|
|
dto "github.com/prometheus/client_model/go" |
|
|
|
"go.uber.org/zap" |
|
|
|
) |
|
|
|
|
|
|
|
// Ping ...
|
|
|
|
func (s *service) Ping(ctx context.Context) (result []models.Pong, err error) { |
|
|
|
var mobj []*dto.MetricFamily |
|
|
|
|
|
|
|
metrics, err := cache.Cache().Get("prometheus") |
|
|
|
if err != nil { |
|
|
|
metrics = fmt.Sprintf("error. %s", err) |
|
|
|
logger.Error(ctx, "error cache (ping)", zap.Error(err)) |
|
|
|
} |
|
|
|
|
|
|
|
bmetric, ok := metrics.([]byte) |
|
|
|
if ok { |
|
|
|
err = json.Unmarshal(bmetric, &mobj) |
|
|
|
if err != nil { |
|
|
|
metrics = fmt.Sprintf("error. %s", err) |
|
|
|
logger.Error(ctx, "cache.Cache Unmarshal", |
|
|
|
zap.Error(err), |
|
|
|
zap.String("metrics failed body", fmt.Sprintf("%+v", metrics))) |
|
|
|
} |
|
|
|
} |
|
|
|
//metrics, err := cache.Cache().Get("prometheus")
|
|
|
|
//if err != nil {
|
|
|
|
// metrics = fmt.Sprintf("error. %s", err)
|
|
|
|
// logger.Error(ctx, "error cache (ping)", zap.Error(err))
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//bmetric, ok := metrics.([]byte)
|
|
|
|
//if ok {
|
|
|
|
// err = json.Unmarshal(bmetric, &mobj)
|
|
|
|
// if err != nil {
|
|
|
|
// metrics = fmt.Sprintf("error. %s", err)
|
|
|
|
// logger.Error(ctx, "cache.Cache Unmarshal",
|
|
|
|
// zap.Error(err),
|
|
|
|
// zap.String("metrics failed body", fmt.Sprintf("%+v", metrics)))
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
pong := models.Pong{} |
|
|
|
pong.Uid = s.cfg.HashRun |
|
|
@ -48,6 +44,10 @@ func (s *service) Ping(ctx context.Context) (result []models.Pong, err error) { |
|
|
|
pong.PortGrpc = s.cfg.GrpcPort |
|
|
|
pong.PortMetric = s.cfg.HTTPPortMetric |
|
|
|
pong.Metrics = mobj |
|
|
|
pong.Environment = s.cfg.Environment |
|
|
|
pong.Cluster = s.cfg.Cluster |
|
|
|
pong.Uptime = time.Now().Sub(s.cfg.RunTime).String() |
|
|
|
pong.Runtime = s.cfg.RunTime |
|
|
|
|
|
|
|
pong.ServiceVersion = s.cfg.ServiceVersion |
|
|
|
pong.HashCommit = s.cfg.HashCommit |
|
|
|