-
Notifications
You must be signed in to change notification settings - Fork 460
/
room.go
79 lines (64 loc) · 1.73 KB
/
room.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package services
import (
"context"
"github.com/topfreegames/pitaya"
"github.com/topfreegames/pitaya/component"
"github.com/topfreegames/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
}