2016-04-29 18:06:19 +00:00
|
|
|
package agent
|
|
|
|
|
2017-10-05 22:43:20 +00:00
|
|
|
import (
|
|
|
|
"net/http"
|
2018-01-11 23:58:59 +00:00
|
|
|
"strings"
|
2017-10-05 22:43:20 +00:00
|
|
|
|
2018-01-11 19:24:57 +00:00
|
|
|
cstructs "github.com/hashicorp/nomad/client/structs"
|
2018-01-31 20:13:57 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2017-10-05 22:43:20 +00:00
|
|
|
)
|
2016-04-29 18:06:19 +00:00
|
|
|
|
2016-05-24 23:41:35 +00:00
|
|
|
func (s *HTTPServer) ClientStatsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
2018-01-11 23:58:59 +00:00
|
|
|
// Get the requested Node ID
|
|
|
|
requestedNode := req.URL.Query().Get("node_id")
|
|
|
|
|
|
|
|
// Build the request and parse the ACL token
|
2018-02-06 01:20:42 +00:00
|
|
|
args := structs.NodeSpecificRequest{
|
2018-01-11 23:58:59 +00:00
|
|
|
NodeID: requestedNode,
|
|
|
|
}
|
|
|
|
s.parse(resp, req, &args.QueryOptions.Region, &args.QueryOptions)
|
2017-10-05 22:43:20 +00:00
|
|
|
|
2018-02-05 22:57:29 +00:00
|
|
|
// Determine the handler to use
|
|
|
|
useLocalClient, useClientRPC, useServerRPC := s.rpcHandlerForNode(requestedNode)
|
|
|
|
|
2018-01-11 19:24:57 +00:00
|
|
|
// Make the RPC
|
|
|
|
var reply cstructs.ClientStatsResponse
|
2018-01-11 23:58:59 +00:00
|
|
|
var rpcErr error
|
|
|
|
if useLocalClient {
|
|
|
|
rpcErr = s.agent.Client().ClientRPC("ClientStats.Stats", &args, &reply)
|
|
|
|
} else if useClientRPC {
|
|
|
|
rpcErr = s.agent.Client().RPC("ClientStats.Stats", &args, &reply)
|
|
|
|
} else if useServerRPC {
|
|
|
|
rpcErr = s.agent.Server().RPC("ClientStats.Stats", &args, &reply)
|
|
|
|
} else {
|
|
|
|
rpcErr = CodedError(400, "No local Node and node_id not provided")
|
|
|
|
}
|
|
|
|
|
|
|
|
if rpcErr != nil {
|
2018-01-31 20:13:57 +00:00
|
|
|
if structs.IsErrNoNodeConn(rpcErr) {
|
2018-01-11 23:58:59 +00:00
|
|
|
rpcErr = CodedError(404, rpcErr.Error())
|
|
|
|
} else if strings.Contains(rpcErr.Error(), "Unknown node") {
|
|
|
|
rpcErr = CodedError(404, rpcErr.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, rpcErr
|
2017-10-05 22:43:20 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 19:24:57 +00:00
|
|
|
return reply.HostStats, nil
|
2016-05-18 05:11:25 +00:00
|
|
|
}
|