You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package service_base
|
|
|
|
import (
|
|
"core/abtime"
|
|
"core/prometheus"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
type Prometheus struct {
|
|
registry *prometheus.Prometheus
|
|
stype string
|
|
sid string
|
|
|
|
handMsgNum *prometheus.CounterVec //客户端消息处理数量
|
|
handMsgCost *prometheus.CounterVec //客户端消息处理耗时
|
|
online *prometheus.GaugeVec //在线玩家数量
|
|
battle_histogram *prometheus.HistogramVec //战斗耗时分布
|
|
}
|
|
|
|
func (this *Prometheus) init(registry *prometheus.Prometheus, stype string, sid int32) {
|
|
this.registry = registry
|
|
this.stype = stype
|
|
this.sid = strconv.Itoa(int(sid))
|
|
subsystem := "service"
|
|
this.handMsgNum = this.registry.RegCounter(subsystem, "msg_num", []string{"stype", "sid", "msg"})
|
|
this.handMsgCost = this.registry.RegCounter(subsystem, "msg_cost", []string{"stype", "sid", "msg"})
|
|
this.online = this.registry.RegGauge(subsystem, "online", []string{"sid"})
|
|
this.battle_histogram = this.registry.RegHistogram(subsystem, "battle_his", []string{"sid"}, []float64{2, 4, 8, 16, 32, 64, 256, 512, 1024, 2048, 4096})
|
|
}
|
|
|
|
func (this *Prometheus) RecordHandMsg(start time.Time, msg string) {
|
|
cost := abtime.Now().Sub(start)
|
|
if cost < 0 {
|
|
cost = 0
|
|
}
|
|
this.handMsgNum.Inc(this.stype, this.sid, msg)
|
|
this.handMsgCost.Add(float64(cost), this.stype, this.sid, msg)
|
|
}
|
|
|
|
func (this *Prometheus) RecordOnline(num int) {
|
|
this.online.Set(float64(num), this.sid)
|
|
}
|
|
|
|
func (this *Prometheus) RecordBattle(t int64) {
|
|
this.battle_histogram.Observe(float64(t), this.sid)
|
|
}
|