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