open-nomad/command/agent/stats_endpoint.go

27 lines
616 B
Go
Raw Normal View History

package agent
2017-10-05 22:43:20 +00:00
import (
"net/http"
"github.com/hashicorp/nomad/nomad/structs"
)
2016-05-24 23:41:35 +00:00
func (s *HTTPServer) ClientStatsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if s.agent.client == nil {
return nil, clientNotRunning
}
2017-10-05 22:43:20 +00:00
var secret string
s.parseToken(req, &secret)
// Check node read permissions
if aclObj, err := s.agent.Client().ResolveToken(secret); err != nil {
return nil, err
} else if aclObj != nil && !aclObj.AllowNodeRead() {
return nil, structs.ErrPermissionDenied
}
clientStats := s.agent.client.StatsReporter()
return clientStats.LatestHostStats(), nil
}