Skip to content

Commit

Permalink
bcicen#191 Collect project's metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
stokito committed Nov 16, 2020
1 parent a3ddfff commit fcb99f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions container/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Project struct {
Config string
Count int // Containers Count
Widgets *compact.CompactRow
Metrics models.Metrics
}

// Metrics and metadata representing a container
Expand Down Expand Up @@ -105,10 +106,15 @@ func (c *Container) Logs() collector.LogCollector {
func (c *Container) Read(stream chan models.Metrics) {
go func() {
for metrics := range stream {
oldContainerMetrics := c.Metrics
c.Project.Metrics.Subtract(oldContainerMetrics)
c.Project.Metrics.Add(metrics)
c.Project.Widgets.SetMetrics(c.Project.Metrics)
c.Metrics = metrics
c.updater.SetMetrics(metrics)
}
log.Infof("reader stopped for container: %s", c.Id)
c.Project.Metrics.Subtract(c.Metrics)
c.Metrics = models.Metrics{}
c.Widgets.Reset()
}()
Expand Down
24 changes: 24 additions & 0 deletions models/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ type Metrics struct {
Pids int
}

func (m *Metrics) Add(otherMetrics Metrics) {
m.CPUUtil += otherMetrics.CPUUtil
m.NetTx += otherMetrics.NetTx
m.NetRx += otherMetrics.NetRx
m.MemLimit += otherMetrics.MemLimit
m.MemPercent += otherMetrics.MemPercent
m.MemUsage += otherMetrics.MemUsage
m.IOBytesRead += otherMetrics.IOBytesRead
m.IOBytesWrite += otherMetrics.IOBytesWrite
m.Pids += otherMetrics.Pids
}

func (m *Metrics) Subtract(otherMetrics Metrics) {
m.CPUUtil -= otherMetrics.CPUUtil
m.NetTx -= otherMetrics.NetTx
m.NetRx -= otherMetrics.NetRx
m.MemLimit -= otherMetrics.MemLimit
m.MemPercent -= otherMetrics.MemPercent
m.MemUsage -= otherMetrics.MemUsage
m.IOBytesRead -= otherMetrics.IOBytesRead
m.IOBytesWrite -= otherMetrics.IOBytesWrite
m.Pids -= otherMetrics.Pids
}

func (m *Metrics) SumNet() int64 { return m.NetRx + m.NetTx }

func (m *Metrics) SumIO() int64 { return m.IOBytesRead + m.IOBytesWrite }

0 comments on commit fcb99f5

Please sign in to comment.