package agent
import "github.com/hashicorp/serf/command/agent"
Index ¶
- Constants
- Variables
- func LevelFilter() *logutils.LevelFilter
- func ValidateLevelFilter(filter *logutils.LevelFilter) bool
- type Agent
- func (a *Agent) Join(addrs []string, ignoreOld bool) (n int, err error)
- func (a *Agent) NotifyLogs(ch chan<- string) []string
- func (a *Agent) Serf() *serf.Serf
- func (a *Agent) Shutdown() error
- func (a *Agent) Start() error
- func (a *Agent) StopLogs(ch chan<- string)
- func (a *Agent) UserEvent(name string, payload []byte, coalesce bool) error
- type AgentState
- type AppendSliceValue
- type Command
- func (c *Command) Help() string
- func (c *Command) Run(args []string, rawUi cli.Ui) int
- func (c *Command) Synopsis() string
- type Config
- func DecodeConfig(r io.Reader) (*Config, error)
- func MergeConfig(a, b *Config) *Config
- func ReadConfigPaths(paths []string) (*Config, error)
- func (c *Config) BindAddrParts() (string, int, error)
- func (c *Config) EncryptBytes() ([]byte, error)
- func (c *Config) EventScripts() ([]EventScript, error)
- type EventHandler
- type EventScript
- func ParseEventScript(v string) ([]EventScript, error)
- func (s *EventScript) Invoke(e serf.Event) bool
- func (s *EventScript) String() string
- func (s *EventScript) Valid() bool
- type EventWriter
- type GatedWriter
- type MockEventHandler
- type RPCClient
- func (c *RPCClient) Close() error
- func (c *RPCClient) ForceLeave(node string) error
- func (c *RPCClient) Join(addrs []string, ignoreOld bool) (n int, err error)
- func (c *RPCClient) Members() ([]serf.Member, error)
- func (c *RPCClient) Monitor(level logutils.LogLevel, ch chan<- string, done <-chan struct{}) error
- func (c *RPCClient) UserEvent(name string, payload []byte, coalesce bool) error
- type RPCJoinArgs
- type RPCMonitorArgs
- type RPCUserEventArgs
- type ScriptEventHandler
Constants ¶
const DefaultBindPort int = 7946
This is the default port that we use for Serf communication
Variables ¶
var DefaultConfig = &Config{ BindAddr: "0.0.0.0", LogLevel: "INFO", RPCAddr: "127.0.0.1:7373", Protocol: serf.ProtocolVersionMax, }
DefaultConfig contains the defaults for configurations.
Functions ¶
func LevelFilter ¶
func LevelFilter() *logutils.LevelFilter
LevelFilter returns a LevelFilter that is configured with the log levels that we use.
func ValidateLevelFilter ¶
func ValidateLevelFilter(filter *logutils.LevelFilter) bool
ValidateLevelFilter verifies that the log levels within the filter are valid.
Types ¶
type Agent ¶
type Agent struct { // EventHandler is what is invoked when an event occurs. If this // isn't set, then events aren't handled in any special way. EventHandler EventHandler // LogOutput is where log messages are written to for the Agent, // Serf, and the underlying Memberlist. LogOutput io.Writer // RPCAddr is the address to bind the RPC listener to. RPCAddr string // SerfConfig is the configuration of Serf to use. Some settings // in here may be overriden by the agent. SerfConfig *serf.Config // contains filtered or unexported fields }
Agent starts and manages a Serf instance, adding some niceties on top of Serf such as storing logs that you can later retrieve, invoking and EventHandler when events occur, and putting an RPC layer in front so that you can query and control the Serf instance remotely.
func (*Agent) Join ¶
Join asks the Serf instance to join. See the Serf.Join function.
func (*Agent) NotifyLogs ¶
NotifyLogs causes the agent to begin sending log events to the given channel. The return value is a buffer of past events up to a point.
All NotifyLogs calls should be paired with a StopLogs call.
func (*Agent) Serf ¶
Returns the Serf agent of the running Agent.
func (*Agent) Shutdown ¶
Shutdown does a graceful shutdown of this agent and all of its processes.
func (*Agent) Start ¶
Start starts the agent, kicking off any goroutines to handle various aspects of the agent.
func (*Agent) StopLogs ¶
StopLogs causes the agent to stop sending logs to the given channel.
func (*Agent) UserEvent ¶
UserEvent sends a UserEvent on Serf, see Serf.UserEvent.
type AgentState ¶
type AgentState int
const ( AgentIdle AgentState = iota AgentRunning )
type AppendSliceValue ¶
type AppendSliceValue []string
AppendSliceValue implements the flag.Value interface and allows multiple calls to the same variable to append a list.
func (*AppendSliceValue) Set ¶
func (s *AppendSliceValue) Set(value string) error
func (*AppendSliceValue) String ¶
func (s *AppendSliceValue) String() string
type Command ¶
type Command struct { ShutdownCh <-chan struct{} // contains filtered or unexported fields }
Command is a Command implementation that runs a Serf agent. The command will not end unless a shutdown message is sent on the ShutdownCh. If two messages are sent on the ShutdownCh it will forcibly exit.
func (*Command) Help ¶
func (*Command) Run ¶
func (*Command) Synopsis ¶
type Config ¶
type Config struct { // All the configurations in this section are identical to their // Serf counterparts. See the documentation for Serf.Config for // more info. NodeName string `mapstructure:"node_name"` Role string `mapstructure:"role"` // BindAddr is the address that the Serf agent's communication ports // will bind to. Serf will use this address to bind to for both TCP // and UDP connections. If no port is present in the address, the default // port will be used. BindAddr string `mapstructure:"bind_addr"` // EncryptKey is the secret key to use for encrypting communication // traffic for Serf. The secret key must be exactly 16-bytes, base64 // encoded. The easiest way to do this on Unix machines is this command: // "head -c16 /dev/urandom | base64". If this is not specified, the // traffic will not be encrypted. EncryptKey string `mapstructure:"encrypt_key"` // LogLevel is the level of the logs to output. LogLevel string `mapstructure:"log_level"` // RPCAddr is the address and port to listen on for the agent's RPC // interface. RPCAddr string `mapstructure:"rpc_addr"` // Protocol is the Serf protocol version to use. Protocol int `mapstructure:"protocol"` // StartJoin is a list of addresses to attempt to join when the // agent starts. If Serf is unable to communicate with any of these // addresses, then the agent will error and exit. StartJoin []string `mapstructure:"start_join"` // EventHandlers is a list of event handlers that will be invoked. EventHandlers []string `mapstructure:"event_handlers"` }
Config is the configuration that can be set for an Agent. Some of these configurations are exposed as command-line flags to `serf agent`, whereas many of the more advanced configurations can only be set by creating a configuration file.
func DecodeConfig ¶
DecodeConfig reads the configuration from the given reader in JSON format and decodes it into a proper Config structure.
func MergeConfig ¶
MergeConfig merges two configurations together to make a single new configuration.
func ReadConfigPaths ¶
ReadConfigPaths reads the paths in the given order to load configurations. The paths can be to files or directories. If the path is a directory, we read one directory deep and read any files ending in ".json" as configuration files.
func (*Config) BindAddrParts ¶
BindAddrParts returns the parts of the BindAddr that should be used to configure Serf.
func (*Config) EncryptBytes ¶
EncryptBytes returns the encryption key configured.
func (*Config) EventScripts ¶
func (c *Config) EventScripts() ([]EventScript, error)
EventScripts returns the list of EventScripts associated with this configuration and specified by the "event_handlers" configuration.
type EventHandler ¶
EventHandler is a handler that does things when events happen.
type EventScript ¶
EventScript is a single event script that will be executed in the case of an event, and is configured from the command-line or from a configuration file.
func ParseEventScript ¶
func ParseEventScript(v string) ([]EventScript, error)
ParseEventScript takes a string in the format of "type=script" and parses it into an EventScript struct, if it can.
func (*EventScript) Invoke ¶
func (s *EventScript) Invoke(e serf.Event) bool
Invoke tests whether or not this event script should be invoked for the given Serf event.
func (*EventScript) String ¶
func (s *EventScript) String() string
func (*EventScript) Valid ¶
func (s *EventScript) Valid() bool
Valid checks if this is a valid agent event script.
type EventWriter ¶
type EventWriter struct { Agent *Agent }
EventWriter is an io.Writer that writes all of its output to the event log of an agent.
func (*EventWriter) Write ¶
func (w *EventWriter) Write(p []byte) (n int, err error)
type GatedWriter ¶
GatedWriter is an io.Writer implementation that buffers all of its data into an internal buffer until it is told to let data through.
func (*GatedWriter) Flush ¶
func (w *GatedWriter) Flush()
Flush tells the GatedWriter to flush any buffered data and to stop buffering.
func (*GatedWriter) Write ¶
func (w *GatedWriter) Write(p []byte) (n int, err error)
type MockEventHandler ¶
MockEventHandler is an EventHandler implementation that can be used for tests.
func (*MockEventHandler) HandleEvent ¶
type RPCClient ¶
RPCClient is the RPC client to make requests to the agent RPC.
func (*RPCClient) Close ¶
Close just closes the underlying RPC client.
func (*RPCClient) ForceLeave ¶
func (*RPCClient) Join ¶
func (*RPCClient) Members ¶
func (*RPCClient) Monitor ¶
func (*RPCClient) UserEvent ¶
type RPCJoinArgs ¶
RPCJoinArgs are the args for the Join RPC call.
type RPCMonitorArgs ¶
RPCMonitorArgs are the args for the Monitor RPC call.
type RPCUserEventArgs ¶
RPCUserEventArgs are the args for the user event RPC call.
type ScriptEventHandler ¶
type ScriptEventHandler struct { Self serf.Member Scripts []EventScript }
ScriptEventHandler invokes scripts for the events that it receives.
func (*ScriptEventHandler) HandleEvent ¶
Source Files ¶
agent.go command.go config.go event_handler.go event_handler_mock.go event_writer.go flag_slice_value.go gated_writer.go invoke.go log_levels.go rpc_client.go rpc_endpoint.go
- Version
- v0.2.0
- Published
- Nov 1, 2013
- Platform
- js/wasm
- Imports
- 22 packages
- Last checked
- 3 weeks ago –
Tools for package owners.