新增#椰奶监控

This commit is contained in:
yeyang
2023-04-21 21:26:15 +08:00
parent b17c086a67
commit 135f111198
6 changed files with 203 additions and 70 deletions

View File

@@ -1,13 +1,13 @@
# 1.2.4
# 1.2.5
* 新增`#椰奶监控`ⁿᵉʷ
# 1.2.1 ~ 1.2.4
* 修改**搜图搜番**正则防止误触发
* 删除`申请头衔`文案
* 修改部分文案
# 1.2.1 ~ 1.2.3
* 优化群违禁词匹配,增加违禁词添加人、添加时间
* 优化群字符列表字符id显示
* 新增可选依赖项`puppeteer-extra``puppeteer-extra-plugin-stealth`

View File

@@ -24,20 +24,19 @@ export class NewState extends plugin {
}
async state (e) {
if (!/椰奶/.test(e.msg) && !Config.Notice.state) return false
if (!State.si) return e.reply('❎ 没有检测到systeminformation依赖请运行"pnpm add systeminformation -w"进行安装')
if (e.msg.includes('监控')) {
let data = {
chartData: JSON.stringify(_.every(_.omit(State.chartData, 'echarts_theme'), _.isEmpty) ? undefined : State.chartData)
}
return await puppeteer.render('state/monitor', {
...data
chartData: JSON.stringify(State.chartData)
}, {
e,
scale: 1.4
})
}
if (!/椰奶/.test(e.msg) && !Config.Notice.state) return false
if (!State.si) return e.reply('❎ 没有检测到systeminformation依赖请运行"pnpm add systeminformation -w"进行安装')
// 防止多次触发
if (interval) { return false } else interval = true
// 系统

View File

@@ -15,14 +15,18 @@ export default new class OSUtils {
this._fsStats = null
this.chartData = {
// 上行
upload: [],
// 下行
download: [],
// 读
readSpeed: [],
// 写
writeSpeed: [],
network: {
// 上行
upload: [],
// 下行
download: []
},
fsStats: {
// 读
readSpeed: [],
// 写
writeSpeed: []
},
// cpu
cpu: [],
// 内存
@@ -39,8 +43,8 @@ export default new class OSUtils {
set network (value) {
if (_.isNumber(value[0]?.tx_sec) && _.isNumber(value[0]?.rx_sec)) {
this._network = value
this.addData(this.chartData.upload, [Date.now(), value[0].tx_sec])
this.addData(this.chartData.download, [Date.now(), value[0].rx_sec])
this.addData(this.chartData.network.upload, [Date.now(), value[0].tx_sec])
this.addData(this.chartData.network.download, [Date.now(), value[0].rx_sec])
}
}
@@ -51,8 +55,8 @@ export default new class OSUtils {
set fsStats (value) {
if (_.isNumber(value?.wx_sec) && _.isNumber(value?.rx_sec)) {
this._fsStats = value
this.addData(this.chartData.writeSpeed, [Date.now(), value.wx_sec])
this.addData(this.chartData.readSpeed, [Date.now(), value.rx_sec])
this.addData(this.chartData.fsStats.writeSpeed, [Date.now(), value.wx_sec])
this.addData(this.chartData.fsStats.readSpeed, [Date.now(), value.rx_sec])
}
}
@@ -161,18 +165,22 @@ export default new class OSUtils {
* @param {boolean} [isSuffix=true] - 如果为 true则在所得到的大小后面加上 kb、mb、gb、tb 等后缀.
* @returns {string} 文件大小格式转换后的字符串.
*/
getFileSize (size = 0, isByte = true, isSuffix = true) {
if (typeof size !== 'number') return '无效参数'
const BYTE_SIZE = 1024
let i = -1
const units = ['B', 'KB', 'MB', 'GB', 'TB']
do {
size = size / BYTE_SIZE
i++
} while (size >= 1 && i < units.length - 1)
const csize = Math.max(size, 0.1).toFixed(2)
return `${csize}${isByte ? '' : ' '}${units[i]}${isSuffix ? ' ' + (isByte ? '' : 'B') : ''}`
getFileSize (size, isByte = true, isSuffix = true) { // 把字节转换成正常文件大小
if (size == null || size == undefined) return 0
let num = 1024.00 // byte
if (isByte && size < num) {
return size.toFixed(2) + 'B'
}
if (size < Math.pow(num, 2)) {
return (size / num).toFixed(2) + `K${isSuffix ? 'b' : ''}`
} // kb
if (size < Math.pow(num, 3)) {
return (size / Math.pow(num, 2)).toFixed(2) + `M${isSuffix ? 'b' : ''}`
} // M
if (size < Math.pow(num, 4)) {
return (size / Math.pow(num, 3)).toFixed(2) + 'G'
} // G
return (size / Math.pow(num, 4)).toFixed(2) + 'T' // T
}
/**

View File

@@ -18,45 +18,82 @@
}
return value.toFixed(0) + units[unitIndex] // 返回带有动态单位标签的字符串
}
var publicOption = {
animation: false,
textStyle: {
fontFamily: 'Number, "汉仪文黑-65W", YS, PingFangSC-Medium, "PingFang SC", sans-serif'
},
grid: {
left: '1%',
right: '1.5%',
bottom: '0',
containLabel: true
},
xAxis: [
{
type: 'time'
}
],
yAxis: [
{
type: 'value',
axisLabel: {
formatter: by
}
}
],
}
</script>
<div class="box">
<div id="Mem"></div>
<div id="cpu" style="height: 300px;"></div>
<script>
const MemData = chartData.mem
const chart = echarts.init(document.getElementById('Mem'), 'westeros', {
const cpuChart = echarts.init(document.getElementById('cpu'), 'westeros', {
renderer: 'svg'
})
chart.setOption({
animation: false,
textStyle: {
fontFamily: 'Number, "汉仪文黑-65W", YS, PingFangSC-Medium, "PingFang SC", sans-serif'
},
cpuChart.setOption(publicOption)
cpuChart.setOption({
title: {
text: 'Mem'
text: 'CPU'
},
legend: {
data: ['主动使用', '缓冲区']
},
grid: {
left: '1%',
right: '1.5%',
bottom: '0',
containLabel: true
},
xAxis: [
{
type: 'time'
}
],
yAxis: [
{
type: 'value',
axisLabel: {
formatter: by
formatter: (value) => parseInt(value) + '%'
}
}
],
series: [
{
name: 'CPU',
type: 'line',
areaStyle: {},
markPoint: {
data: [
{ type: 'max', name: 'Max', label: { formatter: (value) => parseInt(value.value) + '%' } }
]
},
data: chartData.cpu
}
]
})
</script>
</div>
<div class="box">
<div id="RAM" style="height: 300px;"></div>
<script>
const ramChart = echarts.init(document.getElementById('RAM'), 'westeros', {
renderer: 'svg'
})
ramChart.setOption(publicOption)
ramChart.setOption({
title: {
text: 'RAM'
},
legend: {
data: ['主动使用', '缓冲区']
},
series: [
{
name: '主动使用',
@@ -68,7 +105,7 @@
]
},
stacked: true,
data: MemData.active
data: chartData.mem.active
},
{
name: '缓冲区',
@@ -83,7 +120,95 @@
focus: 'series'
},
stacked: true,
data: MemData.buffcache
data: chartData.mem.buffcache
},
]
})
</script>
</div>
<div class="box">
<div id="network" style="height: 300px;"></div>
<script>
const networkChart = echarts.init(document.getElementById('network'), 'westeros', {
renderer: 'svg'
})
networkChart.setOption(publicOption)
networkChart.setOption({
title: {
text: 'Network'
},
legend: {
data: ['上行', '下行']
},
series: [
{
name: '上行',
type: 'line',
areaStyle: {},
markPoint: {
data: [
{ type: 'max', name: 'Max', label: { formatter: by } }
]
},
data: chartData.network.upload
},
{
name: '下行',
type: 'line',
areaStyle: {},
markPoint: {
data: [
{ type: 'max', name: 'Max', label: { formatter: by } }
]
},
emphasis: {
focus: 'series'
},
data: chartData.network.download
},
]
})
</script>
</div>
<div class="box">
<div id="fsStats" style="height: 300px;"></div>
<script>
const fsStatsChart = echarts.init(document.getElementById('fsStats'), 'westeros', {
renderer: 'svg'
})
fsStatsChart.setOption(publicOption)
fsStatsChart.setOption({
title: {
text: 'FsStats'
},
legend: {
data: ['读', '写']
},
series: [
{
name: '读',
type: 'line',
areaStyle: {},
markPoint: {
data: [
{ type: 'max', name: 'Max', label: { formatter: by } }
]
},
data: chartData.fsStats.readSpeed
},
{
name: '写',
type: 'line',
areaStyle: {},
markPoint: {
data: [
{ type: 'max', name: 'Max', label: { formatter: by } }
]
},
emphasis: {
focus: 'series'
},
data: chartData.fsStats.writeSpeed
},
]
})

View File

@@ -1,5 +1,5 @@
.container {
background: url("https://t.lizi.moe/mp") white center top no-repeat;
background: url("https://api.ghser.com/random/pe.php") white center top no-repeat;
background-size: cover;
}

View File

@@ -91,7 +91,7 @@
}
return value.toFixed(0) + units[unitIndex] // 返回带有动态单位标签的字符串
}
chart.setOption({
let option = {
animation: false,
textStyle: {
fontFamily: 'Number, "汉仪文黑-65W", YS, PingFangSC-Medium, "PingFang SC", sans-serif'
@@ -131,7 +131,7 @@
{ type: 'max', name: 'Max', label: { formatter: by } }
]
},
data: chartData.upload
data: chartData.network.upload
},
{
name: '下行',
@@ -142,7 +142,7 @@
{ type: 'max', name: 'Max', label: { formatter: by } }
]
},
data: chartData.download
data: chartData.network.download
},
{
name: '读',
@@ -153,7 +153,7 @@
{ type: 'max', name: 'Max', label: { formatter: by } }
]
},
data: chartData.readSpeed
data: chartData.fsStats.readSpeed
},
{
name: '写',
@@ -164,10 +164,11 @@
{ type: 'max', name: 'Max', label: { formatter: by } }
]
},
data: chartData.writeSpeed
data: chartData.fsStats.writeSpeed
}
]
})
}
chart.setOption(option)
</script>
</div>
{{/if}}