46 lines
779 B
Go
46 lines
779 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/rosti-cz/node-api/apps"
|
|
"github.com/rosti-cz/node-api/docker"
|
|
)
|
|
|
|
func updateContainerStats(app *apps.App) error {
|
|
container := docker.Container{
|
|
App: app,
|
|
}
|
|
state, err := container.GetState()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = apps.UpdateState(
|
|
app.Name,
|
|
state.State,
|
|
state.CPUUsage,
|
|
state.MemoryUsage,
|
|
state.DiskUsageBytes,
|
|
state.DiskUsageInodes,
|
|
)
|
|
return nil
|
|
}
|
|
|
|
// gatherContainersStats gathers information about containers and saves it into the database
|
|
func gatherContainersStats() error {
|
|
appList, err := apps.List()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, app := range *appList {
|
|
err := updateContainerStats(&app)
|
|
if err != nil {
|
|
log.Println("STATS ERROR:", err.Error())
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|