Fix status
This commit is contained in:
parent
c45c27ac38
commit
7d6e9c0ae6
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ rosti.db
|
||||
node-api
|
||||
.history/
|
||||
api-node-17.http
|
||||
*-packr.go
|
||||
|
@ -100,13 +100,7 @@ func (d *Driver) Status(name string) (string, error) {
|
||||
return status, err
|
||||
}
|
||||
|
||||
if info.State.Running {
|
||||
status = "running"
|
||||
} else {
|
||||
status = "stopped"
|
||||
}
|
||||
|
||||
return status, nil
|
||||
return info.State.Status, nil
|
||||
|
||||
}
|
||||
|
||||
@ -308,8 +302,8 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i
|
||||
Resources: container.Resources{
|
||||
CPUPeriod: 100000,
|
||||
CPUQuota: int64(CPU) * 1000,
|
||||
Memory: int64(memory*110/100)*1024 ^ 3, // Allow 10 % more memory so we have space for MemoryReservation
|
||||
MemoryReservation: int64(memory)*1024 ^ 3, // This should provide softer way how to limit the memory of our containers
|
||||
Memory: int64(memory*110/100) * 1024 * 1024, // Allow 10 % more memory so we have space for MemoryReservation
|
||||
MemoryReservation: int64(memory) * 1024 * 1024, // This should provide softer way how to limit the memory of our containers
|
||||
},
|
||||
PortBindings: portmaps,
|
||||
AutoRemove: false,
|
||||
|
12
main.go
12
main.go
@ -26,7 +26,7 @@ func main() {
|
||||
// Stats loop
|
||||
go func() {
|
||||
for {
|
||||
err := gatherContainerStats()
|
||||
err := gatherContainersStats()
|
||||
if err != nil {
|
||||
log.Println("LOOP ERROR:", err.Error())
|
||||
}
|
||||
@ -148,6 +148,8 @@ func main() {
|
||||
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
|
||||
}
|
||||
|
||||
go updateContainerStats(&app)
|
||||
|
||||
return c.JSON(http.StatusOK, Message{Message: "ok"})
|
||||
})
|
||||
|
||||
@ -169,6 +171,8 @@ func main() {
|
||||
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
|
||||
}
|
||||
|
||||
go updateContainerStats(app)
|
||||
|
||||
return c.JSON(http.StatusOK, Message{Message: "ok"})
|
||||
})
|
||||
|
||||
@ -190,6 +194,8 @@ func main() {
|
||||
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
|
||||
}
|
||||
|
||||
go updateContainerStats(app)
|
||||
|
||||
return c.JSON(http.StatusOK, Message{Message: "ok"})
|
||||
})
|
||||
|
||||
@ -211,6 +217,8 @@ func main() {
|
||||
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
|
||||
}
|
||||
|
||||
go updateContainerStats(app)
|
||||
|
||||
return c.JSON(http.StatusOK, Message{Message: "ok"})
|
||||
})
|
||||
|
||||
@ -263,6 +271,8 @@ func main() {
|
||||
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
|
||||
}
|
||||
|
||||
go updateContainerStats(app)
|
||||
|
||||
return c.JSON(http.StatusOK, Message{Message: "ok"})
|
||||
})
|
||||
|
||||
|
43
stats.go
43
stats.go
@ -7,32 +7,35 @@ import (
|
||||
"github.com/rosti-cz/node-api/docker"
|
||||
)
|
||||
|
||||
// gatherContainerStats gathers information about containers and saves it into the database
|
||||
func gatherContainerStats() error {
|
||||
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 {
|
||||
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,
|
||||
)
|
||||
|
||||
err := updateContainerStats(&app)
|
||||
if err != nil {
|
||||
log.Println("STATS ERROR:", err.Error())
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
|
||||
<title>Bare - Start Bootstrap Template</title>
|
||||
<title>Node manager</title>
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet">
|
||||
@ -38,7 +38,12 @@
|
||||
<h1 class="mt-5">Node</h1>
|
||||
|
||||
<p>
|
||||
Load index: <em>12</em>
|
||||
Overall index: <em>{( node.index.toFixed(2) )}</em><br>
|
||||
Load 1 index: <em>{( node.load1_index.toFixed(2) )}</em><br>
|
||||
Load 5 index: <em>{( node.load5_index.toFixed(2) )}</em><br>
|
||||
Load 15 index: <em>{( node.load15_index.toFixed(2) )}</em><br>
|
||||
Memory index: <em>{( node.memory_index.toFixed(2) )}</em><br>
|
||||
Disk space index: <em>{( node.disk_space_index.toFixed(2) )}</em>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@ -67,19 +72,19 @@
|
||||
<tbody>
|
||||
<tr v-for="app in apps">
|
||||
<td><strong>{( app.name )}</strong></td>
|
||||
<td>{( app.state.state )}</td>
|
||||
<td>{( app.state )}</td>
|
||||
<td>{( app.image.replace("docker.io/", "") )}</td>
|
||||
<td>{( app.cpu_usage )} % / {( app.cpu )} %</td>
|
||||
<td>{( app.memory_usage )} MB / {( app.memory )} MB</td>
|
||||
<td>{( (app.cpu_usage).toFixed(2) )} % / {( app.cpu )} %</td>
|
||||
<td>{( (app.memory_usage/1000/1000).toFixed(2) )} MB / {( app.memory )} MB</td>
|
||||
<td>{( (app.disk_usage_bytes / 1000 / 1000 / 1000).toFixed(2) )} GB</td>
|
||||
<td>{( app.disk_usage_inodes )}</td>
|
||||
<td>
|
||||
<span v-for="label in app.labels" class="label label-info">{( label.value )}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-success btn-sm" v-on:click="start(app.name)" v-if="['stopped'].includes(app.state.state)">Start</button>
|
||||
<button class="btn btn-warning btn-sm" v-on:click="stop(app.name)" v-if="['running'].includes(app.state.state)">Stop</button>
|
||||
<button class="btn btn-warning btn-sm" v-on:click="restart(app.name)" v-if="['running'].includes(app.state.state)">Restart</button>
|
||||
<button class="btn btn-success btn-sm" v-on:click="start(app.name)" v-if="['stopped', 'created'].includes(app.state)">Start</button>
|
||||
<button class="btn btn-warning btn-sm" v-on:click="stop(app.name)" v-if="['running'].includes(app.state)">Stop</button>
|
||||
<button class="btn btn-warning btn-sm" v-on:click="restart(app.name)" v-if="['running'].includes(app.state)">Restart</button>
|
||||
<button class="btn btn-warning btn-sm" v-on:click="rebuild(app.name)">Rebuild</button>
|
||||
<button class="btn btn-danger btn-sm" v-on:click="remove(app.name)">Delete</button>
|
||||
</td>
|
||||
@ -102,10 +107,13 @@
|
||||
apps: [],
|
||||
api_status_code: 0,
|
||||
api_response: "",
|
||||
node: {},
|
||||
},
|
||||
created() {
|
||||
fetch('/v1/apps').then(response => response.json())
|
||||
.then(data => this.apps = data);
|
||||
fetch('/v1/node').then(response => response.json())
|
||||
.then(data => this.node = data);
|
||||
},
|
||||
methods: {
|
||||
isSuccess: () => {
|
||||
|
Loading…
Reference in New Issue
Block a user