Convert monitor command to use base.Command
This commit is contained in:
parent
7d72864531
commit
c78f62b83d
|
@ -1,19 +1,19 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/hashicorp/logutils"
|
||||
"github.com/mitchellh/cli"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/consul/command/base"
|
||||
)
|
||||
|
||||
// MonitorCommand is a Command implementation that queries a running
|
||||
// Consul agent what members are part of the cluster currently.
|
||||
type MonitorCommand struct {
|
||||
base.Command
|
||||
|
||||
ShutdownCh <-chan struct{}
|
||||
Ui cli.Ui
|
||||
|
||||
lock sync.Mutex
|
||||
quitting bool
|
||||
|
@ -29,40 +29,34 @@ Usage: consul monitor [options]
|
|||
example your agent may only be logging at INFO level, but with the monitor
|
||||
you can see the DEBUG level logs.
|
||||
|
||||
Options:
|
||||
` + c.Command.Help()
|
||||
|
||||
-log-level=info Log level of the agent.
|
||||
-rpc-addr=127.0.0.1:8400 RPC address of the Consul agent.
|
||||
`
|
||||
return strings.TrimSpace(helpText)
|
||||
}
|
||||
|
||||
func (c *MonitorCommand) Run(args []string) int {
|
||||
var logLevel string
|
||||
cmdFlags := flag.NewFlagSet("monitor", flag.ContinueOnError)
|
||||
cmdFlags.Usage = func() { c.Ui.Output(c.Help()) }
|
||||
cmdFlags.StringVar(&logLevel, "log-level", "INFO", "log level")
|
||||
rpcAddr := RPCAddrFlag(cmdFlags)
|
||||
if err := cmdFlags.Parse(args); err != nil {
|
||||
|
||||
f := c.Command.NewFlagSet(c)
|
||||
f.StringVar(&logLevel, "log-level", "INFO", "Log level of the agent.")
|
||||
|
||||
if err := c.Command.Parse(args); err != nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
client, err := RPCClient(*rpcAddr)
|
||||
client, err := c.Command.HTTPClient()
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
|
||||
return 1
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
logCh := make(chan string, 1024)
|
||||
monHandle, err := client.Monitor(logutils.LogLevel(logLevel), logCh)
|
||||
eventDoneCh := make(chan struct{})
|
||||
logCh, err := client.Agent().Monitor(logLevel, eventDoneCh, nil)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error starting monitor: %s", err))
|
||||
return 1
|
||||
}
|
||||
defer client.Stop(monHandle)
|
||||
|
||||
eventDoneCh := make(chan struct{})
|
||||
go func() {
|
||||
defer close(eventDoneCh)
|
||||
OUTER:
|
||||
|
|
|
@ -155,7 +155,10 @@ func init() {
|
|||
"monitor": func() (cli.Command, error) {
|
||||
return &command.MonitorCommand{
|
||||
ShutdownCh: makeShutdownCh(),
|
||||
Ui: ui,
|
||||
Command: base.Command{
|
||||
Flags: base.FlagSetClientHTTP,
|
||||
Ui: ui,
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
|
||||
|
|
|
@ -22,14 +22,13 @@ logs and watch the debug logs if necessary.
|
|||
|
||||
Usage: `consul monitor [options]`
|
||||
|
||||
The command-line flags are all optional. The list of available flags are:
|
||||
#### API Options
|
||||
|
||||
<%= partial "docs/commands/http_api_options_client" %>
|
||||
|
||||
#### Command Options
|
||||
|
||||
* `-log-level` - The log level of the messages to show. By default this
|
||||
is "info". This log level can be more verbose than what the agent is
|
||||
configured to run at. Available log levels are "trace", "debug", "info",
|
||||
"warn", and "err".
|
||||
|
||||
* `-rpc-addr` - Address to the RPC server of the agent you want to contact
|
||||
to send this command. If this isn't specified, the command checks the
|
||||
CONSUL_RPC_ADDR env variable. If this isn't set, the default RPC
|
||||
address will be set to "127.0.0.1:8400".
|
Loading…
Reference in New Issue