From bf325fb12b703cfb97b0ef223a99b8d50df6a638 Mon Sep 17 00:00:00 2001 From: Seth Schwartzman Date: Thu, 24 May 2018 14:27:30 -0400 Subject: [PATCH 1/2] Working CPU stats, incomplete Memory stats --- f5/sys/cpu_stats.go | 161 +++++++++++++++++++++++++++++++++++++++++ f5/sys/memory_stats.go | 85 ++++++++++++++++++++++ f5/sys/sys.go | 7 ++ 3 files changed, 253 insertions(+) create mode 100644 f5/sys/cpu_stats.go create mode 100644 f5/sys/memory_stats.go diff --git a/f5/sys/cpu_stats.go b/f5/sys/cpu_stats.go new file mode 100644 index 0000000..a78bfa1 --- /dev/null +++ b/f5/sys/cpu_stats.go @@ -0,0 +1,161 @@ +// Copyright e-Xpert Solutions SA. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package sys + +import "github.com/e-XpertSolutions/f5-rest-client/f5" + +type CPUList struct { + Entries map[string]CPUEntries `json:"entries,omitempty"` + Kind string `json:"kind,omitempty" pretty:",expanded"` + SelfLink string `json:"selfLink,omitempty" pretty:",expanded"` +} + +type CPUEntries struct { + NestedStats CPUStatsList `json:"nestedStats,omitempty"` +} + +type CPUStatsList struct { + Entries map[string]CPUStatsEntries `json:"entries,omitempty"` + Kind string `json:"kind,omitempty" pretty:",expanded"` + SelfLink string `json:"selfLink,omitempty" pretty:",expanded"` +} + +type CPUStatsEntries struct { + NestedStats CPUCoreStatsList `json:"nestedStats,omitempty"` + Description string `json:"description,omitempty"` +} + +type CPUCoreStatsList struct { + Entries map[string]CPUCoreStatsEntries `json:"entries,omitempty"` + Kind string `json:"kind,omitempty" pretty:",expanded"` + SelfLink string `json:"selfLink,omitempty" pretty:",expanded"` +} + +type CPUCoreStatsEntries struct { + NestedStats CPUCoreStats `json:"nestedStats,omitempty"` +} + +type CPUCoreStats struct { + Entries struct { + CpuId struct { + Value int `json:"value"` + } `json:"cpuId,omitempty"` + FiveMinAvgIdle struct { + Value int `json:"value"` + } `json:"fiveMinAvgIdle,omitempty"` + FiveMinAvgIowait struct { + Value int `json:"value"` + } `json:"fiveMinAvgIowait,omitempty"` + FiveMinAvgIrq struct { + Value int `json:"value"` + } `json:"fiveMinAvgIrq,omitempty"` + FiveMinAvgNiced struct { + Value int `json:"value"` + } `json:"fiveMinAvgNiced,omitempty"` + FiveMinAvgSoftirq struct { + Value int `json:"value"` + } `json:"fiveMinAvgSoftirq,omitempty"` + FiveMinAvgStolen struct { + Value int `json:"value"` + } `json:"fiveMinAvgStolen,omitempty"` + FiveMinAvgSystem struct { + Value int `json:"value"` + } `json:"fiveMinAvgSystem,omitempty"` + FiveMinAvgUser struct { + Value int `json:"value"` + } `json:"fiveMinAvgUser,omitempty"` + FiveSecAvgIdle struct { + Value int `json:"value"` + } `json:"fiveSecAvgIdle,omitempty"` + FiveSecAvgIowait struct { + Value int `json:"value"` + } `json:"fiveSecAvgIowait,omitempty"` + FiveSecAvgIrq struct { + Value int `json:"value"` + } `json:"fiveSecAvgIrq,omitempty"` + FiveSecAvgNiced struct { + Value int `json:"value"` + } `json:"fiveSecAvgNiced,omitempty"` + FiveSecAvgSoftirq struct { + Value int `json:"value"` + } `json:"fiveSecAvgSoftirq,omitempty"` + FiveSecAvgStolen struct { + Value int `json:"value"` + } `json:"fiveSecAvgStolen,omitempty"` + FiveSecAvgSystem struct { + Value int `json:"value"` + } `json:"fiveSecAvgSystem,omitempty"` + FiveSecAvgUser struct { + Value int `json:"value"` + } `json:"fiveSecAvgUser,omitempty"` + Idle struct { + Value int `json:"value"` + } `json:"idle,omitempty"` + Iowait struct { + Value int `json:"value"` + } `json:"iowait,omitempty"` + Irq struct { + Value int `json:"value"` + } `json:"irq,omitempty"` + Niced struct { + Value int `json:"value"` + } `json:"niced,omitempty"` + OneMinAvgIdle struct { + Value int `json:"value"` + } `json:"oneMinAvgIdle,omitempty"` + OneMinAvgIowait struct { + Value int `json:"value"` + } `json:"oneMinAvgIowait,omitempty"` + OneMinAvgIrq struct { + Value int `json:"value"` + } `json:"oneMinAvgIrq,omitempty"` + OneMinAvgNiced struct { + Value int `json:"value"` + } `json:"oneMinAvgNiced,omitempty"` + OneMinAvgSoftirq struct { + Value int `json:"value"` + } `json:"oneMinAvgSoftirq,omitempty"` + OneMinAvgStolen struct { + Value int `json:"value"` + } `json:"oneMinAvgStolen,omitempty"` + OneMinAvgSystem struct { + Value int `json:"value"` + } `json:"oneMinAvgSystem,omitempty"` + OneMinAvgUser struct { + Value int `json:"value"` + } `json:"oneMinAvgUser,omitempty"` + Softirq struct { + Value int `json:"value"` + } `json:"softirq,omitempty"` + Stolen struct { + Value int `json:"value"` + } `json:"stolen,omitempty"` + System struct { + Value int `json:"value"` + } `json:"system,omitempty"` + UsageRatio struct { + Value int `json:"value"` + } `json:"usageRatio,omitempty"` + User struct { + Value int `json:"value"` + } `json:"user,omitempty"` + } `json:"entries,omitempty"` +} + +// CPUStatsEndpoint represents the REST resource for managing CPUStats. +const CPUStatsEndpoint = "/cpu" + +// CPUStatsResource provides an API to manage CPUStats entries. +type CPUStatsResource struct { + c *f5.Client +} + +func (r *CPUStatsResource) All() (*CPUList, error) { + var list CPUList + if err := r.c.ReadQuery(BasePath+CPUStatsEndpoint, &list); err != nil { + return nil, err + } + return &list, nil +} diff --git a/f5/sys/memory_stats.go b/f5/sys/memory_stats.go new file mode 100644 index 0000000..0af69f8 --- /dev/null +++ b/f5/sys/memory_stats.go @@ -0,0 +1,85 @@ +// Copyright e-Xpert Solutions SA. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package sys + +import "github.com/e-XpertSolutions/f5-rest-client/f5" + +type MemoryStatsList struct { + Entries map[string]MemoryTopLevelEntries `json:"entries,omitempty"` + Kind string `json:"kind,omitempty" pretty:"expanded"` + SelfLink string `json:"selfLink,omitempty" pretty:"expanded"` +} + +type MemoryTopLevelEntries struct { + NestedStats MemoryInnerStatsList `json:"nestedStats,omitempty"` +} + +type MemoryInnerStatsList struct { + Entries map[string]MemoryStatsEntries `json:"entries,omitempty"` +} + +type MemoryStatsEntries struct { + NestedMemoryStats MemoryStats `json:"nestedStats,omitempty"` +} + +type MemoryStats struct { + Entries struct { + HostId struct { + Value string `json:"description"` + } `json:"hostId,omitempty"` + MemoryFree struct { + Value int `json:"value"` + } `json:"memoryFree,omitempty"` + MemoryTotal struct { + Value int `json:"value"` + } `json:"memoryTotal,omitempty"` + MemoryUsed struct { + Value int `json:"value"` + } `json:"memoryUsed,omitempty"` + OtherMemoryFree struct { + Value int `json:"value"` + } `json:"otherMemoryFree,omitempty"` + OtherMemoryTotal struct { + Value int `json:"value"` + } `json:"otherMemoryTotal,omitempty"` + OtherMemoryUsed struct { + Value int `json:"value"` + } `json:"otherMemoryUsed,omitempty"` + SwapFree struct { + Value int `json:"value"` + } `json:"swapFree,omitempty"` + SwapTotal struct { + Value int `json:"value"` + } `json:"swapTotal,omitempty"` + SwapUsed struct { + Value int `json:"value"` + } `json:"swapUsed,omitempty"` + TmmMemoryFree struct { + Value int `json:"value"` + } `json:"tmmMemoryFree,omitempty"` + TmmMemoryTotal struct { + Value int `json:"value"` + } `json:"tmmMemoryTotal,omitempty"` + TmmMemoryUsed struct { + Value int `json:"value"` + } `json:"tmmMemoryUsed,omitempty"` + } `json:"entries,omitempty"` +} + +// MemoryStatsEndpoint represents the REST resource for managing MemoryStats. +const MemoryStatsEndpoint = "/memory" + +// MemoryStatsResource provides an API to manage MemoryStats entries. +type MemoryStatsResource struct { + c *f5.Client +} + +func (r *MemoryStatsResource) All() (*MemoryStatsList, error) { + var list MemoryStatsList + if err := r.c.ReadQuery(BasePath+MemoryStatsEndpoint, &list); err != nil { + return nil, err + } + return &list, nil +} diff --git a/f5/sys/sys.go b/f5/sys/sys.go index 8f4b63b..0331897 100644 --- a/f5/sys/sys.go +++ b/f5/sys/sys.go @@ -26,6 +26,7 @@ type Sys struct { cluster ClusterResource connection ConnectionResource console ConsoleResource + cpuStats CPUStatsResource crypto CryptoResource cryptoCRL CryptoCRLResource cryptoCSR CryptoCSRResource @@ -160,6 +161,7 @@ func New(c *f5.Client) Sys { cluster: ClusterResource{c: c}, connection: ConnectionResource{c: c}, console: ConsoleResource{c: c}, + cpuStats: CPUStatsResource{c: c}, crypto: CryptoResource{c: c}, cryptoCRL: CryptoCRLResource{c: c}, cryptoCSR: CryptoCSRResource{c: c}, @@ -351,6 +353,11 @@ func (sys Sys) Console() *ConsoleResource { return &sys.console } +// console returns a configured ConsoleResource. +func (sys Sys) CPUStats() *CPUStatsResource { + return &sys.cpuStats +} + // crypto returns a configured CryptoResource. func (sys Sys) Crypto() *CryptoResource { return &sys.crypto From f17894c45c6b93c464e0a3d3479167c77874765e Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 29 May 2018 11:59:54 -0500 Subject: [PATCH 2/2] Add F5 memory stats --- f5/sys/memory_stats.go | 17 ++++++++++++++++- f5/sys/sys.go | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/f5/sys/memory_stats.go b/f5/sys/memory_stats.go index 0af69f8..602c0ee 100644 --- a/f5/sys/memory_stats.go +++ b/f5/sys/memory_stats.go @@ -21,14 +21,20 @@ type MemoryInnerStatsList struct { } type MemoryStatsEntries struct { - NestedMemoryStats MemoryStats `json:"nestedStats,omitempty"` + NestedStats MemoryStats `json:"nestedStats,omitempty"` } type MemoryStats struct { Entries struct { + Allocated struct { + Value int `json:"value"` + } `json:"allocated,omitempty"` HostId struct { Value string `json:"description"` } `json:"hostId,omitempty"` + MaxAllocated struct{ + Value int `json:"value"` + } `json maxAllocated,omitempty"` MemoryFree struct { Value int `json:"value"` } `json:"memoryFree,omitempty"` @@ -47,6 +53,9 @@ type MemoryStats struct { OtherMemoryUsed struct { Value int `json:"value"` } `json:"otherMemoryUsed,omitempty"` + Size struct { + Value int `json:"value"` + } `json:"size,omitempty"` SwapFree struct { Value int `json:"value"` } `json:"swapFree,omitempty"` @@ -56,6 +65,9 @@ type MemoryStats struct { SwapUsed struct { Value int `json:"value"` } `json:"swapUsed,omitempty"` + TmmId struct { + Value string `json:"description"` + } `json:"tmmId,omitempty"` TmmMemoryFree struct { Value int `json:"value"` } `json:"tmmMemoryFree,omitempty"` @@ -65,6 +77,9 @@ type MemoryStats struct { TmmMemoryUsed struct { Value int `json:"value"` } `json:"tmmMemoryUsed,omitempty"` + TmName struct { + Value string `json:"description"` + } `json:"tmName,omitempty"` } `json:"entries,omitempty"` } diff --git a/f5/sys/sys.go b/f5/sys/sys.go index 0331897..0d5c4fd 100644 --- a/f5/sys/sys.go +++ b/f5/sys/sys.go @@ -103,6 +103,7 @@ type Sys struct { managementIP ManagementIPResource managementOVSDB ManagementOVSDBResource managementRoute ManagementRouteResource + memoryStats MemoryStatsResource nTP NTPResource nTPRestrict NTPRestrictResource outboundSMTP OutboundSMTPResource @@ -238,6 +239,7 @@ func New(c *f5.Client) Sys { managementIP: ManagementIPResource{c: c}, managementOVSDB: ManagementOVSDBResource{c: c}, managementRoute: ManagementRouteResource{c: c}, + memoryStats: MemoryStatsResource{c: c}, nTP: NTPResource{c: c}, nTPRestrict: NTPRestrictResource{c: c}, outboundSMTP: OutboundSMTPResource{c: c}, @@ -738,6 +740,10 @@ func (sys Sys) ManagementRoute() *ManagementRouteResource { return &sys.managementRoute } +func (sys Sys) MemoryStats() *MemoryStatsResource { + return &sys.memoryStats +} + // nTP returns a configured NTPResource. func (sys Sys) NTP() *NTPResource { return &sys.nTP