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

Better metrics #503

Merged
merged 3 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ jobs:
- name: Git checkout
uses: actions/checkout@v2

- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v3
with:
go-version-file: go.mod

- name: clone and make redis
run: |
sudo apt-get install git
Expand Down
7 changes: 7 additions & 0 deletions internal/rdb/rdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ func (ld *Loader) ParseRDB() int {

// read entries
ld.parseRDBEntry(rd)

// force update rdb_sent_size for issue: https://github.com/alibaba/RedisShake/issues/485
fi, err := os.Stat(ld.filPath)
if err != nil {
log.Panicf("NewRDBReader: os.Stat error: %s", err.Error())
}
statistics.Metrics.RdbSendSize = uint64(fi.Size())
return ld.replStreamDbId
}

Expand Down
2 changes: 2 additions & 0 deletions internal/reader/psync.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (r *psyncReader) saveRDB() {
r.receivedOffset = int64(masterOffset)

log.Infof("source db is doing bgsave. address=[%s]", r.address)
statistics.Metrics.IsDoingBgsave = true
timeStart := time.Now()
// format: \n\n\n$<length>\r\n<rdb>
for true {
Expand All @@ -139,6 +140,7 @@ func (r *psyncReader) saveRDB() {
}
break
}
statistics.Metrics.IsDoingBgsave = false
log.Infof("source db bgsave finished. timeUsed=[%.2f]s, address=[%s]", time.Since(timeStart).Seconds(), r.address)
lengthStr, err := r.rd.ReadString('\n')
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions internal/reader/rdb_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/alibaba/RedisShake/internal/entry"
"github.com/alibaba/RedisShake/internal/log"
"github.com/alibaba/RedisShake/internal/rdb"
"github.com/alibaba/RedisShake/internal/statistics"
"os"
"path/filepath"
)

Expand All @@ -30,6 +32,12 @@ func (r *rdbReader) StartRead() chan *entry.Entry {
go func() {
// start parse rdb
log.Infof("start send RDB. path=[%s]", r.path)
fi, err := os.Stat(r.path)
if err != nil {
log.Panicf("NewRDBReader: os.Stat error: %s", err.Error())
}
statistics.Metrics.RdbFileSize = uint64(fi.Size())
statistics.Metrics.RdbReceivedSize = uint64(fi.Size())
rdbLoader := rdb.NewLoader(r.path, r.ch)
_ = rdbLoader.ParseRDB()
log.Infof("send RDB finished. path=[%s]", r.path)
Expand Down
1 change: 1 addition & 0 deletions internal/statistics/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type metrics struct {
DisallowEntriesCount uint64 `json:"disallow_entries_count"`

// rdb
IsDoingBgsave bool `json:"is_doing_bgsave"`
RdbFileSize uint64 `json:"rdb_file_size"`
RdbReceivedSize uint64 `json:"rdb_received_size"`
RdbSendSize uint64 `json:"rdb_send_size"`
Expand Down
5 changes: 4 additions & 1 deletion scripts/cluster_helper/cluster_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def loop():
for metric in sorted(metrics, key=lambda x: x["address"]):
address = metric['address']
if metric['rdb_file_size'] == 0:
print(f"{metric['address']} shaking...")
if metric['is_doing_bgsave']:
print(f"{address} is doing bgsave...")
else:
print(f"{metric['address']} handshaking...")
elif metric['rdb_received_size'] < metric['rdb_file_size']:
print(f"{metric['address']} receiving rdb. "
f"percent=[{metric['rdb_received_size'] / metric['rdb_file_size'] * 100:.2f}]%, "
Expand Down