perf:health logging
This commit is contained in:
父節點
4b2beba584
當前提交
c827b9dab9
@ -2,6 +2,8 @@ import {IJsonCourse} from "./types"
|
|||||||
import {JsonCourseList} from "./poll"
|
import {JsonCourseList} from "./poll"
|
||||||
import {findJsonCourse} from "./includes"
|
import {findJsonCourse} from "./includes"
|
||||||
import {appConfig} from "./config"
|
import {appConfig} from "./config"
|
||||||
|
import {scalarOptions} from "yaml"
|
||||||
|
import Str = scalarOptions.Str
|
||||||
|
|
||||||
let lastJsonCourseList: { bx: IJsonCourse[], xx: IJsonCourse[], rx: IJsonCourse[] }
|
let lastJsonCourseList: { bx: IJsonCourse[], xx: IJsonCourse[], rx: IJsonCourse[] }
|
||||||
let firstRunHealth = true
|
let firstRunHealth = true
|
||||||
@ -9,6 +11,8 @@ let firstRunHealth = true
|
|||||||
export async function health() {
|
export async function health() {
|
||||||
let totalAcquireCount = 0
|
let totalAcquireCount = 0
|
||||||
let totalExitCount = 0
|
let totalExitCount = 0
|
||||||
|
let acquireNames: string[] = []
|
||||||
|
let exitNames: string[] = []
|
||||||
if (firstRunHealth) {
|
if (firstRunHealth) {
|
||||||
console.log('[health]程序health监控启动完毕')
|
console.log('[health]程序health监控启动完毕')
|
||||||
firstRunHealth = false
|
firstRunHealth = false
|
||||||
@ -25,13 +29,31 @@ export async function health() {
|
|||||||
}
|
}
|
||||||
if (parseInt(currentCourse.syrs) > parseInt(lastCourse.syrs)) {
|
if (parseInt(currentCourse.syrs) > parseInt(lastCourse.syrs)) {
|
||||||
totalExitCount += parseInt(currentCourse.syrs) - parseInt(lastCourse.syrs)
|
totalExitCount += parseInt(currentCourse.syrs) - parseInt(lastCourse.syrs)
|
||||||
|
if (!exitNames.includes(currentCourse.kcmc)) {
|
||||||
|
exitNames.push(currentCourse.kcmc)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
totalAcquireCount += parseInt(lastCourse.syrs) - parseInt(currentCourse.syrs)
|
totalAcquireCount += parseInt(lastCourse.syrs) - parseInt(currentCourse.syrs)
|
||||||
|
if (!acquireNames.includes(currentCourse.kcmc)) {
|
||||||
|
acquireNames.push(currentCourse.kcmc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('[health]实时总退课人次:' + totalExitCount + ',总选课人次:' + totalAcquireCount)
|
console.log('[health]实时总退课人次:' + totalExitCount + '(' + shuffle(exitNames).slice(0, 3).join(',') + '等),总选课人次:'
|
||||||
|
+ totalAcquireCount + '(' + shuffle(acquireNames).slice(0, 3).join(',') + '等)')
|
||||||
}
|
}
|
||||||
lastJsonCourseList = JSON.parse(JSON.stringify(JsonCourseList))
|
lastJsonCourseList = JSON.parse(JSON.stringify(JsonCourseList))
|
||||||
setTimeout(health, 60 * 1000)
|
setTimeout(health, 60 * 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shuffle(array: any[]) {
|
||||||
|
let currentIndex = array.length, randomIndex
|
||||||
|
while (currentIndex != 0) {
|
||||||
|
randomIndex = Math.floor(Math.random() * currentIndex)
|
||||||
|
currentIndex--;
|
||||||
|
[array[currentIndex], array[randomIndex]] = [
|
||||||
|
array[randomIndex], array[currentIndex]]
|
||||||
|
}
|
||||||
|
return array
|
||||||
|
}
|
||||||
|
載入中…
x
新增問題並參考
Block a user