package main import ( "log" "github.com/rosti-cz/node-api/apps" "github.com/rosti-cz/node-api/docker" ) // Updates only container's state func updateContainerState(app *apps.App) error { container := docker.Container{ App: app, } state, err := container.Status() if err != nil { return err } err = apps.UpdateContainerState( app.Name, state, ) return err } // Updates info about all containers 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 err } // 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 } // gatherContainersStates refreshes all container's state func gatherContainersStates() error { appList, err := apps.List() if err != nil { return err } for _, app := range *appList { err := updateContainerState(&app) if err != nil { log.Println("STATE ERROR:", err.Error()) } } return nil }