mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add Volume Ids column only for max 100 volumes for convenience in the master ui.
This commit is contained in:
parent
b4e93b639d
commit
1a642b9876
|
@ -76,6 +76,7 @@ var StatusTpl = template.Must(template.New("status").Parse(`<!DOCTYPE html>
|
|||
<th>Rack</th>
|
||||
<th>RemoteAddr</th>
|
||||
<th>#Volumes</th>
|
||||
<th>Volume Ids</th>
|
||||
<th>#ErasureCodingShards</th>
|
||||
<th>Max</th>
|
||||
</tr>
|
||||
|
@ -89,6 +90,7 @@ var StatusTpl = template.Must(template.New("status").Parse(`<!DOCTYPE html>
|
|||
<td>{{ $rack.Id }}</td>
|
||||
<td><a href="http://{{ $dn.Url }}/ui/index.html">{{ $dn.Url }}</a></td>
|
||||
<td>{{ $dn.Volumes }}</td>
|
||||
<td>{{ $dn.VolumeIds}}</td>
|
||||
<td>{{ $dn.EcShards }}</td>
|
||||
<td>{{ $dn.Max }}</td>
|
||||
</tr>
|
||||
|
|
|
@ -2,6 +2,7 @@ package topology
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
|
@ -166,6 +167,7 @@ func (dn *DataNode) ToMap() interface{} {
|
|||
ret := make(map[string]interface{})
|
||||
ret["Url"] = dn.Url()
|
||||
ret["Volumes"] = dn.GetVolumeCount()
|
||||
ret["VolumeIds"] = dn.GetVolumeIds()
|
||||
ret["EcShards"] = dn.GetEcShardCount()
|
||||
ret["Max"] = dn.GetMaxVolumeCount()
|
||||
ret["Free"] = dn.FreeSpace()
|
||||
|
@ -190,3 +192,19 @@ func (dn *DataNode) ToDataNodeInfo() *master_pb.DataNodeInfo {
|
|||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// GetVolumeIds returns the human readable volume ids limited to count of max 100.
|
||||
func (dn *DataNode) GetVolumeIds() string {
|
||||
volumesLen := len(dn.volumes)
|
||||
if volumesLen > 100 {
|
||||
return "..."
|
||||
}
|
||||
|
||||
ids := make([]int, 0, volumesLen)
|
||||
|
||||
for k := range dn.volumes {
|
||||
ids = append(ids, int(k))
|
||||
}
|
||||
|
||||
return util.HumanReadableInts(ids...)
|
||||
}
|
||||
|
|
43
weed/util/inits.go
Normal file
43
weed/util/inits.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// HumanReadableInts joins a serials of inits into a smart one like 1-3 5 7-10 for human readable.
|
||||
func HumanReadableInts(ids ...int) string {
|
||||
sort.Ints(ids)
|
||||
|
||||
s := ""
|
||||
start := 0
|
||||
last := 0
|
||||
|
||||
for i, v := range ids {
|
||||
if i == 0 {
|
||||
start = v
|
||||
last = v
|
||||
s = fmt.Sprintf("%d", v)
|
||||
continue
|
||||
}
|
||||
|
||||
if last+1 == v {
|
||||
last = v
|
||||
continue
|
||||
}
|
||||
|
||||
if last > start {
|
||||
s += fmt.Sprintf("-%d", last)
|
||||
}
|
||||
|
||||
s += fmt.Sprintf(" %d", v)
|
||||
start = v
|
||||
last = v
|
||||
}
|
||||
|
||||
if last != start {
|
||||
s += fmt.Sprintf("-%d", last)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
14
weed/util/inits_test.go
Normal file
14
weed/util/inits_test.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHumanReadableInts(t *testing.T) {
|
||||
assert.Equal(t, "1-3", HumanReadableInts(1, 2, 3))
|
||||
assert.Equal(t, "1 3", HumanReadableInts(1, 3))
|
||||
assert.Equal(t, "1 3 5", HumanReadableInts(5, 1, 3))
|
||||
assert.Equal(t, "1-3 5", HumanReadableInts(1, 2, 3, 5))
|
||||
assert.Equal(t, "1-3 5 7-9", HumanReadableInts(7, 9, 8, 1, 2, 3, 5))
|
||||
}
|
Loading…
Reference in a new issue