1 Star 0 Fork 0

jack/protoactor-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
metrics.go 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
Roger Johansson 提交于 2024-04-04 08:43 . update copyrights
// Copyright (C) 2017 - 2024 Asynkron.se <http://www.asynkron.se>
package metrics
import (
"fmt"
"log/slog"
"sync"
)
const InternalActorMetrics string = "internal.actor.metrics"
type ProtoMetrics struct {
mu sync.Mutex
actorMetrics *ActorMetrics
knownMetrics map[string]*ActorMetrics
logger *slog.Logger
}
func NewProtoMetrics(logger *slog.Logger) *ProtoMetrics {
protoMetrics := ProtoMetrics{
actorMetrics: NewActorMetrics(logger),
knownMetrics: make(map[string]*ActorMetrics),
logger: logger,
}
protoMetrics.Register(InternalActorMetrics, protoMetrics.actorMetrics)
return &protoMetrics
}
func (pm *ProtoMetrics) Instruments() *ActorMetrics { return pm.actorMetrics }
func (pm *ProtoMetrics) Register(key string, instance *ActorMetrics) {
pm.mu.Lock()
defer pm.mu.Unlock()
logger := pm.logger
if _, ok := pm.knownMetrics[key]; ok {
err := fmt.Errorf("could not register instance %#v of metrics, %s already registered", instance, key)
logger.Error(err.Error(), slog.Any("error", err))
return
}
pm.knownMetrics[key] = instance
}
func (pm *ProtoMetrics) Get(key string) *ActorMetrics {
metrics, ok := pm.knownMetrics[key]
if !ok {
logger := pm.logger
err := fmt.Errorf("unknown metrics for the given %s key", key)
logger.Error(err.Error(), slog.Any("error", err))
return nil
}
return metrics
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wujianhai/protoactor-go.git
git@gitee.com:wujianhai/protoactor-go.git
wujianhai
protoactor-go
protoactor-go
99a34e4ec9eb

搜索帮助

0d507c66 1850385 C8b1a773 1850385