Skip to content

Commit

Permalink
log update
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffy-melli committed Nov 24, 2024
1 parent 9e629ed commit 257d349
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/main/kotlin/net/shibadogs/prcm/process/flow/threads.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.shibadogs.prcm.process.flow

import net.shibadogs.prcm.process.getShortTime
import net.shibadogs.prcm.server.label
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
Expand All @@ -8,7 +9,7 @@ fun newFlow() {
val scheduler = Executors.newSingleThreadScheduledExecutor()
scheduler.scheduleAtFixedRate({
useMemory()
label.add(System.currentTimeMillis() / 1000)
label.add(getShortTime())
if (label.size >= 20) {
label = label.takeLast(20).toMutableList()
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/net/shibadogs/prcm/process/manager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,27 @@ fun run(processInfo: Builder) : Int {
processInfo.status.exit = false
var line: String?
val process = processBuilder.start()
var time = getTime()
val startLogger = "[$time] ${processInfo.node.node} ${processInfo.node.filepath} ${processInfo.node.args.joinToString(" ")} ERR:[${processInfo.status.errCount}/10] PID:${PID(process)}"
logList[processInfo.status.id]?.append(startLogger)?.append("\n")
nodeList[processInfo.status.id] = processInfo
processlist[processInfo.status.id] = process
processInfo.processInfo.pid = PID(process)
val standardOutputReader = BufferedReader(InputStreamReader(process.inputStream, "UTF-8"))
while (standardOutputReader.readLine().also { line = it } != null) {
logList[processInfo.status.id]?.append(line)?.append("\n")
time = getTime()
logList[processInfo.status.id]?.append("[$time] $line")?.append("\n")
}
val errorOutputReader = BufferedReader(InputStreamReader(process.errorStream, "UTF-8"))
while (errorOutputReader.readLine().also { line = it } != null) {
logList[processInfo.status.id]?.append(line)?.append("\n")
time = getTime()
logList[processInfo.status.id]?.append("[$time] $line")?.append("\n")
}
memoryUsageList[processInfo.status.id]?.plus(MemoryUsage(processInfo.processInfo.pid))
val exit = process.waitFor()
time = getTime()
val endLogger = "[$time] Exit: $exit"
logList[processInfo.status.id]?.append(endLogger)?.append("\n")
processInfo.status.endTime = Instant.now().epochSecond
processInfo.status.exit = true
processInfo.status.exitCode = exit
Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/net/shibadogs/prcm/process/time.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.shibadogs.prcm.process

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

fun getTime() : String {
val currentDateTime = LocalDateTime.now()
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
val time = currentDateTime.format(formatter)
return time
}

fun getShortTime() : String {
val currentDateTime = LocalDateTime.now()
val formatter = DateTimeFormatter.ofPattern("HH:mm:ss")
val time = currentDateTime.format(formatter)
return time
}
2 changes: 1 addition & 1 deletion src/main/kotlin/net/shibadogs/prcm/server/heap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package net.shibadogs.prcm.server

import net.shibadogs.prcm.process.Builder

var label: MutableList<Long> = MutableList(20) {0}
var label: MutableList<String> = MutableList(20) {"x"}
var logList: MutableMap<Int, StringBuilder> = mutableMapOf()
var nodeList: MutableMap<Int, Builder> = mutableMapOf()
var processlist: MutableMap<Int, Process> = mutableMapOf()
Expand Down
19 changes: 11 additions & 8 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,19 @@ <h2 class="nodelist-title">Node-List</h2>
</div>
<div class="node-info" v-if="node.config && node.running">
<div v-if="Object.keys(node.config).length != 0">
<canvas class="chart-usage-memory" id="chart-usage-memory"></canvas>
<div>
<h2 v-if="(node.view in node.running) && node.running[node.view].processInfo.pid != -1" @click="nodestop(node.view)">STOP</h2>
<h2 v-else @click="nodestart(node.view)">START</h2>
<div class="chart">
<canvas class="chart-usage-memory" id="chart-usage-memory"></canvas>
</div>
<h2>{{node.config[node.view].node}} {{node.config[node.view].path}} {{node.config[node.view].args.join(' ')}}</h2>
<div v-if="(node.view in node.running)">
<p>PID : {{node.running[node.view].processInfo.pid}}</p>
<div class="toggle">
<div class="command">
<h2 v-if="(node.view in node.running) && node.running[node.view].processInfo.pid != -1" @click="nodestop(node.view)">STOP</h2>
<h2 v-else @click="nodestart(node.view)">START</h2>
<p v-if="(node.view in node.running)">PID : {{node.running[node.view].processInfo.pid}}</p>
</div>
<div class="log">
<pre>{{node.log}}</pre>
</div>
</div>
<pre>{{node.log}}</pre>
</div>
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ new Vue({
this.loadnodes()
}, 2000)
},
beforeDestroy() {
window.removeEventListener('resize', this.resizeChart)
},
methods: {
async loadnodes() {
const response1 = await axios.get('/api/get-config')
Expand Down Expand Up @@ -136,7 +139,9 @@ new Vue({
},
animation: {
duration: 0
}
},
responsive: true,
maintainAspectRatio: false
}
})
}
Expand Down
45 changes: 39 additions & 6 deletions src/main/resources/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
src: url('https://fastly.jsdelivr.net/gh/projectnoonnu/[email protected]/NanumBarunpen.woff') format('woff');
}

html {
width: 100%;
height: 100%;
margin: 0;
}

body {
font-family: 'Nanum-Bold', sans-serif;
margin: 0;
Expand Down Expand Up @@ -44,7 +50,37 @@ body {
position: relative;
}

#chart-usage-memory {
position: relative;
width: 95%;
height: 300px;
top: 0px;
}

.node-info .toggle {
position: absolute;
width: 90%;
}

.node-info .toggle .log {
margin-right: 10px;
position: relative;
width: 90%;
height: auto;
}

.node-info .toggle .log pre {
position: absolute;
width: 100%;
}

.node-info .command {
position: relative;
font-size: 15px;
}

.node-info h2 {
position: relative;
margin-right: 20px;
}

Expand Down Expand Up @@ -84,9 +120,6 @@ body {
background-color: rgb(66, 155, 71);
}

.chart-usage-memory {
position: relative;
width: 95%;
height: 300px;
top: 0px;
}
.green {}

.red {}

0 comments on commit 257d349

Please sign in to comment.