This commit is contained in:
赵鑫 2022-09-08 11:24:02 +08:00
parent f8beaa95b1
commit 67c81173ab
4 changed files with 67 additions and 17 deletions

30
package-lock.json generated
View File

@ -13,6 +13,8 @@
"compression": "^1.7.4",
"dotenv": "^16.0.2",
"express": "^4.18.1",
"filesize": "^9.0.11",
"moment": "^2.29.4",
"mongoose": "^6.5.4",
"pug": "^3.0.2",
"socket.io": "^4.5.2"
@ -673,6 +675,15 @@
"node": ">= 0.10.0"
}
},
"node_modules/filesize": {
"version": "9.0.11",
"resolved": "https://mirrors.cloud.tencent.com/npm/filesize/-/filesize-9.0.11.tgz",
"integrity": "sha512-gTAiTtI0STpKa5xesyTA9hA3LX4ga8sm2nWRcffEa1L/5vQwb4mj2MdzMkoHoGv4QzfDshQZuYscQSf8c4TKOA==",
"license": "BSD-3-Clause",
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/fill-range": {
"version": "7.0.1",
"resolved": "https://mirrors.cloud.tencent.com/npm/fill-range/-/fill-range-7.0.1.tgz",
@ -1084,6 +1095,15 @@
"node": "*"
}
},
"node_modules/moment": {
"version": "2.29.4",
"resolved": "https://mirrors.cloud.tencent.com/npm/moment/-/moment-2.29.4.tgz",
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==",
"license": "MIT",
"engines": {
"node": "*"
}
},
"node_modules/mongodb": {
"version": "4.8.1",
"resolved": "https://mirrors.cloud.tencent.com/npm/mongodb/-/mongodb-4.8.1.tgz",
@ -2493,6 +2513,11 @@
"vary": "~1.1.2"
}
},
"filesize": {
"version": "9.0.11",
"resolved": "https://mirrors.cloud.tencent.com/npm/filesize/-/filesize-9.0.11.tgz",
"integrity": "sha512-gTAiTtI0STpKa5xesyTA9hA3LX4ga8sm2nWRcffEa1L/5vQwb4mj2MdzMkoHoGv4QzfDshQZuYscQSf8c4TKOA=="
},
"fill-range": {
"version": "7.0.1",
"resolved": "https://mirrors.cloud.tencent.com/npm/fill-range/-/fill-range-7.0.1.tgz",
@ -2758,6 +2783,11 @@
"brace-expansion": "^1.1.7"
}
},
"moment": {
"version": "2.29.4",
"resolved": "https://mirrors.cloud.tencent.com/npm/moment/-/moment-2.29.4.tgz",
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w=="
},
"mongodb": {
"version": "4.8.1",
"resolved": "https://mirrors.cloud.tencent.com/npm/mongodb/-/mongodb-4.8.1.tgz",

View File

@ -20,6 +20,8 @@
"compression": "^1.7.4",
"dotenv": "^16.0.2",
"express": "^4.18.1",
"filesize": "^9.0.11",
"moment": "^2.29.4",
"mongoose": "^6.5.4",
"pug": "^3.0.2",
"socket.io": "^4.5.2"

View File

@ -4,6 +4,8 @@ require('dotenv').config()
// Express
const express = require('express')
const compression = require('compression')
const moment = require('moment')
const filesize = require('filesize').partial({base: 2, standard: "jedec"})
const app = express()
app.set('view engine', 'pug')
app.use(compression())
@ -11,6 +13,9 @@ app.use(express.static('public'))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use('/', require('./routers/home'))
app.locals.moment = moment
app.locals.moment.locale('zh-cn')
app.locals.filesize = filesize
const PORT = process.env.PORT || 3000
const server = app.listen(PORT, () => console.log(`zhao server running at port ${PORT}`))

View File

@ -180,21 +180,34 @@ block main
| 内存剩余:
code#pi_mem
| 字节
script(src="//zhao/status/socket.io/socket.io.min.js")
script.
function get_rpis_status() {
fetch(new Request('http://zhao/status'))
.then(resp => resp.json())
.then(data => {
zhao_temp.innerText = data.cpu.temperature.toFixed(2)
zhao_cpu.innerText = (data.cpu.load).toFixed(2)
zhao_mem.innerText = data.memory.available
})
fetch(new Request('http://pi/status'))
.then(resp => resp.json())
.then(data => {
pi_temp.innerText = data.cpu.temperature.toFixed(2)
pi_cpu.innerText = (data.cpu.load).toFixed(2)
pi_mem.innerText = data.memory.available
})
}
setInterval(get_rpis_status, 1000)
const zhao = io('ws://zhao', { path: '/status/socket.io', })
zhao.on('status', (status) => {
zhao_temp.innerText = status.cpu.temperature.toFixed(2)
zhao_cpu.innerText = status.cpu.load.toFixed(2)
zhao_mem.innerText = status.memory.available
})
const pi = io('ws://pi', { path: '/status/socket.io', })
pi.on('status', (status) => {
pi_temp.innerText = status.cpu.temperature.toFixed(2)
pi_cpu.innerText = status.cpu.load.toFixed(2)
pi_mem.innerText = status.memory.available
})
//- function get_rpis_status() {
//- fetch(new Request('http://zhao/status'))
//- .then(resp => resp.json())
//- .then(data => {
//- zhao_temp.innerText = data.cpu.temperature.toFixed(2)
//- zhao_cpu.innerText = (data.cpu.load).toFixed(2)
//- zhao_mem.innerText = data.memory.available
//- })
//- fetch(new Request('http://pi/status'))
//- .then(resp => resp.json())
//- .then(data => {
//- pi_temp.innerText = data.cpu.temperature.toFixed(2)
//- pi_cpu.innerText = (data.cpu.load).toFixed(2)
//- pi_mem.innerText = data.memory.available
//- })
//- }
//- setInterval(get_rpis_status, 1000)