1 Star 0 Fork 0

jack/protoactor-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
metrics.go 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
490689386@qq.com 提交于 2025-05-19 14:50 +08:00 . 初始化
// Copyright (C) 2017 - 2024 Asynkron.se <http://www.asynkron.se>
package actor
import (
"fmt"
"log/slog"
"strings"
"gitee.com/wujianhai/protoactor-go/extensions"
"gitee.com/wujianhai/protoactor-go/metrics"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
)
var extensionId = extensions.NextExtensionID()
type Metrics struct {
metrics *metrics.ProtoMetrics
enabled bool
actorSystem *ActorSystem
}
var _ extensions.Extension = &Metrics{}
func (m *Metrics) Enabled() bool {
return m.enabled
}
func (m *Metrics) ExtensionID() extensions.ExtensionID {
return extensionId
}
func NewMetrics(system *ActorSystem, provider metric.MeterProvider) *Metrics {
if provider == nil {
return &Metrics{}
}
return &Metrics{
metrics: metrics.NewProtoMetrics(system.Logger()),
enabled: true,
actorSystem: system,
}
}
func (m *Metrics) PrepareMailboxLengthGauge() {
meter := otel.Meter(metrics.LibName)
gauge, err := meter.Int64ObservableGauge("protoactor_actor_mailbox_length",
metric.WithDescription("Actor's Mailbox Length"),
metric.WithUnit("1"))
if err != nil {
err = fmt.Errorf("failed to create ActorMailBoxLength instrument, %w", err)
m.actorSystem.Logger().Error(err.Error(), slog.Any("error", err))
}
m.metrics.Instruments().SetActorMailboxLengthGauge(gauge)
}
func (m *Metrics) CommonLabels(ctx Context) []attribute.KeyValue {
labels := []attribute.KeyValue{
attribute.String("address", ctx.ActorSystem().Address()),
attribute.String("actortype", strings.Replace(fmt.Sprintf("%T", ctx.Actor()), "*", "", 1)),
}
return labels
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wujianhai/protoactor-go.git
git@gitee.com:wujianhai/protoactor-go.git
wujianhai
protoactor-go
protoactor-go
5633fe2499dd

搜索帮助