mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
feat: 仪表盘基本数据
This commit is contained in:
parent
15482e398b
commit
7cc55eab3e
23
pkg/api/http/controller/groups/stats.py
Normal file
23
pkg/api/http/controller/groups/stats.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
import quart
|
||||
import asyncio
|
||||
|
||||
from .....core import app, taskmgr
|
||||
from .. import group
|
||||
|
||||
|
||||
@group.group_class('stats', '/api/v1/stats')
|
||||
class StatsRouterGroup(group.RouterGroup):
|
||||
|
||||
async def initialize(self) -> None:
|
||||
@self.route('/basic', methods=['GET'])
|
||||
async def _() -> str:
|
||||
|
||||
conv_count = 0
|
||||
for session in self.ap.sess_mgr.session_list:
|
||||
conv_count += len(session.conversations if session.conversations is not None else [])
|
||||
|
||||
return self.success(data={
|
||||
'active_session_count': len(self.ap.sess_mgr.session_list),
|
||||
'conversation_count': conv_count,
|
||||
'query_count': self.ap.query_pool.query_id_counter,
|
||||
})
|
|
@ -15,7 +15,8 @@ class SystemRouterGroup(group.RouterGroup):
|
|||
return self.success(
|
||||
data={
|
||||
"version": constants.semantic_version,
|
||||
"debug": constants.debug_mode
|
||||
"debug": constants.debug_mode,
|
||||
"enabled_platform_count": len(self.ap.platform_mgr.adapters)
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import quart
|
|||
import quart_cors
|
||||
|
||||
from ....core import app
|
||||
from .groups import logs, system, settings, plugins
|
||||
from .groups import logs, system, settings, plugins, stats
|
||||
from . import group
|
||||
|
||||
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
</v-card-title>
|
||||
|
||||
<div id="basic-analysis-number-card-content">
|
||||
<NumberFieldData title="活跃会话" :number="100" />
|
||||
<NumberFieldData title="对话总数" :number="100" />
|
||||
<NumberFieldData title="请求总数" :number="100" />
|
||||
<NumberFieldData title="活跃会话" :number="basicData.active_session_count" />
|
||||
<NumberFieldData title="对话总数" :number="basicData.conversation_count" />
|
||||
<NumberFieldData title="请求总数" :number="basicData.query_count" />
|
||||
</div>
|
||||
</v-card>
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
|||
</v-card-title>
|
||||
|
||||
<div id="message-platform-card-content">
|
||||
<NumberFieldData title="已启用" :number="1" link="/platforms" linkText="更改配置" />
|
||||
<NumberFieldData title="已启用" :number="proxy.$store.state.enabledPlatformCount" link="/settings" linkText="更改配置" />
|
||||
</div>
|
||||
</v-card>
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
|||
</v-card-title>
|
||||
|
||||
<div id="plugins-amount-card-content">
|
||||
<NumberFieldData title="已加载" :number="3" link="/plugins" linkText="管理插件" />
|
||||
<NumberFieldData title="已加载" :number="pluginsAmount" link="/plugins" linkText="管理插件" />
|
||||
</div>
|
||||
</v-card>
|
||||
</div>
|
||||
|
@ -46,8 +46,45 @@
|
|||
import PageTitle from '@/components/PageTitle.vue'
|
||||
import NumberFieldData from '@/components/NumberFieldData.vue'
|
||||
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, onMounted, inject, getCurrentInstance } from 'vue'
|
||||
|
||||
const { proxy } = getCurrentInstance()
|
||||
|
||||
const snackbar = inject('snackbar')
|
||||
|
||||
const basicData = ref({
|
||||
active_session_count: 0,
|
||||
conversation_count: 0,
|
||||
query_count: 0,
|
||||
})
|
||||
|
||||
const pluginsAmount = ref(0)
|
||||
|
||||
const refresh = () => {
|
||||
proxy.$axios.get('/stats/basic').then(res => {
|
||||
if (res.data.code != 0) {
|
||||
snackbar.error(res.data.msg)
|
||||
return
|
||||
}
|
||||
basicData.value = res.data.data
|
||||
}).catch(error => {
|
||||
snackbar.error(error)
|
||||
})
|
||||
|
||||
proxy.$axios.get('/plugins').then(res => {
|
||||
if (res.data.code != 0) {
|
||||
snackbar.error(res.data.msg)
|
||||
return
|
||||
}
|
||||
pluginsAmount.value = res.data.data.plugins.length
|
||||
}).catch(error => {
|
||||
snackbar.error(error)
|
||||
})
|
||||
|
||||
proxy.$store.commit('fetchSystemInfo')
|
||||
}
|
||||
|
||||
onMounted(refresh)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
|
|
@ -8,7 +8,8 @@ export default createStore({
|
|||
autoRefreshLog: false,
|
||||
settingsPageTab: '',
|
||||
version: 'v0.0.0',
|
||||
debug: false
|
||||
debug: false,
|
||||
enabledPlatformCount: 0,
|
||||
},
|
||||
mutations: {
|
||||
initializeFetch() {
|
||||
|
@ -17,6 +18,14 @@ export default createStore({
|
|||
axios.get('/system/info').then(response => {
|
||||
this.state.version = response.data.data.version
|
||||
this.state.debug = response.data.data.debug
|
||||
this.state.enabledPlatformCount = response.data.data.enabled_platform_count
|
||||
})
|
||||
},
|
||||
fetchSystemInfo() {
|
||||
axios.get('/system/info').then(response => {
|
||||
this.state.version = response.data.data.version
|
||||
this.state.debug = response.data.data.debug
|
||||
this.state.enabledPlatformCount = response.data.data.enabled_platform_count
|
||||
})
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user