Skip to content

Commit

Permalink
cleanup sidekick proxy, ui functions (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored May 7, 2020
1 parent 6df3097 commit f2f4a34
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 167 deletions.
68 changes: 0 additions & 68 deletions http-tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import (
"time"

"github.com/dustin/go-humanize"
ui "github.com/gizak/termui/v3"

"github.com/gizak/termui/v3/widgets"

"github.com/minio/minio/pkg/console"
"github.com/minio/minio/pkg/handlers"
Expand Down Expand Up @@ -367,71 +364,6 @@ type shortTraceMsg struct {
Query string `json:"query"`
}

func initTermTable(backends []*Backend) *widgets.Table {
table := widgets.NewTable()
table.TextStyle = ui.NewStyle(ui.ColorWhite)
table.SetRect(0, 0, 140, 11)
table.Rows = make([][]string, len(backends)+1)
maxEndpointWidth := 0
table.Rows[0] =
[]string{"Host", "Status", "TotCalls", "TotFailures", "Rx", "Tx", "Tot Downtime", "Last Downtime", "Min Latency", "Max Latency"}
for i, b := range backends {
row := []string{
b.endpoint,
b.getServerStatus(),
strconv.FormatInt(b.Stats.TotCalls, 10),
strconv.FormatInt(b.Stats.TotCallFailures, 10),
humanize.IBytes(uint64(b.Stats.Rx)),
humanize.IBytes(uint64(b.Stats.Tx)),
b.Stats.CumDowntime.Round(time.Microsecond).String(),
b.Stats.LastDowntime.Round(time.Microsecond).String(),
"Calculating...",
"Calculating..."}
table.Rows[i+1] = row
if len(b.endpoint) > maxEndpointWidth {
maxEndpointWidth = len(b.endpoint)
}
}
table.ColumnWidths = []int{maxEndpointWidth + 2, 7, 10, 12, 10, 10, 15, 15, 15, 15}
table.FillRow = true
table.BorderStyle = ui.NewStyle(ui.ColorGreen)

table.RowSeparator = true
ui.Render(table)
return table
}
func termTrace(backends []*Backend, t *widgets.Table) {
idx := 0
t.Rows[idx] =
[]string{"Host", "Status", "TotCalls", "TotFailures", "Rx", "Tx", "Tot Downtime", "Last Downtime", "Min Latency", "Max Latency"}
idx++
for _, b := range backends {
b.Stats.Lock()
defer b.Stats.Unlock()
minLatency := "Calculating..."
maxLatency := "Calculating..."
if b.Stats.MaxLatency > 0 {
minLatency = fmt.Sprintf("%2s", b.Stats.MinLatency.Round(time.Microsecond))
maxLatency = fmt.Sprintf("%2s", b.Stats.MaxLatency.Round(time.Microsecond))
}
row := []string{
b.endpoint,
b.getServerStatus(),
strconv.FormatInt(b.Stats.TotCalls, 10),
strconv.FormatInt(b.Stats.TotCallFailures, 10),
humanize.IBytes(uint64(b.Stats.Rx)),
humanize.IBytes(uint64(b.Stats.Tx)),
b.Stats.CumDowntime.String(),
b.Stats.LastDowntime.String(),
minLatency,
maxLatency}

t.Rows[idx] = row
idx++
}
ui.Render(t)
}

func (s shortTraceMsg) String() string {
var b = &strings.Builder{}
fmt.Fprintf(b, " %5s: ", TraceMsgType)
Expand Down
Loading

0 comments on commit f2f4a34

Please sign in to comment.