代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。