open-nomad/client/client_stats_endpoint.go

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

34 lines
900 B
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
2018-01-11 19:24:57 +00:00
package client
import (
"time"
metrics "github.com/armon/go-metrics"
"github.com/hashicorp/nomad/client/structs"
nstructs "github.com/hashicorp/nomad/nomad/structs"
)
// ClientStats endpoint is used for retrieving stats about a client
type ClientStats struct {
c *Client
}
// Stats is used to retrieve the Clients stats.
2018-02-06 01:20:42 +00:00
func (s *ClientStats) Stats(args *nstructs.NodeSpecificRequest, reply *structs.ClientStatsResponse) error {
2018-01-11 21:23:57 +00:00
defer metrics.MeasureSince([]string{"client", "client_stats", "stats"}, time.Now())
2018-01-11 19:24:57 +00:00
// Check node read permissions
if aclObj, err := s.c.ResolveToken(args.AuthToken); err != nil {
return err
} else if aclObj != nil && !aclObj.AllowNodeRead() {
return nstructs.ErrPermissionDenied
}
clientStats := s.c.StatsReporter()
reply.HostStats = clientStats.LatestHostStats()
return nil
}