Skip to content

Commit

Permalink
Merge pull request #1257 from ploubser/issue_1239
Browse files Browse the repository at this point in the history
(#1239) Add totals row to `server report health` command
  • Loading branch information
ripienaar authored Jan 27, 2025
2 parents 444f711 + d471ca2 commit 2b7c75c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cli/server_report_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ func (c *SrvReportCmd) reportHealth(_ *fisk.ParseContext) error {
tbl := iu.NewTableWriter(opts(), "Health Report")
tbl.AddHeaders("Server", "Cluster", "Domain", "Status", "Type", "Error")

var ok, notok, totalErrors int
totalClusters := map[string]struct{}{}

for _, srv := range servers {
tbl.AddRow(
srv.Server.Name,
Expand All @@ -198,11 +201,21 @@ func (c *SrvReportCmd) reportHealth(_ *fisk.ParseContext) error {
fmt.Sprintf("%s (%d)", srv.Data.Status, srv.Data.StatusCode),
)

if srv.Data.StatusCode == 200 {
ok += 1
} else {
notok += 1
}

totalClusters[srv.Server.Cluster] = struct{}{}

ecnt := len(srv.Data.Errors)
if ecnt == 0 {
continue
}

totalErrors += ecnt

show := ecnt
if ecnt > 10 {
show = 9
Expand All @@ -220,6 +233,9 @@ func (c *SrvReportCmd) reportHealth(_ *fisk.ParseContext) error {
}
}

//tbl.AddSeparator()
tbl.AddFooter(f(len(servers)), f(len(totalClusters)), "", f(fmt.Sprintf("ok: %d / err: %d", ok, notok)), "", f(totalErrors))

fmt.Println(tbl.Render())

return nil
Expand Down

0 comments on commit 2b7c75c

Please sign in to comment.