open-nomad/command/agent/stats_endpoint.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.3 KiB
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
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-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
// 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)
parseNode(req, &args.NodeID)
2017-10-05 22:43:20 +00:00
// Determine the handler to use
useLocalClient, useClientRPC, useServerRPC := s.rpcHandlerForNode(args.NodeID)
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
}