Skip to content

Instantly share code, notes, and snippets.

@yashtibrewal
Created May 24, 2022 12:10
Show Gist options
  • Save yashtibrewal/18ed4414cbc7a2a63b4d6f44678b818d to your computer and use it in GitHub Desktop.
Save yashtibrewal/18ed4414cbc7a2a63b4d6f44678b818d to your computer and use it in GitHub Desktop.
Dashboard Alternative (ZTM)
//--Summary:
// Create a system monitoring dashboard using the existing dashboard
// component structures. Each array element in the components represent
// a 1-second sampling. e.g. for CPU, Network, Memory
//
//--Requirements:
//* Create functions to calculate averages for each dashboard component
//* Using struct embedding, create a Dashboard structure that contains
// each dashboard component
//* Print out a 5-second average from each component using promoted
// methods on the Dashboard
package main
import "fmt"
type Dashboard struct {
usageInBytes []int
}
func (d *Dashboard) average(values []int) int {
var sum int = 0
for i := 0; i < len(values); i++ {
sum += values[i]
}
return sum / len(values)
}
type CPUUsage struct {
Dashboard
}
type MemoryUsage struct {
Dashboard
}
type NetworkUsage struct {
Dashboard
}
func main() {
n := NetworkUsage{Dashboard{usageInBytes: []int{100, 200, 300}}}
result := n.average(n.usageInBytes)
fmt.Println(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment