82466d587d
iotlcm-upstream-proxy:渠道缓存与转发网关。 - 内联原私有依赖:yunze-public → internal/pub/(18 文件), yunze-pb/pb → internal/pb/(9 文件);Consul 注册改用官方 gogf/gf/contrib/registry/consul/v2(API 兼容) - Go module:yz-svr → git.5iot.com/iotlcm-public/iotlcm-upstream-proxy - 凭据与内部标识脱敏:MySQL/Redis/Consul 凭据、私网与生产 IP、内网域名 - 移除内部资产:CI 触发器 - Dockerfile 改用公共基础镜像,移除写死的 registry 凭据 - 补 Apache-2.0 LICENSE,重写 README,LF 行尾 + .gitattributes
128 lines
2.9 KiB
Go
128 lines
2.9 KiB
Go
package info
|
|
|
|
import (
|
|
"context"
|
|
"runtime"
|
|
|
|
"git.5iot.com/iotlcm-public/iotlcm-upstream-proxy/internal/pub/xjpubmodel"
|
|
"git.5iot.com/iotlcm-public/iotlcm-upstream-proxy/internal/pub/xjpubservice"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/glog"
|
|
)
|
|
|
|
type sInfoRpc struct {
|
|
Info *xjpubmodel.InfoModel
|
|
}
|
|
|
|
func NewInfoRpc() *sInfoRpc {
|
|
return &sInfoRpc{
|
|
Info: xjpubmodel.NewInfoModel(),
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
xjpubservice.RegisterInfoRpc(NewInfoRpc())
|
|
}
|
|
|
|
func (s *sInfoRpc) GetInfo() *xjpubmodel.InfoModel {
|
|
ctx := context.Background()
|
|
logLevel := g.Cfg().MustGet(ctx, "logger.level", "").String()
|
|
if logLevel != "" {
|
|
g.Log().SetLevelStr(logLevel)
|
|
}
|
|
s.AddInfoData("log_level_conf", logLevel)
|
|
s.AddInfoData("log_level_real", toLogLevelStr(g.Log().GetLevel()))
|
|
s.AddInfoData("Goroutines", runtime.NumGoroutine())
|
|
var m runtime.MemStats
|
|
runtime.ReadMemStats(&m)
|
|
s.AddInfoData("MemAllocKB", m.Alloc/1024)
|
|
s.AddInfoData("MemTotalAllocKB", m.TotalAlloc/1024)
|
|
s.AddInfoData("MemSysKB", m.Sys/1024)
|
|
s.AddInfoData("MemHeapAllocKB", m.HeapAlloc/1024)
|
|
s.AddInfoData("MemHeapSysKB", m.HeapSys/1024)
|
|
s.AddInfoData("MemHeapIdleKB", m.HeapIdle/1024)
|
|
s.AddInfoData("MemHeapInuseKB", m.HeapInuse/1024)
|
|
s.AddInfoData("MemHeapReleasedKB", m.HeapReleased/1024)
|
|
s.AddInfoData("MemHeapObjects", m.HeapObjects)
|
|
s.AddInfoData("MemStackInuseKB", m.StackInuse/1024)
|
|
s.AddInfoData("MemStackSysKB", m.StackSys/1024)
|
|
s.AddInfoData("MemNumGC", m.NumGC)
|
|
return s.Info
|
|
}
|
|
|
|
func toLogLevelStr(level int) string {
|
|
if level == glog.LEVEL_NONE {
|
|
return "NONE"
|
|
}
|
|
if level == glog.LEVEL_ALL {
|
|
return "ALL"
|
|
}
|
|
if level == glog.LEVEL_DEV {
|
|
return "DEV"
|
|
}
|
|
if level == glog.LEVEL_PROD {
|
|
return "PROD"
|
|
}
|
|
str := ""
|
|
if level&glog.LEVEL_DEBU != 0 {
|
|
str += "DEBUG "
|
|
}
|
|
if level&glog.LEVEL_INFO != 0 {
|
|
str += "INFO "
|
|
}
|
|
if level&glog.LEVEL_NOTI != 0 {
|
|
str += "NOTI "
|
|
}
|
|
if level&glog.LEVEL_WARN != 0 {
|
|
str += "WARN "
|
|
}
|
|
if level&glog.LEVEL_ERRO != 0 {
|
|
str += "ERRO "
|
|
}
|
|
if level&glog.LEVEL_CRIT != 0 {
|
|
str += "CRIT "
|
|
}
|
|
if level&glog.LEVEL_PANI != 0 {
|
|
str += "PANI "
|
|
}
|
|
if level&glog.LEVEL_FATA != 0 {
|
|
str += "FATA "
|
|
}
|
|
return str
|
|
}
|
|
|
|
func (s *sInfoRpc) SetInfoName(Type, Name, Title, Description string) {
|
|
if s.Info.Name == "" {
|
|
s.Info.Type = Type
|
|
s.Info.Name = Name
|
|
s.Info.Title = Title
|
|
s.Info.Description = Description
|
|
}
|
|
}
|
|
|
|
func (s *sInfoRpc) SetInfoBuild(buildVersion, buildTime, commitID string) {
|
|
s.Info.Version = buildVersion
|
|
s.Info.Build = buildTime
|
|
s.Info.Commit = commitID
|
|
}
|
|
|
|
func (s *sInfoRpc) SetInfoData(data map[string]interface{}) {
|
|
s.Info.Data = data
|
|
}
|
|
|
|
func (s *sInfoRpc) GetInfoData() map[string]interface{} {
|
|
return s.Info.Data
|
|
}
|
|
|
|
func (s *sInfoRpc) AddInfoData(key string, value interface{}) {
|
|
s.Info.Data[key] = value
|
|
}
|
|
|
|
func (s *sInfoRpc) DelInfoData(key string) {
|
|
delete(s.Info.Data, key)
|
|
}
|
|
|
|
func (s *sInfoRpc) GetInfoDataByKey(key string) interface{} {
|
|
return s.Info.Data[key]
|
|
}
|