forked from bblfsh/bblfshd
/
status.go
62 lines (50 loc) · 1.6 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package cmd
import (
"context"
"fmt"
"os"
"strings"
"github.com/bblfsh/bblfshd/daemon/protocol"
"github.com/olekukonko/tablewriter"
)
const (
StatusCommandDescription = "List all the pools of driver instances running"
StatusCommandHelp = StatusCommandDescription + "\n\n" +
"The drivers are started on-demand based on the load of the server, \n" +
"this driver instances are organized in pools by language.\n\n" +
"This command prints a list of the pools running on the daemon, with \n" +
"the number of requests success and failed, the number of instances \n" +
"current and desired, the number of request waiting to be handle and \n" +
"the drivers existed with with a non-zero code."
)
type StatusCommand struct {
ControlCommand
}
func (c *StatusCommand) Execute(args []string) error {
if err := c.ControlCommand.Execute(nil); err != nil {
return err
}
r, err := c.srv.DriverPoolStates(context.Background(), &protocol.DriverPoolStatesRequest{})
if err != nil {
return err
}
if err == nil && len(r.Errors) == 0 {
daemonStatusToText(r)
return nil
}
return err
}
func daemonStatusToText(r *protocol.DriverPoolStatesResponse) {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Language", "Success/Failed", "State/Desired", "Waiting", "Exited"})
table.SetAlignment(tablewriter.ALIGN_LEFT)
for language, s := range r.State {
line := fmt.Sprintf("%s\t%d/%d\t%d/%d\t%d\t%d", language,
s.Success, s.Errors,
s.Running, s.Wanted, s.Waiting, s.Exited,
)
table.Append(strings.Split(line, "\t"))
}
table.Render()
fmt.Printf("Response time %s\n", r.Elapsed)
}