Skip to content

Commit

Permalink
Merge pull request #14 from newrelic-experts/master
Browse files Browse the repository at this point in the history
Added CPU and Memory stats API calls
  • Loading branch information
gilliek authored Jun 1, 2018
2 parents 2fe161b + f17894c commit d7a337b
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 0 deletions.
161 changes: 161 additions & 0 deletions f5/sys/cpu_stats.go
Original file line number Diff line number Diff line change
@@ -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
}
100 changes: 100 additions & 0 deletions f5/sys/memory_stats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// 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 {
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"`
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"`
Size struct {
Value int `json:"value"`
} `json:"size,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"`
TmmId struct {
Value string `json:"description"`
} `json:"tmmId,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"`
TmName struct {
Value string `json:"description"`
} `json:"tmName,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
}
13 changes: 13 additions & 0 deletions f5/sys/sys.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Sys struct {
cluster ClusterResource
connection ConnectionResource
console ConsoleResource
cpuStats CPUStatsResource
crypto CryptoResource
cryptoCRL CryptoCRLResource
cryptoCSR CryptoCSRResource
Expand Down Expand Up @@ -102,6 +103,7 @@ type Sys struct {
managementIP ManagementIPResource
managementOVSDB ManagementOVSDBResource
managementRoute ManagementRouteResource
memoryStats MemoryStatsResource
nTP NTPResource
nTPRestrict NTPRestrictResource
outboundSMTP OutboundSMTPResource
Expand Down Expand Up @@ -160,6 +162,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},
Expand Down Expand Up @@ -236,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},
Expand Down Expand Up @@ -351,6 +355,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
Expand Down Expand Up @@ -731,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
Expand Down

0 comments on commit d7a337b

Please sign in to comment.