⚡️ 优化状态
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
# 1.2.8
|
||||
|
||||
* 增加状态配置文件`config/state.yaml`
|
||||
* 增加网址测试超时时间配置
|
||||
* 增加网址测试配置
|
||||
* 将`whole.yaml`状态相关配置移入`state.yaml`
|
||||
* 优化状态异步任务使用`Promise.all`
|
||||
|
||||
# 1.2.7
|
||||
|
||||
* 删除依赖`puppeteer-extra``puppeteer-extra-plugin-stealth`
|
||||
|
||||
@@ -8,9 +8,7 @@ import { setu, puppeteer } from '../model/index.js'
|
||||
const OtherCfgType = {
|
||||
全部通知: 'notificationsAll',
|
||||
状态: 'state',
|
||||
陌生人点赞: 'Strangers_love',
|
||||
// 给有问题的用户关闭定时器
|
||||
状态任务: 'statusTask'
|
||||
陌生人点赞: 'Strangers_love'
|
||||
}
|
||||
const SeSeCfgType = {
|
||||
涩涩: 'sese',
|
||||
|
||||
@@ -44,18 +44,42 @@ export class NewState extends plugin {
|
||||
// 防止多次触发
|
||||
if (interval) { return false } else interval = true
|
||||
// 系统
|
||||
let osinfo = await State.si.osInfo()
|
||||
let FastFetch; let HardDisk
|
||||
let otherInfo = []
|
||||
// 其他信息
|
||||
otherInfo.push({
|
||||
first: '系统',
|
||||
tail: State.osInfo?.distro
|
||||
})
|
||||
// 网络
|
||||
otherInfo.push(State.getnetwork)
|
||||
// 插件数量
|
||||
otherInfo.push(State.getPluginNum)
|
||||
let promiseTaskList = [
|
||||
State.getFastFetch(e).then(res => { FastFetch = res }),
|
||||
State.getFsSize().then(res => { HardDisk = res })
|
||||
]
|
||||
|
||||
// 网络测试
|
||||
let psTest = []
|
||||
let { psTestSites, psTestTimeout } = Config.state
|
||||
psTestSites && promiseTaskList.push(...psTestSites?.map(i => State.getNetworkLatency(i.url, psTestTimeout).then(res => psTest.push({
|
||||
first: i.name,
|
||||
tail: res
|
||||
}))))
|
||||
// 执行promise任务
|
||||
await Promise.all(promiseTaskList)
|
||||
// 可视化数据
|
||||
let visualData = _.compact([
|
||||
let visualData = _.compact(await Promise.all([
|
||||
// CPU板块
|
||||
await State.getCpuInfo(osinfo.arch),
|
||||
State.getCpuInfo(),
|
||||
// 内存板块
|
||||
await State.getMemUsage(),
|
||||
State.getMemUsage(),
|
||||
// GPU板块
|
||||
await State.getGPU(),
|
||||
State.getGPU(),
|
||||
// Node板块
|
||||
await State.getNodeInfo()
|
||||
])
|
||||
State.getNodeInfo()
|
||||
]))
|
||||
// 渲染数据
|
||||
let data = {
|
||||
chartData: JSON.stringify(common.checkIfEmpty(State.chartData, ['echarts_theme', 'cpu', 'ram']) ? undefined : State.chartData),
|
||||
@@ -76,30 +100,30 @@ export class NewState extends plugin {
|
||||
// 图片
|
||||
screenshot: await redis.get('Yz:count:screenshot:total') || 0,
|
||||
// nodejs版本
|
||||
nodeversion: process.version,
|
||||
nodeVersion: process.version,
|
||||
// 群数
|
||||
group_quantity: Array.from(this.Bot.gl.values()).length,
|
||||
groupQuantity: Array.from(this.Bot.gl.values()).length,
|
||||
// 好友数
|
||||
friend_quantity: Array.from(this.Bot.fl.values()).length,
|
||||
friendQuantity: Array.from(this.Bot.fl.values()).length,
|
||||
// 登陆设备
|
||||
platform: platform[this.Bot.config?.platform],
|
||||
// 在线状态
|
||||
status: status[this.Bot.status],
|
||||
// 硬盘内存
|
||||
HardDisk: await State.getFsSize(),
|
||||
HardDisk,
|
||||
// FastFetch
|
||||
FastFetch: await State.getFastFetch(e),
|
||||
// 取插件
|
||||
plugin: State.numberOfPlugIns,
|
||||
FastFetch,
|
||||
// 硬盘速率
|
||||
fsStats: State.DiskSpeed,
|
||||
// 网络
|
||||
network: State.getnetwork,
|
||||
// 可视化数据
|
||||
visualData,
|
||||
// 系统信息
|
||||
osinfo
|
||||
// 系统平台
|
||||
osPlatform: State.osInfo?.platform,
|
||||
// 其他数据
|
||||
otherInfo: _.compact(otherInfo),
|
||||
psTest: _.isEmpty(psTest) ? false : psTest
|
||||
}
|
||||
|
||||
// 渲染图片
|
||||
await puppeteer.render('state/state', {
|
||||
...data
|
||||
@@ -107,6 +131,7 @@ export class NewState extends plugin {
|
||||
e,
|
||||
scale: 1.4
|
||||
})
|
||||
|
||||
interval = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,11 @@ class Config {
|
||||
return this.getDefOrConfig('setu')
|
||||
}
|
||||
|
||||
/** 状态 */
|
||||
get state () {
|
||||
return this.getDefOrConfig('state')
|
||||
}
|
||||
|
||||
/** 默认配置和用户配置 */
|
||||
getDefOrConfig (name) {
|
||||
let def = this.getdefSet(name)
|
||||
|
||||
18
config/default_config/state.yaml
Normal file
18
config/default_config/state.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
#网址测试超时时间
|
||||
psTestTimeout: 5000
|
||||
|
||||
# 测试访问的网址列表(可空)
|
||||
# name: 显示名称
|
||||
# url: 要访问的网址
|
||||
psTestSites: false
|
||||
# psTestSites:
|
||||
# - name: Baidu
|
||||
# url: https://baidu.com
|
||||
# - name: Google
|
||||
# url: https://google.com
|
||||
|
||||
#监控任务
|
||||
statusTask: true
|
||||
|
||||
#如果出现内存异常的情况可将此配置项开启,如果打开后报错请将监控任务关闭
|
||||
statusPowerShellStart: false
|
||||
@@ -23,8 +23,5 @@ sese: false #涩涩
|
||||
state: false #状态
|
||||
deltime: 600 #删除缓存
|
||||
sesepro: false #涩涩增强
|
||||
statusTask: true #状态网速定时器
|
||||
renderScale: 100 #渲染精度
|
||||
anonymous: false #匿名
|
||||
#如果出现内存异常的情况可将此配置项开启,如果打开后报错请将状态定时器关闭
|
||||
statusPowerShellStart: false
|
||||
|
||||
@@ -152,13 +152,6 @@ export function supportGuoba () {
|
||||
bottomHelpMessage: '是否将椰奶状态作为默认状态',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
field: 'whole.statusTask',
|
||||
label: '状态任务',
|
||||
helpMessage: '关闭后不再读取网速和硬盘速率',
|
||||
bottomHelpMessage: '如果出现许多cmd进程占用或控制台输出乱码可尝试关闭此选项',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
field: 'whole.notificationsAll',
|
||||
label: '通知全部管理',
|
||||
|
||||
@@ -76,10 +76,10 @@ export default new class {
|
||||
* @async
|
||||
* @function
|
||||
* @param {string} url - 请求的URL
|
||||
* @param {import('node-fetch').RequestInit} [options={}] - 请求的配置项
|
||||
* @param {Object} [options.params] - 请求的参数
|
||||
* @param {Object} [options.headers] - 请求的HTTP头部
|
||||
* @param {Object} [options.data] - 请求的数据
|
||||
* @param {object} [options={}] - 请求的配置项
|
||||
* @param {object} [options.params] - 请求的参数
|
||||
* @param {object} [options.headers] - 请求的HTTP头部
|
||||
* @param {object} [options.data] - 请求的数据
|
||||
* @param {boolean} [options.closeCheckStatus=false] - 是否关闭状态检查
|
||||
* @param {'buffer'|'json'|'text'|'arrayBuffer'|'formData'|'blob'} [options.statusCode] - 期望的返回数据,如果设置了该值,则返回响应数据的特定的方法(如json()、text()等)
|
||||
* @returns {Promise<Response|*>} - HTTP响应或响应数据
|
||||
|
||||
120
model/State.js
120
model/State.js
@@ -3,10 +3,12 @@ import _ from 'lodash'
|
||||
import fs from 'fs'
|
||||
import { common } from './index.js'
|
||||
import { Config, Data } from '../components/index.js'
|
||||
import request from '../lib/request/request.js'
|
||||
|
||||
export default new class {
|
||||
constructor () {
|
||||
this.si = null
|
||||
this.osInfo = null
|
||||
// 是否可以获取gpu
|
||||
this.isGPU = false
|
||||
// 网络
|
||||
@@ -72,6 +74,7 @@ export default new class {
|
||||
async initDependence () {
|
||||
try {
|
||||
this.si = await import('systeminformation')
|
||||
this.osInfo = await this.si.osInfo()
|
||||
return this.si
|
||||
} catch (error) {
|
||||
if (error.stack?.includes('Cannot find package')) {
|
||||
@@ -97,33 +100,42 @@ export default new class {
|
||||
this.isGPU = true
|
||||
}
|
||||
// 给有问题的用户关闭定时器
|
||||
if (!Config.whole.statusTask) return
|
||||
|
||||
if (Config.whole.statusPowerShellStart) this.si.powerShellStart()
|
||||
if (!Config.state.statusTask) return
|
||||
|
||||
if (Config.state.statusPowerShellStart) this.si.powerShellStart()
|
||||
this.getData()
|
||||
// 网速
|
||||
const Timer = setInterval(async () => {
|
||||
let data = await this.si.get(this.valueObject)
|
||||
_.forIn(data, (value, key) => {
|
||||
if (_.isEmpty(value)) {
|
||||
logger.debug(`获取${key}数据失败,停止获取对应数据`)
|
||||
delete this.valueObject[key]
|
||||
}
|
||||
})
|
||||
|
||||
let data = await this.getData()
|
||||
if (_.isEmpty(data)) clearInterval(Timer)
|
||||
let { fsStats, networkStats, mem: { active }, currentLoad: { currentLoad } } = data
|
||||
this.fsStats = fsStats
|
||||
this.network = networkStats
|
||||
if (_.isNumber(active)) {
|
||||
this.addData(this.chartData.ram, [Date.now(), active])
|
||||
}
|
||||
if (_.isNumber(currentLoad)) {
|
||||
this.addData(this.chartData.cpu, [Date.now(), currentLoad])
|
||||
}
|
||||
}, 60000)
|
||||
}
|
||||
|
||||
async getData () {
|
||||
let data = await this.si.get(this.valueObject)
|
||||
_.forIn(data, (value, key) => {
|
||||
if (_.isEmpty(value)) {
|
||||
logger.debug(`获取${key}数据失败,停止获取对应数据`)
|
||||
delete this.valueObject[key]
|
||||
}
|
||||
})
|
||||
let {
|
||||
fsStats,
|
||||
networkStats,
|
||||
mem: { active },
|
||||
currentLoad: { currentLoad }
|
||||
} = data
|
||||
this.fsStats = fsStats
|
||||
this.network = networkStats
|
||||
if (_.isNumber(active)) {
|
||||
this.addData(this.chartData.ram, [Date.now(), active])
|
||||
}
|
||||
if (_.isNumber(currentLoad)) {
|
||||
this.addData(this.chartData.cpu, [Date.now(), currentLoad])
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* 向数组中添加数据,如果数组长度超过允许的最大值,则删除最早添加的数据
|
||||
*
|
||||
@@ -266,7 +278,7 @@ export default new class {
|
||||
}
|
||||
|
||||
/** 获取CPU占用 */
|
||||
async getCpuInfo (arch) {
|
||||
async getCpuInfo () {
|
||||
let { currentLoad: { currentLoad }, cpuCurrentSpeed } = await this.si.get({
|
||||
currentLoad: 'currentLoad',
|
||||
cpuCurrentSpeed: 'max,avg'
|
||||
@@ -281,7 +293,7 @@ export default new class {
|
||||
inner: Math.round(currentLoad) + '%',
|
||||
title: 'CPU',
|
||||
info: [
|
||||
`${cpuModel} ${cores.length}核 ${arch}`,
|
||||
`${cpuModel} ${cores.length}核 ${this.osInfo?.arch}`,
|
||||
`平均${cpuCurrentSpeed.avg}GHz`,
|
||||
`最大${cpuCurrentSpeed.max}GHz`
|
||||
]
|
||||
@@ -294,11 +306,13 @@ export default new class {
|
||||
if (!this.isGPU) return false
|
||||
try {
|
||||
const { controllers } = await this.si.graphics()
|
||||
logger.debug(controllers)
|
||||
let graphics = controllers?.find(item =>
|
||||
item.memoryUsed && item.memoryFree && item.utilizationGpu
|
||||
)
|
||||
if (!graphics) return false
|
||||
if (!graphics) {
|
||||
logger.warn('[Yenai-plugin][state]状态GPU数据异常:\n', controllers)
|
||||
return false
|
||||
}
|
||||
let {
|
||||
vendor, temperatureGpu, utilizationGpu,
|
||||
memoryTotal, memoryUsed, powerDraw
|
||||
@@ -385,14 +399,18 @@ export default new class {
|
||||
}
|
||||
network.rx_sec = this.getFileSize(network.rx_sec, false, false)
|
||||
network.tx_sec = this.getFileSize(network.tx_sec, false, false)
|
||||
return network
|
||||
// return network
|
||||
return {
|
||||
first: network.iface,
|
||||
tail: `↑${network.tx_sec}/s | ↓${network.rx_sec}/s`
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 取插件包
|
||||
* @return {*} 插件包数量
|
||||
*/
|
||||
get numberOfPlugIns () {
|
||||
get getPluginNum () {
|
||||
let str = './plugins'
|
||||
let arr = fs.readdirSync(str)
|
||||
let plugin = []
|
||||
@@ -404,10 +422,54 @@ export default new class {
|
||||
})
|
||||
let del = ['example', 'genshin', 'other', 'system', 'bin']
|
||||
plugin = plugin.filter(item => !del.includes(item))
|
||||
|
||||
const plugins = plugin?.length || 0
|
||||
const js = fs.readdirSync('./plugins/example')?.filter(item => item.includes('.js'))?.length || 0
|
||||
// return {
|
||||
// plugins: plugin?.length || 0,
|
||||
// js: fs.readdirSync('./plugins/example')?.filter(item => item.includes('.js'))?.length || 0
|
||||
// }
|
||||
return {
|
||||
plugins: plugin?.length || 0,
|
||||
js: fs.readdirSync('./plugins/example')?.filter(item => item.includes('.js'))?.length || 0
|
||||
first: '插件',
|
||||
tail: `${plugins} plugin | ${js} js`
|
||||
}
|
||||
}
|
||||
|
||||
async getNetworkLatency (url, timeoutTime = 5000) {
|
||||
const AbortController = globalThis.AbortController || await import('abort-controller')
|
||||
|
||||
const controller = new AbortController()
|
||||
const timeout = setTimeout(() => {
|
||||
controller.abort()
|
||||
}, timeoutTime)
|
||||
try {
|
||||
const startTime = Date.now()
|
||||
let { status } = await request.get(url, { signal: controller.signal })
|
||||
const endTime = Date.now()
|
||||
let delay = endTime - startTime
|
||||
let color = ''; let statusColor = ''
|
||||
if (delay > 2000) {
|
||||
color = '#F44336'
|
||||
} else if (delay > 500) {
|
||||
color = '#d68100'
|
||||
} else {
|
||||
color = '#188038'
|
||||
}
|
||||
if (status >= 500) {
|
||||
statusColor = '#9C27B0'
|
||||
} else if (status >= 400) {
|
||||
statusColor = '#F44336'
|
||||
} else if (status >= 300) {
|
||||
statusColor = '#FF9800'
|
||||
} else if (status >= 200) {
|
||||
statusColor = '#188038'
|
||||
} else if (status >= 100) {
|
||||
statusColor = '#03A9F4'
|
||||
}
|
||||
return `<span style='color:${statusColor}'>${status}</span> | <span style='color:${color}'>${delay}ms</span>`
|
||||
} catch {
|
||||
return "<span style='color:#F44336'>timeout</span>"
|
||||
} finally {
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -187,14 +187,6 @@
|
||||
</div>
|
||||
<div class="cfg-desc">开启后将使用椰奶版状态作为yunzai的默认状态</div>
|
||||
</li>
|
||||
<li class="cfg-li">
|
||||
<div class="cfg-line">
|
||||
椰奶状态定时器
|
||||
<span class="cfg-hint">#椰奶设置状态任务 + 开启/关闭 </span>
|
||||
{{@statusTask}}
|
||||
</div>
|
||||
<div class="cfg-desc">如果出现开启很多cmd任务的情况下可将其关闭,关闭后将不再获取网速和硬盘速率</div>
|
||||
</li>
|
||||
<li class="cfg-li">
|
||||
<div class="cfg-line">
|
||||
设置删除缓存时间
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.help-title, .help-group {
|
||||
background-image: linear-gradient(180deg, #d51a2f, #0cacaa);
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
dd background-clip: text;
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ body {
|
||||
background-position: right center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: cover;
|
||||
padding: 20px 35px 10px 25px;
|
||||
padding: 20px 25px 10px 25px;
|
||||
width: 1130px;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ body {
|
||||
size: cover;
|
||||
}
|
||||
|
||||
padding: 20px 35px 10px 25px;
|
||||
padding: 20px 25px 10px 25px;
|
||||
width: 1130px;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
<div class="header">
|
||||
<h1>{{nickname}}</h1>
|
||||
<hr noshade>
|
||||
<p>{{status}}({{platform}}) | 收{{recv}} | 发{{sent}} | 图片{{screenshot}} | 好友{{friend_quantity}} |
|
||||
群{{group_quantity}}
|
||||
<p>{{status}}({{platform}}) | 收{{recv}} | 发{{sent}} | 图片{{screenshot}} | 好友{{friendQuantity}} |
|
||||
群{{groupQuantity}}
|
||||
</p>
|
||||
<p>Yunzai-Bot 已运行 {{runTime}} | 系统运行 {{systime}}</p>
|
||||
<p>{{calendar}} | Nodejs {{nodeversion}} | {{osinfo.platform}}</p>
|
||||
<p>{{calendar}} | Nodejs {{nodeVersion}} | {{osPlatform}}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -179,22 +179,30 @@
|
||||
chart.setOption(option)
|
||||
</script>
|
||||
</div>
|
||||
|
||||
{{/if}}
|
||||
{{if otherInfo}}
|
||||
<div class="box">
|
||||
{{each otherInfo}}
|
||||
<div class="speed">
|
||||
<p>系统</p>
|
||||
<p>{{osinfo.distro}}</p>
|
||||
</div>
|
||||
{{if network}}
|
||||
<div class="speed">
|
||||
<p>{{network.iface}}</p>
|
||||
<p>↑{{network.tx_sec}}/s | ↓{{network.rx_sec}}/s</p>
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="speed">
|
||||
<p>插件</p>
|
||||
<p>{{plugin.plugins}} plugin | {{plugin.js}} js</p>
|
||||
<p>{{$value.first}}</p>
|
||||
<p>{{@$value.tail}}</p>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{if psTest}}
|
||||
<div class="box">
|
||||
{{each psTest}}
|
||||
<div class="speed">
|
||||
<p>{{$value.first}}</p>
|
||||
<p>{{@$value.tail}}</p>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{@FastFetch}}
|
||||
|
||||
{{/block}}
|
||||
Reference in New Issue
Block a user