github.com/ryanslade/nomad@v0.2.4-0.20160128061903-fc95782f2089/command/eval_monitor.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 type EvalMonitorCommand struct { 9 Meta 10 } 11 12 func (c *EvalMonitorCommand) Help() string { 13 helpText := ` 14 Usage: nomad eval-monitor [options] <evaluation> 15 16 Start an interactive monitoring session for an existing evaluation. 17 The monitor command periodically polls for information about the 18 provided evaluation, including status updates, new allocations, 19 updates to allocations, and failures. Status is printed in near 20 real-time to the terminal. 21 22 The command will exit when the given evaluation reaches a terminal 23 state (completed or failed). Exit code 0 is returned on successful 24 evaluation, and if there are no scheduling problems. If there are 25 job placement issues encountered (unsatisfiable constraints, 26 resource exhaustion, etc), then the exit code will be 2. Any other 27 errors, including client connection issues or internal errors, are 28 indicated by exit code 1. 29 30 General Options: 31 32 ` + generalOptionsUsage() + ` 33 34 Eval Monitor Options: 35 36 -verbose 37 Show full information. 38 ` 39 return strings.TrimSpace(helpText) 40 } 41 42 func (c *EvalMonitorCommand) Synopsis() string { 43 return "Monitor an evaluation interactively" 44 } 45 46 func (c *EvalMonitorCommand) Run(args []string) int { 47 var verbose bool 48 49 flags := c.Meta.FlagSet("eval-monitor", FlagSetClient) 50 flags.Usage = func() { c.Ui.Output(c.Help()) } 51 flags.BoolVar(&verbose, "verbose", false, "") 52 53 if err := flags.Parse(args); err != nil { 54 return 1 55 } 56 57 // Truncate the id unless full length is requested 58 length := shortId 59 if verbose { 60 length = fullId 61 } 62 63 // Check that we got exactly one eval ID 64 args = flags.Args() 65 if len(args) != 1 { 66 c.Ui.Error(c.Help()) 67 return 1 68 } 69 evalID := args[0] 70 71 // Get the HTTP client 72 client, err := c.Meta.Client() 73 if err != nil { 74 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 75 return 1 76 } 77 78 // Start monitoring 79 mon := newMonitor(c.Ui, client, length) 80 return mon.monitor(evalID, true) 81 }