github.com/jmitchell/nomad@v0.1.3-0.20151007230021-7ab84c2862d8/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  	return strings.TrimSpace(helpText)
    34  }
    35  
    36  func (c *EvalMonitorCommand) Synopsis() string {
    37  	return "Monitor an evaluation interactively"
    38  }
    39  
    40  func (c *EvalMonitorCommand) Run(args []string) int {
    41  	flags := c.Meta.FlagSet("eval-monitor", FlagSetClient)
    42  	flags.Usage = func() { c.Ui.Output(c.Help()) }
    43  	if err := flags.Parse(args); err != nil {
    44  		return 1
    45  	}
    46  
    47  	// Check that we got exactly one eval ID
    48  	args = flags.Args()
    49  	if len(args) != 1 {
    50  		c.Ui.Error(c.Help())
    51  		return 1
    52  	}
    53  	evalID := args[0]
    54  
    55  	// Get the HTTP client
    56  	client, err := c.Meta.Client()
    57  	if err != nil {
    58  		c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
    59  		return 1
    60  	}
    61  
    62  	// Start monitoring
    63  	mon := newMonitor(c.Ui, client)
    64  	return mon.monitor(evalID)
    65  }