aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2020-05-28 23:27:29 -0700
committerGitHub <noreply@github.com>2020-05-28 23:27:29 -0700
commit5837fe72fc097ce3db4cd839cfc0f6dfe09f9051 (patch)
treefc8a114c4aa05f59b4a25abdab9d1c150a63c5f3
parent6286a454c7fa37198b7cffb8f895b8b9443ced8b (diff)
parentb4e93b639d95da4954052c583e2368baef2992c7 (diff)
downloadseaweedfs-5837fe72fc097ce3db4cd839cfc0f6dfe09f9051.tar.xz
seaweedfs-5837fe72fc097ce3db4cd839cfc0f6dfe09f9051.zip
Merge pull request #1335 from bingoohuang/master
add BytesToHumanReadable for see_dat and see_idx
-rw-r--r--unmaintained/see_dat/see_dat.go4
-rw-r--r--unmaintained/see_idx/see_idx.go3
-rw-r--r--weed/server/volume_server_ui/templates.go34
-rw-r--r--weed/util/bytes.go16
4 files changed, 32 insertions, 25 deletions
diff --git a/unmaintained/see_dat/see_dat.go b/unmaintained/see_dat/see_dat.go
index efc58e751..17c494841 100644
--- a/unmaintained/see_dat/see_dat.go
+++ b/unmaintained/see_dat/see_dat.go
@@ -2,6 +2,7 @@ package main
import (
"flag"
+ "github.com/chrislusf/seaweedfs/weed/util"
"time"
"github.com/chrislusf/seaweedfs/weed/glog"
@@ -31,7 +32,8 @@ func (scanner *VolumeFileScanner4SeeDat) ReadNeedleBody() bool {
func (scanner *VolumeFileScanner4SeeDat) VisitNeedle(n *needle.Needle, offset int64, needleHeader, needleBody []byte) error {
t := time.Unix(int64(n.AppendAtNs)/int64(time.Second), int64(n.AppendAtNs)%int64(time.Second))
- glog.V(0).Infof("%d,%s%x offset %d size %d cookie %x appendedAt %v", *volumeId, n.Id, n.Cookie, offset, n.Size, n.Cookie, t)
+ glog.V(0).Infof("%d,%s%x offset %d size %d(%s) cookie %x appendedAt %v",
+ *volumeId, n.Id, n.Cookie, offset, n.Size, util.BytesToHumanReadable(uint64(n.Size)), n.Cookie, t)
return nil
}
diff --git a/unmaintained/see_idx/see_idx.go b/unmaintained/see_idx/see_idx.go
index 777af1821..47cbd291b 100644
--- a/unmaintained/see_idx/see_idx.go
+++ b/unmaintained/see_idx/see_idx.go
@@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
+ "github.com/chrislusf/seaweedfs/weed/util"
"os"
"path"
"strconv"
@@ -36,7 +37,7 @@ func main() {
defer indexFile.Close()
idx.WalkIndexFile(indexFile, func(key types.NeedleId, offset types.Offset, size uint32) error {
- fmt.Printf("key:%v offset:%v size:%v\n", key, offset, size)
+ fmt.Printf("key:%v offset:%v size:%v(%v)\n", key, offset, size, util.BytesToHumanReadable(uint64(size)))
return nil
})
diff --git a/weed/server/volume_server_ui/templates.go b/weed/server/volume_server_ui/templates.go
index a3175e9ca..8705bc088 100644
--- a/weed/server/volume_server_ui/templates.go
+++ b/weed/server/volume_server_ui/templates.go
@@ -2,24 +2,12 @@ package master_ui
import (
"fmt"
+ "github.com/chrislusf/seaweedfs/weed/util"
"html/template"
"strconv"
"strings"
)
-func bytesToHumanReadble(b uint64) string {
- const unit = 1024
- if b < unit {
- return fmt.Sprintf("%d B", b)
- }
- div, exp := uint64(unit), 0
- for n := b / unit; n >= unit; n /= unit {
- div *= unit
- exp++
- }
- return fmt.Sprintf("%.2f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
-}
-
func percentFrom(total uint64, part_of uint64) string {
return fmt.Sprintf("%.2f", (float64(part_of)/float64(total))*100)
}
@@ -33,9 +21,9 @@ func join(data []int64) string {
}
var funcMap = template.FuncMap{
- "join": join,
- "bytesToHumanReadble": bytesToHumanReadble,
- "percentFrom": percentFrom,
+ "join": join,
+ "bytesToHumanReadable": util.BytesToHumanReadable,
+ "percentFrom": percentFrom,
}
var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOCTYPE html>
@@ -90,8 +78,8 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
{{ range .DiskStatuses }}
<tr>
<td>{{ .Dir }}</td>
- <td>{{ bytesToHumanReadble .All }}</td>
- <td>{{ bytesToHumanReadble .Free }}</td>
+ <td>{{ bytesToHumanReadable .All }}</td>
+ <td>{{ bytesToHumanReadable .Free }}</td>
<td>{{ percentFrom .All .Used}}%</td>
</tr>
{{ end }}
@@ -151,9 +139,9 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
<tr>
<td><code>{{ .Id }}</code></td>
<td>{{ .Collection }}</td>
- <td>{{ bytesToHumanReadble .Size }}</td>
+ <td>{{ bytesToHumanReadable .Size }}</td>
<td>{{ .FileCount }}</td>
- <td>{{ .DeleteCount }} / {{bytesToHumanReadble .DeletedByteCount}}</td>
+ <td>{{ .DeleteCount }} / {{bytesToHumanReadable .DeletedByteCount}}</td>
<td>{{ .Ttl }}</td>
<td>{{ .ReadOnly }}</td>
</tr>
@@ -181,9 +169,9 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
<tr>
<td><code>{{ .Id }}</code></td>
<td>{{ .Collection }}</td>
- <td>{{ bytesToHumanReadble .Size }}</td>
+ <td>{{ bytesToHumanReadable .Size }}</td>
<td>{{ .FileCount }}</td>
- <td>{{ .DeleteCount }} / {{bytesToHumanReadble .DeletedByteCount}}</td>
+ <td>{{ .DeleteCount }} / {{bytesToHumanReadable .DeletedByteCount}}</td>
<td>{{ .RemoteStorageName }}</td>
<td>{{ .RemoteStorageKey }}</td>
</tr>
@@ -209,7 +197,7 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
<tr>
<td><code>{{ .VolumeId }}</code></td>
<td>{{ .Collection }}</td>
- <td>{{ bytesToHumanReadble .ShardSize }}</td>
+ <td>{{ bytesToHumanReadable .ShardSize }}</td>
<td>{{ .ShardIdList }}</td>
<td>{{ .CreatedAt.Format "02 Jan 06 15:04 -0700" }}</td>
</tr>
diff --git a/weed/util/bytes.go b/weed/util/bytes.go
index d72d199f8..0650919c0 100644
--- a/weed/util/bytes.go
+++ b/weed/util/bytes.go
@@ -6,6 +6,22 @@ import (
"io"
)
+// BytesToHumanReadable returns the converted human readable representation of the bytes.
+func BytesToHumanReadable(b uint64) string {
+ const unit = 1024
+ if b < unit {
+ return fmt.Sprintf("%d B", b)
+ }
+
+ div, exp := uint64(unit), 0
+ for n := b / unit; n >= unit; n /= unit {
+ div *= unit
+ exp++
+ }
+
+ return fmt.Sprintf("%.2f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
+}
+
// big endian
func BytesToUint64(b []byte) (v uint64) {