From e5eb863e273a21adf502cf9d7a16d51986cbc4db Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Thu, 16 Jun 2016 17:34:09 -0700 Subject: [PATCH 1/3] Whitespace police --- command/check.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command/check.go b/command/check.go index ce54b2717..d1f97a73d 100644 --- a/command/check.go +++ b/command/check.go @@ -22,7 +22,7 @@ type AgentCheckCommand struct { func (c *AgentCheckCommand) Help() string { helpText := ` Usage: nomad check - + Display state of the Nomad agent. The exit code of the command is Nagios compatible and could be used with alerting systems. @@ -31,7 +31,7 @@ General Options: ` + generalOptionsUsage() + ` Agent Check Options: - + -min-peers Minimum number of peers that a server is expected to know. From 6035dbfbe48f8d1e17e4427a23beddd611e36a85 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Thu, 16 Jun 2016 17:34:25 -0700 Subject: [PATCH 2/3] Automatically register service checks for HTTP, RPC, and Serf. --- command/agent/agent.go | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/command/agent/agent.go b/command/agent/agent.go index cac832d53..362f6cbb6 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -21,6 +21,19 @@ import ( "github.com/hashicorp/nomad/nomad/structs" ) +const ( + clientHttpCheckInterval = 10 * time.Second + clientHttpCheckTimeout = 3 * time.Second + clientRpcCheckInterval = 10 * time.Second + clientRpcCheckTimeout = 3 * time.Second + serverHttpCheckInterval = 10 * time.Second + serverHttpCheckTimeout = 3 * time.Second + serverRpcCheckInterval = 10 * time.Second + serverRpcCheckTimeout = 3 * time.Second + serverSerfCheckInterval = 10 * time.Second + serverSerfCheckTimeout = 3 * time.Second +) + // Agent is a long running daemon that is used to run both // clients and servers. Servers are responsible for managing // state and making scheduling decisions. Clients can be @@ -390,16 +403,42 @@ func (a *Agent) setupServer() error { Name: a.config.Consul.ServerServiceName, PortLabel: a.serverHTTPAddr, Tags: []string{consul.ServiceTagHTTP}, + Checks: []*structs.ServiceCheck{ + &structs.ServiceCheck{ + Name: "Nomad Server HTTP Check", + Type: "http", + Path: "/v1/status/peers", + Protocol: "http", // TODO TLS + Interval: serverHttpCheckInterval, + Timeout: serverHttpCheckTimeout, + }, + }, } rpcServ := &structs.Service{ Name: a.config.Consul.ServerServiceName, PortLabel: a.serverRPCAddr, Tags: []string{consul.ServiceTagRPC}, + Checks: []*structs.ServiceCheck{ + &structs.ServiceCheck{ + Name: "Nomad Server RPC Check", + Type: "tcp", + Interval: serverRpcCheckInterval, + Timeout: serverRpcCheckTimeout, + }, + }, } serfServ := &structs.Service{ PortLabel: a.serverSerfAddr, Name: a.config.Consul.ServerServiceName, Tags: []string{consul.ServiceTagSerf}, + Checks: []*structs.ServiceCheck{ + &structs.ServiceCheck{ + Name: "Nomad Server Serf Check", + Type: "tcp", + Interval: serverSerfCheckInterval, + Timeout: serverSerfCheckTimeout, + }, + }, } a.consulSyncer.SetServices(consul.ServerDomain, map[consul.ServiceKey]*structs.Service{ consul.GenerateServiceKey(httpServ): httpServ, @@ -443,11 +482,29 @@ func (a *Agent) setupClient() error { Name: a.config.Consul.ClientServiceName, PortLabel: a.clientHTTPAddr, Tags: []string{consul.ServiceTagHTTP}, + Checks: []*structs.ServiceCheck{ + &structs.ServiceCheck{ + Name: "Nomad Client HTTP Check", + Type: "http", + Path: "/v1/agent/self", + Protocol: "http", // TODO TLS + Interval: clientHttpCheckInterval, + Timeout: clientHttpCheckTimeout, + }, + }, } rpcServ := &structs.Service{ Name: a.config.Consul.ClientServiceName, PortLabel: a.clientRPCAddr, Tags: []string{consul.ServiceTagRPC}, + Checks: []*structs.ServiceCheck{ + &structs.ServiceCheck{ + Name: "Nomad Client RPC Check", + Type: "tcp", + Interval: clientRpcCheckInterval, + Timeout: clientRpcCheckTimeout, + }, + }, } a.consulSyncer.SetServices(consul.ClientDomain, map[consul.ServiceKey]*structs.Service{ consul.GenerateServiceKey(httpServ): httpServ, From 25aed9826a05508976e099f1c821988b6227473c Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Thu, 16 Jun 2016 17:40:47 -0700 Subject: [PATCH 3/3] Use `/v1/agent/servers` (vs `/v1/agent/self`). --- command/agent/agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index 362f6cbb6..05b2a1248 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -486,7 +486,7 @@ func (a *Agent) setupClient() error { &structs.ServiceCheck{ Name: "Nomad Client HTTP Check", Type: "http", - Path: "/v1/agent/self", + Path: "/v1/agent/servers", Protocol: "http", // TODO TLS Interval: clientHttpCheckInterval, Timeout: clientHttpCheckTimeout,