Skip to content

Commit

Permalink
feat(status): support storageSize
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 18, 2021
1 parent d17428e commit dfdba08
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/plugin-status/client/views/home/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<card-numeric title="当前消息频率" icon="paper-plane">{{ currentRate }} / min</card-numeric>
<card-numeric title="近期消息频率" icon="history">{{ recentRate }} / d</card-numeric>
<card-numeric title="命名插件数量" icon="plug">{{ registry.pluginCount }}</card-numeric>
<card-numeric title="数据库体积" icon="database">456 MB</card-numeric>
<card-numeric title="活跃用户数量" icon="heart">456</card-numeric>
<card-numeric title="活跃群数量" icon="users">32</card-numeric>
<card-numeric title="数据库体积" icon="database">{{ (profile.storageSize / 1048576).toFixed(1) }} MB</card-numeric>
<card-numeric title="活跃用户数量" icon="heart">{{ profile.activeUsers }}</card-numeric>
<card-numeric title="活跃群数量" icon="users">{{ profile.activeGroups }}</card-numeric>
</div>
<load-chart/>
<div class="stats-grid chart-stats">
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-status/server/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {} from 'koishi-plugin-mongo'
Database.extend('koishi-plugin-mongo', {
async getProfile() {
const $gt = new Date(new Date().getTime() - 1000 * 3600 * 24)
const [allGroups, activeGroups, allUsers, activeUsers] = await Promise.all([
const [allGroups, activeGroups, allUsers, activeUsers, { storageSize }] = await Promise.all([
this.channel.countDocuments(),
this.channel.find({ assignee: { $ne: null } }).count(),
this.user.countDocuments(),
this.user.find({ lastCall: { $gt } }).count(),
this.mongo.db.stats(),
])
return { allGroups, activeGroups, allUsers, activeUsers }
return { allGroups, activeGroups, allUsers, activeUsers, storageSize }
},
})
5 changes: 3 additions & 2 deletions packages/plugin-status/server/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ namespace Stat {

Database.extend('koishi-plugin-mysql', {
async getProfile() {
const [[{ activeUsers }], [{ allUsers }], [{ activeGroups }], [{ allGroups }]] = await this.query([
const [[{ activeUsers }], [{ allUsers }], [{ activeGroups }], [{ allGroups }], [{ storageSize }]] = await this.query([
'SELECT COUNT(*) as activeUsers FROM `user` WHERE CURRENT_TIMESTAMP() - `lastCall` < 1000 * 3600 * 24',
'SELECT COUNT(*) as allUsers FROM `user`',
'SELECT COUNT(*) as activeGroups FROM `channel` WHERE `assignee`',
'SELECT COUNT(*) as allGroups FROM `channel`',
'SELECT SUM(DATA_LENGTH) as storageSize from information_schema.TABLES',
])
return { activeUsers, allUsers, activeGroups, allGroups }
return { activeUsers, allUsers, activeGroups, allGroups, storageSize }
},

async setChannels(data) {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-status/server/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export namespace Profile {
activeUsers: number
allGroups: number
activeGroups: number
storageSize: number
}

export async function get(ctx: Context, config: Config) {
Expand Down

0 comments on commit dfdba08

Please sign in to comment.