refactored main page to not use xhr, added thread ui stat area

This commit is contained in:
Kevin Froman 2020-03-20 03:46:33 -05:00
parent b5ac1ed7d8
commit b2f4dae226
3 changed files with 83 additions and 47 deletions

View File

@ -262,6 +262,13 @@
Blocks in queue: <span id="blockQueue"></span> Blocks in queue: <span id="blockQueue"></span>
</div> </div>
</div> </div>
<h6>Process Info</h6>
<div class="columns">
<div class="column">
<i class="fas fa-microchip"></i>
Current CPU threads: <span id="threads"></span>
</div>
</div>
</div> </div>
</div> </div>

View File

@ -55,7 +55,14 @@ function seconds2time (seconds) {
return time return time
} }
switch (httpGet('/config/get/general.security_level')){
fetch('/config/get/general.security_level', {
headers: {
"token": webpass
}})
.then((resp) => resp.text()) // Transform the data into text
.then(function(resp) {
switch(resp){
case "0": case "0":
sec_description_str = 'normal' sec_description_str = 'normal'
break; break;
@ -69,13 +76,18 @@ switch (httpGet('/config/get/general.security_level')){
sec_description_str = 'extreme' sec_description_str = 'extreme'
break; break;
} }
if (sec_description_str !== 'normal'){ if (sec_description_str !== 'normal'){
showSecStatNotice() showSecStatNotice()
} }
})
function getStats(){ var getStats = function(){
stats = JSON.parse(httpGet('getstats', webpass)) fetch('/getstats', {
headers: {
"token": webpass
}})
.then((resp) => resp.json())
.then(function(stats) {
uptimeDisplay.innerText = seconds2time(stats['uptime']) uptimeDisplay.innerText = seconds2time(stats['uptime'])
connectedNodes = stats['connectedNodes'].split('\n') connectedNodes = stats['connectedNodes'].split('\n')
connectedDisplay.innerText = '' connectedDisplay.innerText = ''
@ -86,12 +98,26 @@ function getStats(){
} }
storedBlockDisplay.innerText = stats['blockCount'] storedBlockDisplay.innerText = stats['blockCount']
queuedBlockDisplay.innerText = stats['blockQueueCount'] queuedBlockDisplay.innerText = stats['blockQueueCount']
document.getElementById('threads').innerText = stats['threads']
securityLevel.innerText = sec_description_str securityLevel.innerText = sec_description_str
totalRec.innerText = httpGet('/hitcount') fetch('/hitcount', {
var lastConnect = httpGet('/lastconnect') headers: {
"token": webpass
}})
.then((resp) => resp.text())
.then(function(totalRec) {
totalRec.innerText = totalRec
})
fetch('/lastconnect', {
headers: {
"token": webpass
}})
.then((resp) => resp.text())
.then(function(conn) {
var lastConnect = conn
if (lastConnect > 0){ if (lastConnect > 0){
var humanDate = new Date(0) var humanDate = new Date(0)
humanDate.setUTCSeconds(httpGet('/lastconnect')) humanDate.setUTCSeconds(conn)
humanDate = humanDate.toString() humanDate = humanDate.toString()
lastConnect = humanDate.substring(0, humanDate.indexOf('(')); lastConnect = humanDate.substring(0, humanDate.indexOf('('));
} }
@ -99,6 +125,9 @@ function getStats(){
lastConnect = 'None since start' lastConnect = 'None since start'
} }
lastIncoming.innerText = lastConnect lastIncoming.innerText = lastConnect
})
})
} }
getStats() getStats()
setInterval(function(){getStats()}, 10000) setInterval(function(){getStats()}, 10000)