node-api/stats.go

43 lines
736 B
Go
Raw Normal View History

2020-07-16 17:05:38 +00:00
package main
import (
"log"
"github.com/rosti-cz/node-api/apps"
"github.com/rosti-cz/node-api/docker"
)
// gatherContainerStats gathers information about containers and saves it into the database
func gatherContainerStats() error {
appList, err := apps.List()
if err != nil {
return err
}
for _, app := range *appList {
container := docker.Container{
App: &app,
}
state, err := container.GetState()
if err != nil {
log.Println("STATS ERROR:", err.Error())
continue
}
err = apps.UpdateState(
app.Name,
state.State,
state.CPUUsage,
state.MemoryUsage,
state.DiskUsageBytes,
state.DiskUsageInodes,
)
if err != nil {
log.Println("STATS ERROR:", err.Error())
}
}
return nil
}