Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statistics: show stores of peers in pd-ctl output #5330

Merged
merged 6 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,23 +1032,14 @@ func (h *Handler) packHotRegions(hotPeersStat statistics.StoreHotPeersStat, hotR
if err != nil {
return nil, err
}
var peerID uint64
var isLearner bool
for _, peer := range meta.Peers {
if peer.StoreId == hotPeerStat.StoreID {
peerID = peer.Id
isLearner = core.IsLearner(peer)
break
}
}
stat := storage.HistoryHotRegion{
// store in ms.
UpdateTime: hotPeerStat.LastUpdateTime.UnixNano() / int64(time.Millisecond),
RegionID: hotPeerStat.RegionID,
StoreID: hotPeerStat.StoreID,
PeerID: peerID,
IsLeader: peerID == region.GetLeader().Id,
IsLearner: isLearner,
PeerID: region.GetStorePeer(hotPeerStat.StoreID).GetId(),
IsLeader: hotPeerStat.IsLeader,
IsLearner: hotPeerStat.IsLearner,
HotDegree: int64(hotPeerStat.HotDegree),
FlowBytes: hotPeerStat.ByteRate,
KeyRate: hotPeerStat.KeyRate,
Expand Down
16 changes: 16 additions & 0 deletions server/statistics/hot_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type HotPeerStat struct {

actionType ActionType
isLeader bool
isLearner bool
interval uint64
thresholds []float64
peers []*metapb.Peer
Expand Down Expand Up @@ -131,6 +132,7 @@ func (stat *HotPeerStat) Log(str string, level func(msg string, fields ...zap.Fi
zap.Uint64("region-id", stat.RegionID),
zap.Uint64("store", stat.StoreID),
zap.Bool("is-leader", stat.isLeader),
zap.Bool("is-learner", stat.isLearner),
zap.String("type", stat.Kind.String()),
zap.Float64s("loads", stat.GetLoads()),
zap.Float64s("loads-instant", stat.Loads),
Expand Down Expand Up @@ -219,3 +221,17 @@ func (stat *HotPeerStat) getIntervalSum() time.Duration {
}
return stat.rollingLoads[0].lastAverage.GetIntervalSum()
}

// GetStores returns stores of the item.
func (stat *HotPeerStat) GetStores() []uint64 {
stores := []uint64{}
for _, peer := range stat.peers {
stores = append(stores, peer.StoreId)
}
return stores
}

// IsLearner indicates whether the item is learner.
func (stat *HotPeerStat) IsLearner() bool {
return stat.isLearner
}
2 changes: 2 additions & 0 deletions server/statistics/hot_peer_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (f *hotPeerCache) checkPeerFlow(peer *core.PeerInfo, region *core.RegionInf
Loads: loads,
LastUpdateTime: time.Now(),
isLeader: region.GetLeader().GetStoreId() == storeID,
isLearner: core.IsLearner(region.GetPeer(storeID)),
interval: interval,
peers: region.GetPeers(),
actionType: Update,
Expand Down Expand Up @@ -230,6 +231,7 @@ func (f *hotPeerCache) checkColdPeer(storeID uint64, reportRegions map[uint64]*c
Loads: oldItem.thresholds,
LastUpdateTime: time.Now(),
isLeader: oldItem.isLeader,
isLearner: oldItem.isLearner,
interval: interval,
peers: oldItem.peers,
actionType: Update,
Expand Down
3 changes: 3 additions & 0 deletions server/statistics/hot_regions_stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type HotPeersStat struct {
// HotPeerStatShow records the hot region statistics for output
type HotPeerStatShow struct {
StoreID uint64 `json:"store_id"`
Stores []uint64 `json:"stores"`
IsLeader bool `json:"is_leader"`
IsLearner bool `json:"is_learner"`
RegionID uint64 `json:"region_id"`
HotDegree int `json:"hot_degree"`
ByteRate float64 `json:"flow_bytes"`
Expand Down
3 changes: 3 additions & 0 deletions server/statistics/store_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func toHotPeerStatShow(p *HotPeerStat, kind RWType) HotPeerStatShow {
queryRate := p.Loads[q]
return HotPeerStatShow{
StoreID: p.StoreID,
Stores: p.GetStores(),
IsLeader: p.IsLeader(),
IsLearner: p.IsLearner(),
RegionID: p.RegionID,
HotDegree: p.HotDegree,
ByteRate: byteRate,
Expand Down