-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### 新增: 1. 管理系统新增平台数据统计页面,统计内容如下: - 总用户数量,总账户数量,总租户数量,总作业数,总消费数 - 筛选时间内 新增用户数,新增账户数,新增租户数,新增作业数,新增消费数 - 筛选时间内,新增用户数每日统计,活跃用户数每日统计(用户是否活跃根据是否产生操作日志判断) - 筛选时间内,消费账户top10统计,消费金额每日统计,充值账户top10统计,充值金额每日统计 - 筛选时间内,提交作业数top10用户统计,新增作业每日统计 - 筛选时间内,使用portal功能次数统计(维度仅限于操作日志统计的操作类型),使用mis功能次数统计 ![image](https://github.com/PKUHPC/SCOW/assets/130351655/4bb4f6f6-c690-4399-b7fd-3ad4a5bf43ab) ![image](https://github.com/PKUHPC/SCOW/assets/130351655/08d6461d-987b-49f0-8bd3-c3050e5ede61) ![image](https://github.com/PKUHPC/SCOW/assets/130351655/31f3aa3f-d18b-477e-b15c-634092c815a0) 2. scow db里新增TABLE `query_cache`,表结构如下 ![image](https://github.com/PKUHPC/SCOW/assets/130351655/a204b918-1e5c-4929-93e8-d56c84b49e7a) 该表主要用于缓存时间统计页面中时间消耗较长的接口, 如: - getTopChargeAccount - getDailyCharge - getTopPayAccount - getDailyPay - getTopSubmitJobUsers - getNewJobCount 缓存方案: 1. 调用以上接口时,将接口方法以及传参作为key查询query_cache中的query_key, 如果有结果,直接返回该条数据的query_result作为接口返回,如果没有,则查询真实的表,并将该结果缓存在query_cache表中 2. 设置定时任务,每天零点清除一次query_cache表,将缓存删除。
- Loading branch information
1 parent
cd252c1
commit f023d52
Showing
59 changed files
with
3,244 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@scow/grpc-api": minor | ||
--- | ||
|
||
新增数据统计接口,audit 新增 GetActiveUserCount,GetPortalUsageCount,GetMisUsageCount, server 新增 GetTopChargeAccount,GetDailyCharge,GetTopPayAccount,GetDailyPay,GetStatisticInfo,GetTopSubmitJobUsers,GetNewJobCount,GetJobTotalCount,GetNewUserCount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@scow/portal-server": minor | ||
"@scow/audit-server": minor | ||
"@scow/mis-server": minor | ||
"@scow/mis-web": minor | ||
--- | ||
|
||
管理系统新增数据统计功能,统计用户,账户,租户,作业,消费及功能使用次数 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/** | ||
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy | ||
* SCOW is licensed under Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
import { ensureNotUndefined, plugin } from "@ddadaal/tsgrpc-server"; | ||
import { QueryOrder } from "@mikro-orm/core"; | ||
import { OperationType } from "@scow/lib-operation-log"; | ||
import { StatisticServiceServer, StatisticServiceService } from "@scow/protos/build/audit/statistic"; | ||
import { OperationLog } from "src/entities/OperationLog"; | ||
|
||
|
||
export const statisticServiceServer = plugin((server) => { | ||
|
||
server.addService<StatisticServiceServer>(StatisticServiceService, { | ||
|
||
getActiveUserCount: async ({ request, em }) => { | ||
|
||
const { startTime, endTime } = ensureNotUndefined(request, ["startTime", "endTime"]); | ||
|
||
const qb = em.createQueryBuilder(OperationLog, "o"); | ||
|
||
qb | ||
.select("DATE(o.operation_time) as date, COUNT(DISTINCT o.operator_user_id) as userCount") | ||
.where({ operationTime: { $gte: startTime } }) | ||
.andWhere({ operationTime: { $lte: endTime } }) | ||
.groupBy("DATE(o.operation_time)") | ||
.orderBy({ "DATE(o.operation_time)": QueryOrder.DESC }); | ||
|
||
const records: {date: string, userCount: number}[] = await qb.execute(); | ||
|
||
return [{ | ||
results: records.map((record) => ({ | ||
date: record.date, | ||
count: record.userCount, | ||
})), | ||
}]; | ||
}, | ||
|
||
getPortalUsageCount: async ({ request, em }) => { | ||
const { startTime, endTime } = ensureNotUndefined(request, ["startTime", "endTime"]); | ||
|
||
const portalOperationType: OperationType[] = [ | ||
"submitJob", | ||
"endJob", | ||
"addJobTemplate", | ||
"deleteJobTemplate", | ||
"updateJobTemplate", | ||
"shellLogin", | ||
"createDesktop", | ||
"deleteDesktop", | ||
"createApp", | ||
"createFile", | ||
"deleteFile", | ||
"uploadFile", | ||
"createDirectory", | ||
"deleteDirectory", | ||
"moveFileItem", | ||
"copyFileItem", | ||
]; | ||
|
||
const qb = em.createQueryBuilder(OperationLog, "o"); | ||
qb | ||
.select("JSON_EXTRACT(meta_data, '$.$case') as operationType, COUNT(*) as count") | ||
.where({ operationTime: { $gte: startTime } }) | ||
.andWhere({ operationTime: { $lte: endTime } }) | ||
.andWhere({ "JSON_EXTRACT(meta_data, '$.$case')": { $in: portalOperationType } }) | ||
.groupBy("JSON_EXTRACT(meta_data, '$.$case')") | ||
.orderBy({ "COUNT(*)": QueryOrder.DESC }); | ||
|
||
const results: {operationType: string, count: number}[] = await qb.execute(); | ||
|
||
return [{ | ||
results, | ||
}]; | ||
|
||
|
||
}, | ||
getMisUsageCount: async ({ request, em }) => { | ||
const { startTime, endTime } = ensureNotUndefined(request, ["startTime", "endTime"]); | ||
|
||
const misOperationType: OperationType[] = [ | ||
"setJobTimeLimit", | ||
"createUser", | ||
"addUserToAccount", | ||
"removeUserFromAccount", | ||
"setAccountAdmin", | ||
"unsetAccountAdmin", | ||
"blockUser", | ||
"unblockUser", | ||
"accountSetChargeLimit", | ||
"accountUnsetChargeLimit", | ||
"setTenantBilling", | ||
"setTenantAdmin", | ||
"unsetTenantAdmin", | ||
"setTenantFinance", | ||
"unsetTenantFinance", | ||
"tenantChangePassword", | ||
"createAccount", | ||
"addAccountToWhitelist", | ||
"removeAccountFromWhitelist", | ||
"accountPay", | ||
"blockAccount", | ||
"unblockAccount", | ||
"importUsers", | ||
"setPlatformAdmin", | ||
"unsetPlatformAdmin", | ||
"setPlatformFinance", | ||
"unsetPlatformFinance", | ||
"platformChangePassword", | ||
"setPlatformBilling", | ||
"createTenant", | ||
"tenantPay", | ||
]; | ||
|
||
const qb = em.createQueryBuilder(OperationLog, "o"); | ||
qb | ||
.select("JSON_EXTRACT(meta_data, '$.$case') as operationType, COUNT(*) as count") | ||
.where({ operationTime: { $gte: startTime } }) | ||
.andWhere({ operationTime: { $lte: endTime } }) | ||
.andWhere({ "JSON_EXTRACT(meta_data, '$.$case')": { $in: misOperationType } }) | ||
.groupBy("JSON_EXTRACT(meta_data, '$.$case')") | ||
.orderBy({ "COUNT(*)": QueryOrder.DESC }); | ||
|
||
const results: {operationType: string, count: number}[] = await qb.execute(); | ||
|
||
return [{ | ||
results, | ||
}]; | ||
|
||
|
||
}, | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.