mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-19 19:19:22 +08:00
util.BytesToHumanReadable
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
@@ -31,7 +32,9 @@ func (scanner *VolumeFileScanner4SeeDat) ReadNeedleBody() bool {
|
|||||||
|
|
||||||
func (scanner *VolumeFileScanner4SeeDat) VisitNeedle(n *needle.Needle, offset int64, needleHeader, needleBody []byte) error {
|
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))
|
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)
|
// I0529 09:56:30 12560 see_dat.go:35] 4,17f03026 offset 8 size 17214(16.81 KiB) cookie 7f03026 appendedAt 2020-05-28 10:39:56.19197 +0800 CST
|
||||||
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -36,7 +37,8 @@ func main() {
|
|||||||
defer indexFile.Close()
|
defer indexFile.Close()
|
||||||
|
|
||||||
idx.WalkIndexFile(indexFile, func(key types.NeedleId, offset types.Offset, size uint32) error {
|
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)
|
// key:1 offset:1 size:17214(16.81 KiB)
|
||||||
|
fmt.Printf("key:%v offset:%v size:%v(%v)\n", key, offset, size, util.BytesToHumanReadable(uint64(size)))
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -2,24 +2,12 @@ package master_ui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"html/template"
|
"html/template"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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 {
|
func percentFrom(total uint64, part_of uint64) string {
|
||||||
return fmt.Sprintf("%.2f", (float64(part_of)/float64(total))*100)
|
return fmt.Sprintf("%.2f", (float64(part_of)/float64(total))*100)
|
||||||
}
|
}
|
||||||
@@ -33,9 +21,9 @@ func join(data []int64) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var funcMap = template.FuncMap{
|
var funcMap = template.FuncMap{
|
||||||
"join": join,
|
"join": join,
|
||||||
"bytesToHumanReadble": bytesToHumanReadble,
|
"bytesToHumanReadable": util.BytesToHumanReadable,
|
||||||
"percentFrom": percentFrom,
|
"percentFrom": percentFrom,
|
||||||
}
|
}
|
||||||
|
|
||||||
var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOCTYPE html>
|
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 }}
|
{{ range .DiskStatuses }}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ .Dir }}</td>
|
<td>{{ .Dir }}</td>
|
||||||
<td>{{ bytesToHumanReadble .All }}</td>
|
<td>{{ bytesToHumanReadable .All }}</td>
|
||||||
<td>{{ bytesToHumanReadble .Free }}</td>
|
<td>{{ bytesToHumanReadable .Free }}</td>
|
||||||
<td>{{ percentFrom .All .Used}}%</td>
|
<td>{{ percentFrom .All .Used}}%</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@@ -151,9 +139,9 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
|
|||||||
<tr>
|
<tr>
|
||||||
<td><code>{{ .Id }}</code></td>
|
<td><code>{{ .Id }}</code></td>
|
||||||
<td>{{ .Collection }}</td>
|
<td>{{ .Collection }}</td>
|
||||||
<td>{{ bytesToHumanReadble .Size }}</td>
|
<td>{{ bytesToHumanReadable .Size }}</td>
|
||||||
<td>{{ .FileCount }}</td>
|
<td>{{ .FileCount }}</td>
|
||||||
<td>{{ .DeleteCount }} / {{bytesToHumanReadble .DeletedByteCount}}</td>
|
<td>{{ .DeleteCount }} / {{bytesToHumanReadable .DeletedByteCount}}</td>
|
||||||
<td>{{ .Ttl }}</td>
|
<td>{{ .Ttl }}</td>
|
||||||
<td>{{ .ReadOnly }}</td>
|
<td>{{ .ReadOnly }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -181,9 +169,9 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
|
|||||||
<tr>
|
<tr>
|
||||||
<td><code>{{ .Id }}</code></td>
|
<td><code>{{ .Id }}</code></td>
|
||||||
<td>{{ .Collection }}</td>
|
<td>{{ .Collection }}</td>
|
||||||
<td>{{ bytesToHumanReadble .Size }}</td>
|
<td>{{ bytesToHumanReadable .Size }}</td>
|
||||||
<td>{{ .FileCount }}</td>
|
<td>{{ .FileCount }}</td>
|
||||||
<td>{{ .DeleteCount }} / {{bytesToHumanReadble .DeletedByteCount}}</td>
|
<td>{{ .DeleteCount }} / {{bytesToHumanReadable .DeletedByteCount}}</td>
|
||||||
<td>{{ .RemoteStorageName }}</td>
|
<td>{{ .RemoteStorageName }}</td>
|
||||||
<td>{{ .RemoteStorageKey }}</td>
|
<td>{{ .RemoteStorageKey }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -209,7 +197,7 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
|
|||||||
<tr>
|
<tr>
|
||||||
<td><code>{{ .VolumeId }}</code></td>
|
<td><code>{{ .VolumeId }}</code></td>
|
||||||
<td>{{ .Collection }}</td>
|
<td>{{ .Collection }}</td>
|
||||||
<td>{{ bytesToHumanReadble .ShardSize }}</td>
|
<td>{{ bytesToHumanReadable .ShardSize }}</td>
|
||||||
<td>{{ .ShardIdList }}</td>
|
<td>{{ .ShardIdList }}</td>
|
||||||
<td>{{ .CreatedAt.Format "02 Jan 06 15:04 -0700" }}</td>
|
<td>{{ .CreatedAt.Format "02 Jan 06 15:04 -0700" }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@@ -6,6 +6,22 @@ import (
|
|||||||
"io"
|
"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
|
// big endian
|
||||||
|
|
||||||
func BytesToUint64(b []byte) (v uint64) {
|
func BytesToUint64(b []byte) (v uint64) {
|
||||||
|
Reference in New Issue
Block a user