mirror of https://github.com/hashicorp/consul
Exposing the agent checks and services over HTTP endpoints
parent
d5d705b931
commit
cb7541c7af
|
@ -6,8 +6,13 @@ import (
|
|||
)
|
||||
|
||||
func (s *HTTPServer) AgentServices(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
// TODO
|
||||
return nil, nil
|
||||
services := s.agent.Services()
|
||||
return services, nil
|
||||
}
|
||||
|
||||
func (s *HTTPServer) AgentChecks(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
checks := s.agent.Checks()
|
||||
return checks, nil
|
||||
}
|
||||
|
||||
func (s *HTTPServer) AgentMembers(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
|
|
|
@ -71,6 +71,7 @@ func (s *HTTPServer) registerHandlers() {
|
|||
s.mux.HandleFunc("/v1/health/service/", s.wrap(s.HealthServiceNodes))
|
||||
|
||||
s.mux.HandleFunc("/v1/agent/services", s.wrap(s.AgentServices))
|
||||
s.mux.HandleFunc("/v1/agent/checks", s.wrap(s.AgentChecks))
|
||||
s.mux.HandleFunc("/v1/agent/members", s.wrap(s.AgentMembers))
|
||||
s.mux.HandleFunc("/v1/agent/join/", s.wrap(s.AgentJoin))
|
||||
s.mux.HandleFunc("/v1/agent/force-leave/", s.wrap(s.AgentForceLeave))
|
||||
|
|
|
@ -25,8 +25,8 @@ The current URLs supported are:
|
|||
* /v1/status/leader : Returns the current Raft leader
|
||||
* /v1/status/peers : Returns the current Raft peer set
|
||||
|
||||
* /v1/agent/health: Returns the health info from the local agent (future)
|
||||
* /v1/agent/services : Returns the services local agent is attempting to register
|
||||
* /v1/agent/checks: Returns the checks the local agent is managing
|
||||
* /v1/agent/services : Returns the services local agent is managing
|
||||
* /v1/agent/members : Returns the members as seen by the local serf agent
|
||||
* /v1/agent/join/<node> : Instructs the local agent to join a node
|
||||
* /v1/agent/force-leave/<node>: Instructs the agent to force a node into the left state
|
||||
|
|
|
@ -89,6 +89,19 @@ func (a *Agent) RemoveService(serviceID string) {
|
|||
a.state.changeMade()
|
||||
}
|
||||
|
||||
// Services returns the locally registered services that the
|
||||
// agent is aware of and are being kept in sync with the server
|
||||
func (a *Agent) Services() map[string]*structs.NodeService {
|
||||
services := make(map[string]*structs.NodeService)
|
||||
a.state.Lock()
|
||||
defer a.state.Unlock()
|
||||
|
||||
for name, serv := range a.state.services {
|
||||
services[name] = serv
|
||||
}
|
||||
return services
|
||||
}
|
||||
|
||||
// AddCheck is used to add a health check to the local state.
|
||||
// This entry is persistent and the agent will make a best effort to
|
||||
// ensure it is registered
|
||||
|
@ -133,6 +146,19 @@ func (a *Agent) UpdateCheck(checkID, status string) {
|
|||
a.state.changeMade()
|
||||
}
|
||||
|
||||
// Checks returns the locally registered checks that the
|
||||
// agent is aware of and are being kept in sync with the server
|
||||
func (a *Agent) Checks() map[string]*structs.HealthCheck {
|
||||
checks := make(map[string]*structs.HealthCheck)
|
||||
a.state.Lock()
|
||||
defer a.state.Unlock()
|
||||
|
||||
for name, check := range a.state.checks {
|
||||
checks[name] = check
|
||||
}
|
||||
return checks
|
||||
}
|
||||
|
||||
// antiEntropy is a long running method used to perform anti-entropy
|
||||
// between local and remote state.
|
||||
func (a *Agent) antiEntropy() {
|
||||
|
|
Loading…
Reference in New Issue