2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
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
|
|
|
|
2023-02-07 22:42:25 +00:00
|
|
|
// Build the request and get the requested Node ID
|
|
|
|
args := structs.NodeSpecificRequest{}
|
2018-01-11 23:58:59 +00:00
|
|
|
s.parse(resp, req, &args.QueryOptions.Region, &args.QueryOptions)
|
2023-02-07 22:42:25 +00:00
|
|
|
parseNode(req, &args.NodeID)
|
2017-10-05 22:43:20 +00:00
|
|
|
|
2018-02-05 22:57:29 +00:00
|
|
|
// Determine the handler to use
|
2023-02-07 22:42:25 +00:00
|
|
|
useLocalClient, useClientRPC, useServerRPC := s.rpcHandlerForNode(args.NodeID)
|
2018-02-05 22:57:29 +00:00
|
|
|
|
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
|
|
|
}
|