Skip to content

Commit

Permalink
new Func: Status
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffy-melli committed Nov 30, 2024
1 parent f2232b0 commit 2770b6d
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/net/shibadogs/prcm/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.shibadogs.prcm
import net.shibadogs.prcm.command.command
import net.shibadogs.prcm.command.run
import net.shibadogs.prcm.process.flow.newFlow
import net.shibadogs.prcm.process.flow.newFlowStatus
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

Expand All @@ -14,5 +15,6 @@ fun main(args: Array<String>) {
println("Load: $currentDir...")
run(command(args))
runApplication<PRCMServer>()
newFlowStatus()
newFlow()
}
29 changes: 29 additions & 0 deletions src/main/kotlin/net/shibadogs/prcm/process/calculate/status.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.shibadogs.prcm.process.calculate

import net.shibadogs.prcm.server.statusList

fun percent(): MutableMap<Int, Int> {
val result: MutableMap<Int, Int> = mutableMapOf()
for (i in statusList) {
var runs = 0
if (i.value.isEmpty()) {
result[i.key] = 0
continue
}
for (ck in i.value) {
if (ck) {
runs += 1
}
}
if (runs == 0) {
result[i.key] = 0
continue
}
if (runs == i.value.size) {
result[i.key] = 100
continue
}
result[i.key] = (runs.toDouble() / i.value.size * 100).toInt()
}
return result
}
22 changes: 22 additions & 0 deletions src/main/kotlin/net/shibadogs/prcm/process/flow/status.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.shibadogs.prcm.process.flow

import net.shibadogs.prcm.save.loadxml
import net.shibadogs.prcm.server.nodeList
import net.shibadogs.prcm.server.statusList

fun nodeStatus() {
val loadConfigs = loadxml("configs.xml")
for (i in loadConfigs) {
if (statusList.getOrElse(i.value.id) { null } == null) {
statusList[i.value.id] = MutableList(60) {false}
}
if (nodeList.getOrElse(i.value.id) { null } == null) {
statusList[i.value.id]?.add(false)
} else {
statusList[i.value.id]?.add(true)
}
if (statusList[i.value.id]?.size ?: 0 >= 60) {
statusList[i.value.id]?.subList(0, statusList[i.value.id]!!.size - 60)?.clear()
}
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/net/shibadogs/prcm/process/flow/threads.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ fun newFlow() {
label = label.takeLast(20).toMutableList()
}
}, 0, 5, TimeUnit.SECONDS)
}

fun newFlowStatus() {
val scheduler = Executors.newSingleThreadScheduledExecutor()
scheduler.scheduleAtFixedRate({
nodeStatus()
}, 0, 1, TimeUnit.MINUTES)
}
7 changes: 3 additions & 4 deletions src/main/kotlin/net/shibadogs/prcm/process/manager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package net.shibadogs.prcm.process
import net.shibadogs.prcm.save.Config
import net.shibadogs.prcm.save.loadxml
import net.shibadogs.prcm.save.savexml
import net.shibadogs.prcm.server.logList
import net.shibadogs.prcm.server.memoryUsageList
import net.shibadogs.prcm.server.nodeList
import net.shibadogs.prcm.server.processlist
import net.shibadogs.prcm.server.*
import java.io.BufferedReader
import java.io.InputStreamReader
import java.time.Instant
Expand Down Expand Up @@ -123,6 +120,7 @@ fun del(id: Int) : Boolean {

logList.remove(id)
memoryUsageList.remove(id)
statusList.remove(id)
return true
}

Expand All @@ -147,5 +145,6 @@ fun edit(id: Int, config: Config) : Boolean {

logList.remove(id)
memoryUsageList.remove(id)
statusList.remove(id)
return true
}
1 change: 1 addition & 0 deletions src/main/kotlin/net/shibadogs/prcm/server/heap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.shibadogs.prcm.server
import net.shibadogs.prcm.process.Builder

var label: MutableList<String> = MutableList(20) {"x"}
var statusList: MutableMap<Int, MutableList<Boolean>> = mutableMapOf()
var logList: MutableMap<Int, StringBuilder> = mutableMapOf()
var nodeList: MutableMap<Int, Builder> = mutableMapOf()
var processlist: MutableMap<Int, Process> = mutableMapOf()
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/net/shibadogs/prcm/server/router.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.shibadogs.prcm.server

import net.shibadogs.prcm.process.*
import net.shibadogs.prcm.process.calculate.percent
import net.shibadogs.prcm.save.Config
import net.shibadogs.prcm.save.loadxml
import org.springframework.web.bind.annotation.*
Expand All @@ -17,6 +18,11 @@ class Router {
return loadxml("configs.xml")
}

@GetMapping("/api/node/status-percent")
fun statusNode(): MutableMap<Int, Int> {
return percent()
}

@GetMapping("/api/node/get-log/{number}")
fun getLog(@PathVariable number: Int): StringBuilder {
if (logList.getOrElse(number) { null } == null) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ <h2 class="nodelist-title">Node-List</h2>
</form>
</div>
</div>
<div v-if="Object.keys(node.status).length != 0">
<p class="status-header">Status</p>
<p v-for="[key, value] of Object.entries(node.status)" class="status-item">
<span class="status-key">[{{ key }}]</span> <span class="status-value">{{ value }}%</span>
</p>
</div>
</div>
</div>
<div v-else class="node-info">
Expand Down Expand Up @@ -139,6 +145,12 @@ <h2 class="nodelist-title">Node-List</h2>
</form>
</div>
</div>
<div>
<p class="status-header">Status</p>
<p class="status-item">
<span class="status-key"></span><span class="status-value">{{node.status[node.view]}}%</span>
</p>
</div>
<div class="toggle">
<div class="log">
<pre v-if="(node.view in node.running)">PID : {{node.running[node.view].processInfo.pid}}</pre>
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ new Vue({
label: [],
memory: []
},
status: null
},
formData: {
file: '',
Expand All @@ -29,12 +30,20 @@ new Vue({
}
},
mounted() {
this.statusnodes()
this.loadnodes()
setInterval(() => {
this.loadnodes()
}, 2000)
setInterval(() => {
this.statusnodes()
}, 60000)
},
methods: {
async statusnodes() {
const NodeStatus = await axios.get('/api/node/status-percent')
this.node.status = NodeStatus.data
},
async loadnodes() {
const nodeConfig = await axios.get('/api/get-config')
this.node.config = nodeConfig.data
Expand Down
32 changes: 32 additions & 0 deletions src/main/resources/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,38 @@ body {
border-color: #ccc;
}

.status-header {
font-weight: bold;
color: #4A90E2;
margin-bottom: 10px;
text-align: center;
}

.status-item {
display: flex;
justify-content: space-between;
font-size: 1.1rem;
margin-bottom: 10px;
padding: 8px 12px;
border-radius: 5px;
background-color: #f4f7fc;
transition: background-color 0.3s ease;
}

.status-item:hover {
background-color: #e1e9f4;
}

.status-key {
font-weight: bold;
color: #333;
}

.status-value {
font-weight: normal;
color: #4CAF50;
}

.green {}

.red {}

0 comments on commit 2770b6d

Please sign in to comment.