diff --git a/astrbot/dashboard/routes/stat.py b/astrbot/dashboard/routes/stat.py index b20e9dca4..04b2d21ee 100644 --- a/astrbot/dashboard/routes/stat.py +++ b/astrbot/dashboard/routes/stat.py @@ -1,6 +1,7 @@ import traceback import psutil import time +import threading from .route import Route, Response, RouteContext from astrbot.core import logger from quart import request @@ -64,6 +65,25 @@ class StatRoute(Route): stat_dict = stat.__dict__ + # 获取CPU使用率 - 修复CPU始终为0的问题 + process = psutil.Process() + # 获取系统CPU使用率而不是进程CPU使用率 + cpu_percent = psutil.cpu_percent(interval=0.5) + + # 获取线程数 + thread_count = threading.active_count() + + # 获取插件信息 + plugins = self.core_lifecycle.star_context.get_all_stars() + plugin_info = [] + for plugin in plugins: + info = { + "name": getattr(plugin, "name", plugin.__class__.__name__), + "version": getattr(plugin, "version", "1.0.0"), + "is_enabled": True + } + plugin_info.append(info) + stat_dict.update( { "platform": self.db_helper.get_grouped_base_stats( @@ -73,9 +93,8 @@ class StatRoute(Route): "platform_count": len( self.core_lifecycle.platform_manager.get_insts() ), - "plugin_count": len( - self.core_lifecycle.star_context.get_all_stars() - ), + "plugin_count": len(plugins), + "plugins": plugin_info, "message_time_series": message_time_based_stats, "running": self.format_sec( int(time.time()) - self.core_lifecycle.start_time @@ -84,6 +103,9 @@ class StatRoute(Route): "process": psutil.Process().memory_info().rss >> 20, "system": psutil.virtual_memory().total >> 20, }, + "cpu_percent": round(cpu_percent, 1), + "thread_count": thread_count, + "start_time": self.core_lifecycle.start_time, } ) diff --git a/dashboard/src/components/shared/AstrBotConfig.vue b/dashboard/src/components/shared/AstrBotConfig.vue index e9d8e667b..2796f95da 100644 --- a/dashboard/src/components/shared/AstrBotConfig.vue +++ b/dashboard/src/components/shared/AstrBotConfig.vue @@ -1,207 +1,141 @@ @@ -219,125 +153,4 @@ export default { metadataKey: String } } - - - \ No newline at end of file + \ No newline at end of file diff --git a/dashboard/src/views/dashboards/default/DefaultDashboard.vue b/dashboard/src/views/dashboards/default/DefaultDashboard.vue index e904bf3a9..859d62267 100644 --- a/dashboard/src/views/dashboards/default/DefaultDashboard.vue +++ b/dashboard/src/views/dashboards/default/DefaultDashboard.vue @@ -1,37 +1,84 @@ + + diff --git a/dashboard/src/views/dashboards/default/components/MemoryUsage.vue b/dashboard/src/views/dashboards/default/components/MemoryUsage.vue new file mode 100644 index 000000000..79d0ecb29 --- /dev/null +++ b/dashboard/src/views/dashboards/default/components/MemoryUsage.vue @@ -0,0 +1,140 @@ + + + + + diff --git a/dashboard/src/views/dashboards/default/components/MessageStat.vue b/dashboard/src/views/dashboards/default/components/MessageStat.vue index 98b568199..6856c3027 100644 --- a/dashboard/src/views/dashboards/default/components/MessageStat.vue +++ b/dashboard/src/views/dashboards/default/components/MessageStat.vue @@ -1,65 +1,136 @@ - - \ No newline at end of file + methods: { + formatNumber(num) { + return new Intl.NumberFormat('zh-CN').format(num); + }, + + async fetchMessageSeries() { + this.loading = true; + + try { + const response = await axios.get(`/api/stat/get?offset_sec=${this.selectedTimeRange.value}`); + const data = response.data.data; + + if (data && data.message_time_series) { + this.messageTimeSeries = data.message_time_series; + this.processTimeSeriesData(); + } + } catch (error) { + console.error('获取消息趋势数据失败:', error); + } finally { + this.loading = false; + } + }, + + processTimeSeriesData() { + // 转换数据为图表格式 + this.chartSeries[0].data = this.messageTimeSeries.map((item) => { + return [new Date(item[0]*1000).getTime(), item[1]]; + }); + + // 计算总消息数 + let total = 0; + this.messageTimeSeries.forEach(item => { + total += item[1]; + }); + this.totalMessages = this.formatNumber(total); + + // 计算日平均 + if (this.messageTimeSeries.length > 0) { + const daysSpan = this.selectedTimeRange.value / 86400; // 将秒转换为天数 + this.dailyAverage = this.formatNumber(Math.round(total / daysSpan)); + } + + // 计算增长率 + this.calculateGrowthRate(); + }, + + calculateGrowthRate() { + if (this.messageTimeSeries.length < 4) { + this.growthRate = 0; + return; + } + + // 计算前半部分和后半部分的消息总数 + const halfIndex = Math.floor(this.messageTimeSeries.length / 2); + + const firstHalf = this.messageTimeSeries + .slice(0, halfIndex) + .reduce((sum, item) => sum + item[1], 0); + + const secondHalf = this.messageTimeSeries + .slice(halfIndex) + .reduce((sum, item) => sum + item[1], 0); + + // 计算增长率 + if (firstHalf > 0) { + this.growthRate = Math.round(((secondHalf - firstHalf) / firstHalf) * 100); + } else { + this.growthRate = secondHalf > 0 ? 100 : 0; + } + } + } +}; + + + \ No newline at end of file diff --git a/dashboard/src/views/dashboards/default/components/OnlinePlatform.vue b/dashboard/src/views/dashboards/default/components/OnlinePlatform.vue index 26fd6e8a1..3eee6aaa1 100644 --- a/dashboard/src/views/dashboards/default/components/OnlinePlatform.vue +++ b/dashboard/src/views/dashboards/default/components/OnlinePlatform.vue @@ -1,37 +1,84 @@ - - - \ No newline at end of file + + + \ No newline at end of file diff --git a/dashboard/src/views/dashboards/default/components/OnlineTime.vue b/dashboard/src/views/dashboards/default/components/OnlineTime.vue index 4ba51a7d1..3c869aa36 100644 --- a/dashboard/src/views/dashboards/default/components/OnlineTime.vue +++ b/dashboard/src/views/dashboards/default/components/OnlineTime.vue @@ -1,61 +1,190 @@ - - - - \ No newline at end of file + \ No newline at end of file diff --git a/dashboard/src/views/dashboards/default/components/PlatformStat.vue b/dashboard/src/views/dashboards/default/components/PlatformStat.vue index 243fd5b18..9235ff723 100644 --- a/dashboard/src/views/dashboards/default/components/PlatformStat.vue +++ b/dashboard/src/views/dashboards/default/components/PlatformStat.vue @@ -1,116 +1,253 @@ - - - \ No newline at end of file + + + \ No newline at end of file diff --git a/dashboard/src/views/dashboards/default/components/RunningTime.vue b/dashboard/src/views/dashboards/default/components/RunningTime.vue new file mode 100644 index 000000000..139eaa6a4 --- /dev/null +++ b/dashboard/src/views/dashboards/default/components/RunningTime.vue @@ -0,0 +1,89 @@ + + + + + diff --git a/dashboard/src/views/dashboards/default/components/TotalMessage.vue b/dashboard/src/views/dashboards/default/components/TotalMessage.vue index 8af94a754..6644a7b9c 100644 --- a/dashboard/src/views/dashboards/default/components/TotalMessage.vue +++ b/dashboard/src/views/dashboards/default/components/TotalMessage.vue @@ -1,40 +1,97 @@ - - \ No newline at end of file + + + \ No newline at end of file