Documentation ¶
Overview ¶
Package agent is the running Sensu agent. Agents connect to a Sensu backend, register their presence, subscribe to check channels, download relevant check packages, execute checks, and send results to the Sensu backend via the Event channel.
Package agent is the running Sensu agent. Agents connect to a Sensu backend, register their presence, subscribe to check channels, download relevant check packages, execute checks, and send results to the Sensu backend via the Event channel.
Index ¶
- Constants
- func GetDefaultAgentName() string
- func NewClientFromViper(v *viper.Viper, a *Agent) (gostatsd.Backend, error)
- func NewServer() *statsd.Server
- func NewStatsdServer(a *Agent) *statsd.Server
- func TestEnvVars(t *testing.T)
- func TokenSubstitution(data, input interface{}) ([]byte, error)
- type APIConfig
- type Agent
- func (a *Agent) Connected() bool
- func (a *Agent) ExecuteHooks(request *types.CheckRequest, status int) []*types.Hook
- func (a *Agent) Run(ctx context.Context) error
- func (a *Agent) StartAPI(ctx context.Context)
- func (a *Agent) StartSocketListeners(ctx context.Context)
- func (a *Agent) StartStatsd(ctx context.Context)
- type BackendSelector
- type Client
- type Config
- type RandomBackendSelector
- type SocketConfig
- type StatsdServerConfig
- type Transformer
Constants ¶
const ( // MaxMessageBufferSize specifies the maximum number of messages of a given // type that an agent will queue before rejecting messages. MaxMessageBufferSize = 10 // TCPSocketReadDeadline specifies the maximum time the TCP socket will wait // to receive data. TCPSocketReadDeadline = 500 * time.Millisecond // DefaultAPIHost specifies the default API Host DefaultAPIHost = "127.0.0.1" // DefaultAPIPort specifies the default API Port DefaultAPIPort = 3031 // DefaultBackendURL specifies the default backend URL DefaultBackendURL = "ws://127.0.0.1:8081" // DefaultEventsAPIRateLimit defines the rate limit, in events per second, // for outgoing events. DefaultEventsAPIRateLimit rate.Limit = 10.0 // DefaultEventsAPIBurstLimit defines the burst ceiling for a rate limited // events API. If DefaultEventsAPIRateLimit is 0, then the setting has no // effect. DefaultEventsAPIBurstLimit int = 10 // DefaultKeepaliveInterval specifies the default keepalive interval DefaultKeepaliveInterval = 20 // DefaultNamespace specifies the default namespace DefaultNamespace = "default" // DefaultPassword specifies the default password DefaultPassword = "P@ssw0rd!" // DefaultSocketHost specifies the default socket host DefaultSocketHost = "127.0.0.1" // DefaultSocketPort specifies the default socket port DefaultSocketPort = 3030 // DefaultStatsdDisable specifies if the statsd listener is disabled DefaultStatsdDisable = false // DefaultStatsdFlushInterval specifies the default flush interval for statsd DefaultStatsdFlushInterval = 10 // DefaultStatsdMetricsHost specifies the default metrics host for statsd server DefaultStatsdMetricsHost = "127.0.0.1" // DefaultStatsdMetricsPort specifies the default metrics port for statsd server DefaultStatsdMetricsPort = 8125 // DefaultSystemInfoRefreshInterval specifies the default refresh interval // (in seconds) for the agent's cached system information. DefaultSystemInfoRefreshInterval = 20 // DefaultUser specifies the default user DefaultUser = "agent" )
const BackendName = "sensu-statsd"
BackendName is the name of this statsd backend.
Variables ¶
This section is empty.
Functions ¶
func GetDefaultAgentName ¶
func GetDefaultAgentName() string
GetDefaultAgentName returns the default agent name
func NewClientFromViper ¶
NewClientFromViper constructs a sensu-statsd backend.
func NewStatsdServer ¶
NewStatsdServer provides a new statsd server for the sensu-agent.
func TestEnvVars ¶
func TokenSubstitution ¶
TokenSubstitution evaluates the input template, that possibly contains tokens, with the provided data object and returns a slice of bytes representing the result along with any error encountered
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
An Agent receives and acts on messages from a Sensu Backend.
func NewAgent ¶
NewAgent creates a new Agent. It returns non-nil error if there is any error when creating the config.CacheDir.
func (*Agent) ExecuteHooks ¶
ExecuteHooks executes all hooks contained in a check request based on the check status code of the check request
func (*Agent) Run ¶
Run starts the Agent.
1. Start the asset manager. 2. Start a statsd server on the agent and logs the received metrics. 3. Connect to the backend, return an error if unsuccessful. 4. Start the socket listeners, return an error if unsuccessful. 5. Start the send/receive pumps. 6. Issue a keepalive immediately. 7. Start refreshing system info periodically. 8. Start sending periodic keepalives. 9. Start the API server, shutdown the agent if doing so fails.
func (*Agent) StartAPI ¶
StartAPI starts the Agent HTTP API. After attempting to start the API, if the HTTP server encounters a fatal error, it will shutdown the rest of the agent.
func (*Agent) StartSocketListeners ¶
StartSocketListeners starts the agent's TCP and UDP socket listeners. Agent TCP/UDP sockets are deprecated in favor of the agent rest api.
func (*Agent) StartStatsd ¶
StartStatsd starts up a StatsD listener on the agent, logs an error for any failures.
type BackendSelector ¶
type BackendSelector interface { // Select returns an appropriate backend given the selection strategy for // the selector. Select() string }
A BackendSelector is repsonsible for selecting an appropriate backend from a provided list of backends.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an object that is used to send messages to sensu-statsd.
func (Client) SendEvent ¶
SendEvent sends event to the statsd backend which resides on the sensu-agent, not to be confused with the sensu-backend.
func (Client) SendMetricsAsync ¶
func (c Client) SendMetricsAsync(ctx context.Context, metrics *gostatsd.MetricMap, cb gostatsd.SendCallback)
SendMetricsAsync flushes the metrics to the statsd backend which resides on the sensu-agent, preparing payload synchronously but doing the send asynchronously. Must not read/write MetricMap asynchronously.
type Config ¶
type Config struct { // AgentName is the entity name for the running agent. Default is hostname. AgentName string // API contains the Sensu client HTTP API configuration API *APIConfig // BackendURLs is a list of URLs for the Sensu Backend. Default: // ws://127.0.0.1:8081 BackendURLs []string // CacheDir path where cached data is stored CacheDir string // Deregister indicates whether the entity is ephemeral Deregister bool // DeregistrationHandler specifies a single deregistration handler DeregistrationHandler string // DisableAPI disables the events API DisableAPI bool // DisableSockets disables the event sockets DisableSockets bool // EventsAPIRateLimit is the maximum number of events per second that will // be transmitted to the backend from the events API EventsAPIRateLimit rate.Limit // EventsAPIBurstLimit is the maximum amount of burst allowed in a rate // interval. EventsAPIBurstLimit int // KeepaliveInterval is the interval between keepalive events. KeepaliveInterval uint32 // KeepaliveTimeout is the time after which a sensu-agent is considered dead // by the backend. See DefaultKeepaliveTimeout in types package for default // value. KeepaliveTimeout uint32 // Labels are key-value pairs that users can provide to agent entities Labels map[string]string // Annotations are key-value pairs that users can provide to agent entities Annotations map[string]string // Namespace sets the Agent's RBAC namespace identifier Namespace string // Password sets Agent's password Password string // Redact contains the fields to redact when marshalling the agent's entity Redact []string // Socket contains the Sensu client socket configuration Socket *SocketConfig // StatsdServer contains the statsd server configuration StatsdServer *StatsdServerConfig // Subscriptions is an array of subscription names. Default: empty array. Subscriptions []string // TLS sets the TLSConfig for agent TLS options TLS *types.TLSOptions // User sets the Agent's username User string }
A Config specifies Agent configuration.
func FixtureConfig ¶
func FixtureConfig() (*Config, func())
FixtureConfig provides a new Config object initialized with defaults for use in tests, as well as a cleanup function to call at the end of the test.
type RandomBackendSelector ¶
type RandomBackendSelector struct { // Backends is the list of backend URLs to shuffle through. Backends []string // contains filtered or unexported fields }
A RandomBackendSelector does a single random shuffle of a list of backends and perpetually returns them in the shuffled order.
RandomBackendSelector is not guaranteed to maintain shuffle order if used by multiple goroutines concurrently.
func (*RandomBackendSelector) Select ¶
func (b *RandomBackendSelector) Select() string
Select returns the next random backend.
type SocketConfig ¶
SocketConfig contains the Socket configuration
type StatsdServerConfig ¶
type StatsdServerConfig struct { Host string Port int FlushInterval int Handlers []string Disable bool }
StatsdServerConfig contains the statsd server configuration
type Transformer ¶
type Transformer interface { // Transform transforms a metric in a different output metric format to Sensu Metric // Format Transform() []*types.MetricPoint }
A Transformer handles transforming Sensu metrics to other output metric formats