-
Notifications
You must be signed in to change notification settings - Fork 2
/
consume_stats.go
59 lines (53 loc) · 1.75 KB
/
consume_stats.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
package admin
import (
"git.oschina.net/cloudzone/smartgo/stgcommon/message"
"git.oschina.net/cloudzone/smartgo/stgnet/protocol"
)
// OffsetWrapper 消费者统计
// Author rongzhihong
// Since 2017/9/19
type ConsumeStats struct {
ConsumeTps float64 `json:"consumeTps"`
OffsetTable map[*message.MessageQueue]*OffsetWrapper `json:"offsetTable"`
*protocol.RemotingSerializable
}
// NewConsumeStats 初始化
// Author rongzhihong
// Since 2017/9/19
func NewConsumeStats() *ConsumeStats {
consumeStats := new(ConsumeStats)
consumeStats.OffsetTable = make(map[*message.MessageQueue]*OffsetWrapper)
consumeStats.RemotingSerializable = new(protocol.RemotingSerializable)
return consumeStats
}
// ComputeTotalDiff 偏移量差值
// Author rongzhihong
// Since 2017/9/19
func (consumeStats *ConsumeStats) ComputeTotalDiff() int64 {
diffTotal := int64(0)
if consumeStats == nil || consumeStats.OffsetTable == nil {
return diffTotal
}
for _, wrapper := range consumeStats.OffsetTable {
diff := wrapper.BrokerOffset - wrapper.ConsumerOffset
diffTotal += diff
}
return diffTotal
}
// OffsetWrapper 消费者统计
// Author rongzhihong
// Since 2017/9/19
type ConsumeStatsPlus struct {
ConsumeTps float64 `json:"consumeTps"`
OffsetTable map[string]*OffsetWrapper `json:"offsetTable"` // key: Topic@BrokerName@QueueId
*protocol.RemotingSerializable
}
// NewConsumeStats 初始化
// Author rongzhihong
// Since 2017/9/19
func NewConsumeStatsPlus() *ConsumeStatsPlus {
consumeStats := new(ConsumeStatsPlus)
consumeStats.OffsetTable = make(map[string]*OffsetWrapper)
consumeStats.RemotingSerializable = new(protocol.RemotingSerializable)
return consumeStats
}