Fix showing data usage indicators
This commit is contained in:
parent
4880d31120
commit
2b1fb662fb
|
@ -24,6 +24,18 @@ func formatSpeed(speed float64) string {
|
||||||
return fmt.Sprintf("%.2f Tbit/s", float32(speed)/(1000*1000*1000))
|
return fmt.Sprintf("%.2f Tbit/s", float32(speed)/(1000*1000*1000))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func formatSize(size float64) string {
|
||||||
|
if size < 1024 {
|
||||||
|
return fmt.Sprintf("%.1fK", size)
|
||||||
|
} else if size < 1024*1024 {
|
||||||
|
return fmt.Sprintf("%.1fM", size/1024.0)
|
||||||
|
} else if size < 1024*1024*1024 {
|
||||||
|
return fmt.Sprintf("%.1fG", size/(1024.0*1024.0))
|
||||||
|
}
|
||||||
|
// WTF, you crazy?
|
||||||
|
return fmt.Sprintf("%.1fT", size/(1024*1024*1024))
|
||||||
|
}
|
||||||
|
|
||||||
var summarizers = map[string]func(uint64, uint64, string) []string{
|
var summarizers = map[string]func(uint64, uint64, string) []string{
|
||||||
"websites": func(totalCount uint64, anomalyCount uint64, ss string) []string {
|
"websites": func(totalCount uint64, anomalyCount uint64, ss string) []string {
|
||||||
return []string{
|
return []string{
|
||||||
|
@ -102,9 +114,7 @@ func logResultItem(w io.Writer, f log.Fields) error {
|
||||||
util.RightPad(summary[2], colWidth)))
|
util.RightPad(summary[2], colWidth)))
|
||||||
|
|
||||||
if index == totalCount-1 {
|
if index == totalCount-1 {
|
||||||
fmt.Fprintf(w, "└┬──────────────┬──────────────┬──────────────┬")
|
fmt.Fprintf(w, "└┬──────────────┬──────────────┬──────────────────┬┘\n")
|
||||||
fmt.Fprintf(w, strings.Repeat("─", colWidth*2-44))
|
|
||||||
fmt.Fprintf(w, "┘\n")
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -125,8 +135,8 @@ func logResultSummary(w io.Writer, f log.Fields) error {
|
||||||
fmt.Fprintf(w, " │ %s │ %s │ %s │\n",
|
fmt.Fprintf(w, " │ %s │ %s │ %s │\n",
|
||||||
util.RightPad(fmt.Sprintf("%d tests", tests), 12),
|
util.RightPad(fmt.Sprintf("%d tests", tests), 12),
|
||||||
util.RightPad(fmt.Sprintf("%d nets", networks), 12),
|
util.RightPad(fmt.Sprintf("%d nets", networks), 12),
|
||||||
util.RightPad(fmt.Sprintf("%.0f ⬆ %.0f ⬇", dataUp, dataDown), 12))
|
util.RightPad(fmt.Sprintf("⬆ %s ⬇ %s", formatSize(dataUp), formatSize(dataDown)), 16))
|
||||||
fmt.Fprintf(w, " └──────────────┴──────────────┴──────────────┘\n")
|
fmt.Fprintf(w, " └──────────────┴──────────────┴──────────────────┘\n")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,11 @@ func EscapeAwareRuneCountInString(s string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RightPad(str string, length int) string {
|
func RightPad(str string, length int) string {
|
||||||
return str + strings.Repeat(" ", length-EscapeAwareRuneCountInString(str))
|
c := length - EscapeAwareRuneCountInString(str)
|
||||||
|
if c < 0 {
|
||||||
|
c = 0
|
||||||
|
}
|
||||||
|
return str + strings.Repeat(" ", c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WrapString wraps the given string within lim width in characters.
|
// WrapString wraps the given string within lim width in characters.
|
||||||
|
|
|
@ -286,7 +286,7 @@ func (c *Controller) Init(nt *mk.Nettest) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
c.res.DataUsageDown += e.Value.DownloadedKB
|
c.res.DataUsageDown += e.Value.DownloadedKB
|
||||||
c.res.DataUsageDown += e.Value.UploadedKB
|
c.res.DataUsageUp += e.Value.UploadedKB
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Debugf("Registered all the handlers")
|
log.Debugf("Registered all the handlers")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user