|
|
@@ -7,6 +7,7 @@ import (
|
|
|
"goseg/docker"
|
|
|
"goseg/startram"
|
|
|
"goseg/structs"
|
|
|
+ "goseg/system"
|
|
|
"log/slog"
|
|
|
"math"
|
|
|
"os"
|
|
|
@@ -98,15 +99,26 @@ func bootstrapBroadcastState(config structs.SysConfig) (structs.AuthBroadcast, e
|
|
|
logger.Error(errmsg)
|
|
|
}
|
|
|
}
|
|
|
+ // update with system state
|
|
|
+ sysInfo := constructSystemInfo()
|
|
|
+ err = UpdateBroadcastState(sysInfo)
|
|
|
+ if err != nil {
|
|
|
+ errmsg := fmt.Sprintf("Error updating broadcast state:", err)
|
|
|
+ logger.Error(errmsg)
|
|
|
+ }
|
|
|
// return the boostrapped result
|
|
|
res = GetState()
|
|
|
return res, nil
|
|
|
}
|
|
|
|
|
|
+// this is for building the broadcast objects describing piers
|
|
|
func constructPierInfo(piers []string) (map[string]structs.Urbit, error) {
|
|
|
updates := make(map[string]structs.Urbit)
|
|
|
+ // load fresh broadcast state
|
|
|
currentState := GetState()
|
|
|
+ // get the networks containers are attached to
|
|
|
shipNetworks := GetContainerNetworks(piers)
|
|
|
+ // find out whether they're running
|
|
|
pierStatus, err := docker.GetShipStatus(piers)
|
|
|
if err != nil {
|
|
|
errmsg := fmt.Sprintf("Unable to bootstrap urbit states: %v", err)
|
|
|
@@ -129,7 +141,7 @@ func constructPierInfo(piers []string) (map[string]structs.Urbit, error) {
|
|
|
continue
|
|
|
}
|
|
|
dockerConfig := docker.Conf(pier)
|
|
|
- // pull docker info from json
|
|
|
+ // get container stats from docker
|
|
|
var dockerStats structs.ContainerStats
|
|
|
dockerStats, err = docker.GetContainerStats(pier)
|
|
|
if err != nil {
|
|
|
@@ -151,6 +163,7 @@ func constructPierInfo(piers []string) (map[string]structs.Urbit, error) {
|
|
|
if dockerConfig.Network == "wireguard" {
|
|
|
setRemote = true
|
|
|
}
|
|
|
+ // collate all the info from our sources into the struct
|
|
|
urbit.Info.Running = isRunning
|
|
|
urbit.Info.Network = shipNetworks[pier]
|
|
|
urbit.Info.URL = fmt.Sprintf("http://%s.local:%d", hostName, dockerConfig.HTTPPort)
|
|
|
@@ -162,11 +175,34 @@ func constructPierInfo(piers []string) (map[string]structs.Urbit, error) {
|
|
|
urbit.Info.DetectBootStatus = bootStatus
|
|
|
urbit.Info.Remote = setRemote
|
|
|
urbit.Info.Vere = dockerConfig.UrbitVersion
|
|
|
+ // and insert the struct into the map we will use as input for the broadcast struct
|
|
|
updates[pier] = urbit
|
|
|
}
|
|
|
return updates, nil
|
|
|
}
|
|
|
|
|
|
+// put together the system[usage] subobject
|
|
|
+func constructSystemInfo() map[string]interface{} {
|
|
|
+ var res map[string]interface{}
|
|
|
+ var ramObj []uint64
|
|
|
+ var diskObj []uint64
|
|
|
+ usedRam, totalRam := system.GetMemory()
|
|
|
+ ramObj = append(ramObj,usedRam,totalRam)
|
|
|
+ cpuUsage := system.GetCPU()
|
|
|
+ usedDisk, freeDisk := system.GetDisk()
|
|
|
+ diskObj = append(diskObj,usedDisk,freeDisk)
|
|
|
+ res = map[string]interface{}{
|
|
|
+ "system":map[string]interface{}{
|
|
|
+ "usage":map[string]interface{}{
|
|
|
+ "ram":ramObj,
|
|
|
+ "cpu":cpuUsage,
|
|
|
+ "disk":diskObj,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
// return a map of ships and their networks
|
|
|
func GetContainerNetworks(containers []string) map[string]string {
|
|
|
res := make(map[string]string)
|