Add backup maintenance and guest update controls
This commit is contained in:
36
agent.go
36
agent.go
@@ -13,6 +13,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -40,16 +41,18 @@ type agentConfig struct {
|
||||
}
|
||||
|
||||
type AgentContainer struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Image string `json:"image"`
|
||||
State string `json:"state"`
|
||||
Status string `json:"status"`
|
||||
Health string `json:"health,omitempty"`
|
||||
Restarts int64 `json:"restarts"`
|
||||
CPUPercent float64 `json:"cpuPercent"`
|
||||
MemoryUsage uint64 `json:"memoryUsage"`
|
||||
Ports []string `json:"ports,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Image string `json:"image"`
|
||||
State string `json:"state"`
|
||||
Status string `json:"status"`
|
||||
Health string `json:"health,omitempty"`
|
||||
Restarts int64 `json:"restarts"`
|
||||
CPUPercent float64 `json:"cpuPercent"`
|
||||
MemoryUsage uint64 `json:"memoryUsage"`
|
||||
Ports []string `json:"ports,omitempty"`
|
||||
Compose bool `json:"compose"`
|
||||
UpdateAvailable bool `json:"updateAvailable"`
|
||||
}
|
||||
|
||||
type AgentInterface struct {
|
||||
@@ -913,14 +916,27 @@ func collectDockerContainers() ([]AgentContainer, string) {
|
||||
inspect, inspectErr := client.Get("http://docker/containers/" + v.ID + "/json")
|
||||
if inspectErr == nil {
|
||||
var detail struct {
|
||||
Image string
|
||||
RestartCount int64
|
||||
State struct{ Health *struct{ Status string } }
|
||||
Config struct {
|
||||
Labels map[string]string
|
||||
}
|
||||
}
|
||||
if json.NewDecoder(inspect.Body).Decode(&detail) == nil {
|
||||
item.Restarts = detail.RestartCount
|
||||
if detail.State.Health != nil {
|
||||
item.Health = detail.State.Health.Status
|
||||
}
|
||||
item.Compose = detail.Config.Labels["com.docker.compose.service"] != ""
|
||||
imageResponse, imageErr := client.Get("http://docker/images/" + url.PathEscape(v.Image) + "/json")
|
||||
if imageErr == nil {
|
||||
var imageDetail struct{ ID string }
|
||||
if json.NewDecoder(imageResponse.Body).Decode(&imageDetail) == nil && detail.Image != "" && imageDetail.ID != "" {
|
||||
item.UpdateAvailable = detail.Image != imageDetail.ID
|
||||
}
|
||||
imageResponse.Body.Close()
|
||||
}
|
||||
}
|
||||
inspect.Body.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user