Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

put average cpu usage with some containers #61

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions esp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func main() {
log.Fatal("error retrieving container name from environment variable")
}

var totalCPUUsage float64
var containerCount int

for _, container := range taskMetadata.Containers {
if container.Name == containerName {
s := containersMetadata[container.DockerID]
Expand All @@ -41,10 +44,8 @@ func main() {
(float64(s.CPUStats.SystemCPUUsage) - float64(s.PreCPUStats.SystemCPUUsage))) *
float64(s.CPUStats.OnlineCPUs) * 100

_, err = cloudwatch.PutMetricData(cpuUsage)
if err != nil {
log.Printf("Error putting metric data: %s", err)
}
totalCPUUsage += cpuUsage
containerCount++

log.SetFormatter(&log.JSONFormatter{})
log.WithFields(log.Fields{
Expand All @@ -60,6 +61,16 @@ func main() {
}).Info("ESP Stats")
}
}

if containerCount > 0 {
averageCPUUsage := totalCPUUsage / float64(containerCount)

_, err = cloudwatch.PutMetricData(averageCPUUsage)
if err != nil {
log.Printf("Error putting metric data: %s", err)
}
}

time.Sleep(time.Second * 1)
}
}
Loading