diff --git a/src/redis-shake/common/common.go b/src/redis-shake/common/common.go index 2543f12..74b6d46 100644 --- a/src/redis-shake/common/common.go +++ b/src/redis-shake/common/common.go @@ -146,4 +146,21 @@ func CheckVersionChecksum(d []byte) (uint, uint64, error) { } return rdbVersion, checksum, nil +} + +func GetMetric(input int64) string { + switch { + case input > PB: + return fmt.Sprintf("%.3fPB", float64(input) / PB) + case input > TB: + return fmt.Sprintf("%.3fTB", float64(input) / TB) + case input > GB: + return fmt.Sprintf("%.3fGB", float64(input) / GB) + case input > MB: + return fmt.Sprintf("%.3fMB", float64(input) / MB) + case input > KB: + return fmt.Sprintf("%.3fKB", float64(input) / KB) + default: + return fmt.Sprintf("%dB", input) + } } \ No newline at end of file diff --git a/src/redis-shake/decode.go b/src/redis-shake/decode.go index 68c7e29..0a0ce1e 100644 --- a/src/redis-shake/decode.go +++ b/src/redis-shake/decode.go @@ -102,9 +102,9 @@ func (cmd *CmdDecode) decode(input, output string) { var b bytes.Buffer fmt.Fprintf(&b, "decode: ") if nsize != 0 { - fmt.Fprintf(&b, "total = %d - %12d [%3d%%]", nsize, stat.rbytes, 100*stat.rbytes/nsize) + fmt.Fprintf(&b, "total = %s - %12s [%3d%%]", utils.GetMetric(nsize), utils.GetMetric(stat.rbytes), 100*stat.rbytes/nsize) } else { - fmt.Fprintf(&b, "total = %12d", stat.rbytes) + fmt.Fprintf(&b, "total = %12s", utils.GetMetric(stat.rbytes)) } fmt.Fprintf(&b, " write=%-12d", stat.wbytes) fmt.Fprintf(&b, " entry=%-12d", stat.nentry) diff --git a/src/redis-shake/dump.go b/src/redis-shake/dump.go index 394a45b..71d9836 100644 --- a/src/redis-shake/dump.go +++ b/src/redis-shake/dump.go @@ -99,7 +99,7 @@ func (cmd *CmdDump) dumpCommand(reader *bufio.Reader, writer *bufio.Writer, nsiz for { time.Sleep(time.Second) - log.Infof("dump: total = %d\n", nsize+nread.Get()) + log.Infof("dump: total = %s\n", utils.GetMetric(nsize+nread.Get())) } } @@ -175,7 +175,7 @@ func (dd *dbDumper) dumpRDBFile(reader *bufio.Reader, writer *bufio.Writer, nsiz } n := nread.Get() p := 100 * n / nsize - log.Infof("routine[%v] total = %d - %12d [%3d%%]\n", dd.id, nsize, n, p) + log.Infof("routine[%v] total = %s - %12s [%3d%%]\n", dd.id, utils.GetMetric(nsize), utils.GetMetric(n), p) } log.Infof("routine[%v] dump: rdb done", dd.id) } diff --git a/src/redis-shake/restore.go b/src/redis-shake/restore.go index 4c000f8..0cd1de1 100644 --- a/src/redis-shake/restore.go +++ b/src/redis-shake/restore.go @@ -199,9 +199,10 @@ func (dr *dbRestorer) restoreRDBFile(reader *bufio.Reader, target []string, auth stat := dr.Stat() var b bytes.Buffer if nsize != 0 { - fmt.Fprintf(&b, "routine[%v] total = %d - %12d [%3d%%]", dr.id, nsize, stat.rbytes, 100*stat.rbytes/nsize) + fmt.Fprintf(&b, "routine[%v] total = %s - %12s [%3d%%]", dr.id, utils.GetMetric(nsize), + utils.GetMetric(stat.rbytes), 100*stat.rbytes/nsize) } else { - fmt.Fprintf(&b, "routine[%v] total = %12d", dr.id, stat.rbytes) + fmt.Fprintf(&b, "routine[%v] total = %12s", dr.id, utils.GetMetric(stat.rbytes)) } fmt.Fprintf(&b, " entry=%-12d", stat.nentry) if stat.ignore != 0 { diff --git a/src/redis-shake/sync.go b/src/redis-shake/sync.go index 407cff7..b5ae439 100644 --- a/src/redis-shake/sync.go +++ b/src/redis-shake/sync.go @@ -464,8 +464,9 @@ func (ds *dbSyncer) syncRDBFile(reader *bufio.Reader, target []string, auth_type } stat = ds.Stat() var b bytes.Buffer - fmt.Fprintf(&b, "dbSyncer[%v] total=%d - %12d [%3d%%] entry=%-12d", - ds.id, nsize, stat.rbytes, 100*stat.rbytes/nsize, stat.nentry) + // fmt.Fprintf(&b, "dbSyncer[%v] total=%s - %12d [%3d%%] entry=%-12d", + fmt.Fprintf(&b, "dbSyncer[%v] total = %s - %12s [%3d%%] entry=%-12d", + ds.id, utils.GetMetric(nsize), utils.GetMetric(stat.rbytes), 100*stat.rbytes/nsize, stat.nentry) if stat.ignore != 0 { fmt.Fprintf(&b, " ignore=%-12d", stat.ignore) }