Files
nomad/client/client_stats_endpoint.go
Matt Keeler 833e240597 Upgrade to using hashicorp/go-metrics@v0.5.4 (#24856)
* Upgrade to using hashicorp/go-metrics@v0.5.4

This also requires bumping the dependencies for:

* memberlist
* serf
* raft
* raft-boltdb
* (and indirectly hashicorp/mdns due to the memberlist or serf update)

Unlike some other HashiCorp products, Nomads root module is currently expected to be consumed by others. This means that it needs to be treated more like our libraries and upgrade to hashicorp/go-metrics by utilizing its compat packages. This allows those importing the root module to control the metrics module used via build tags.
2025-01-31 15:22:00 -05:00

34 lines
895 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package client
import (
"time"
metrics "github.com/hashicorp/go-metrics/compat"
"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.
func (s *ClientStats) Stats(args *nstructs.NodeSpecificRequest, reply *structs.ClientStatsResponse) error {
defer metrics.MeasureSince([]string{"client", "client_stats", "stats"}, time.Now())
// Check node read permissions
if aclObj, err := s.c.ResolveToken(args.AuthToken); err != nil {
return err
} else if !aclObj.AllowNodeRead() {
return nstructs.ErrPermissionDenied
}
clientStats := s.c.StatsReporter()
reply.HostStats = clientStats.LatestHostStats()
return nil
}