2 Star 0 Fork 0

MixerJ/pitaya

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
room.go 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
MixerJ 提交于 2020-07-18 16:58 +08:00 . !1go mod
package services
import (
"context"
"gitee.com/mixerj/pitaya"
"gitee.com/mixerj/pitaya/component"
"gitee.com/mixerj/pitaya/examples/demo/custom_metrics/messages"
)
// Room server
type Room struct {
component.Base
}
// SetCounter sets custom my_counter
func (*Room) SetCounter(
ctx context.Context,
arg *messages.SetCounterArg,
) (*messages.Response, error) {
counterMetricName := "my_counter"
for _, reporter := range pitaya.GetMetricsReporters() {
reporter.ReportCount(counterMetricName, map[string]string{
"tag1": arg.Tag1,
"tag2": arg.Tag2,
}, arg.Value)
}
return messages.OKResponse(), nil
}
// SetGauge1 sets custom my_gauge_1
func (*Room) SetGauge1(
ctx context.Context,
arg *messages.SetGaugeArg,
) (*messages.Response, error) {
counterMetricName := "my_gauge_1"
for _, reporter := range pitaya.GetMetricsReporters() {
reporter.ReportGauge(counterMetricName, map[string]string{
"tag1": arg.Tag,
}, arg.Value)
}
return messages.OKResponse(), nil
}
// SetGauge2 sets custom my_gauge_2
func (*Room) SetGauge2(
ctx context.Context,
arg *messages.SetGaugeArg,
) (*messages.Response, error) {
counterMetricName := "my_gauge_2"
for _, reporter := range pitaya.GetMetricsReporters() {
reporter.ReportGauge(counterMetricName, map[string]string{
"tag2": arg.Tag,
}, arg.Value)
}
return messages.OKResponse(), nil
}
// SetSummary sets custom my_summary
func (*Room) SetSummary(
ctx context.Context,
arg *messages.SetSummaryArg,
) (*messages.Response, error) {
counterMetricName := "my_summary"
for _, reporter := range pitaya.GetMetricsReporters() {
reporter.ReportSummary(counterMetricName, map[string]string{
"tag1": arg.Tag,
}, arg.Value)
}
return messages.OKResponse(), nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mixerj/pitaya.git
git@gitee.com:mixerj/pitaya.git
mixerj
pitaya
pitaya
4e7898a663a6

搜索帮助