diff --git a/api/allocations.go b/api/allocations.go index 233d9e0ba..1da3a856f 100644 --- a/api/allocations.go +++ b/api/allocations.go @@ -58,8 +58,12 @@ func (a *Allocations) Stats(alloc *Allocation, q *QueryOptions) (map[string]*Tas if err != nil { return nil, err } + resp := make(map[string][]*TaskResourceUsage) + client.query("/v1/client/allocation/"+alloc.ID+"/stats", &resp, nil) res := make(map[string]*TaskResourceUsage) - client.query("/v1/client/allocation/"+alloc.ID+"/stats", &res, nil) + for task, ru := range resp { + res[task] = ru[0] + } return res, nil } diff --git a/api/api.go b/api/api.go index 2b40a24b1..80c03b256 100644 --- a/api/api.go +++ b/api/api.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - //"io/ioutil" "net/http" "net/url" "os" diff --git a/api/nodes.go b/api/nodes.go index 9b3302f3b..5ed88d6b0 100644 --- a/api/nodes.go +++ b/api/nodes.go @@ -89,11 +89,12 @@ func (n *Nodes) Stats(nodeID string, q *QueryOptions) (*HostStats, error) { if err != nil { return nil, err } - var hostStats HostStats - if _, err := client.query("/v1/client/stats/", &hostStats, nil); err != nil { + var resp []HostStats + if _, err := client.query("/v1/client/stats/", &resp, nil); err != nil { return nil, err } - return &hostStats, nil + + return &resp[0], nil } // Node is used to deserialize a node entry. diff --git a/api/tasks.go b/api/tasks.go index 8a9aaa17b..c82db5ba2 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -4,6 +4,7 @@ import ( "time" ) +// MemoryStats holds memory usage related stats type MemoryStats struct { RSS uint64 Cache uint64 @@ -13,6 +14,7 @@ type MemoryStats struct { KernelMaxUsage uint64 } +// CpuStats holds cpu usage related stats type CpuStats struct { SystemMode float64 UserMode float64 @@ -21,15 +23,17 @@ type CpuStats struct { Percent float64 } +// ResourceUsage holds information related to cpu and memory stats type ResourceUsage struct { MemoryStats *MemoryStats CpuStats *CpuStats - Timestamp time.Time } +// TaskResourceUsage holds aggregated resource usage of all processes in a Task +// and the resource usage of the individual pids type TaskResourceUsage struct { ResourceUsage *ResourceUsage - Timestamp time.Time + Timestamp int64 Pids map[string]*ResourceUsage }