badmfck-api-server 2.8.8 → 2.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,19 +5,27 @@ export interface IEPStat {
|
|
|
5
5
|
success: number;
|
|
6
6
|
fail: number;
|
|
7
7
|
}
|
|
8
|
+
export interface ICustomEvent {
|
|
9
|
+
event: string;
|
|
10
|
+
data?: any;
|
|
11
|
+
project?: string;
|
|
12
|
+
}
|
|
8
13
|
export interface IEPStatReqFilter {
|
|
9
|
-
range
|
|
10
|
-
from
|
|
11
|
-
to
|
|
12
|
-
ep
|
|
14
|
+
range?: "minute" | "hour" | "day";
|
|
15
|
+
from?: string;
|
|
16
|
+
to?: string;
|
|
17
|
+
ep?: string;
|
|
18
|
+
project?: string;
|
|
19
|
+
event?: string;
|
|
13
20
|
}
|
|
14
21
|
export interface IEPStatResult {
|
|
15
22
|
}
|
|
16
23
|
export declare const S_STAT_REGISTRATE_REQUEST: Signal<TransferPacketVO<any>>;
|
|
24
|
+
export declare const S_STAT_REGISTRATE_CUSTOM_EVENT: Signal<ICustomEvent>;
|
|
17
25
|
export declare const S_STAT_REGISTRATE_SERVICE: Signal<string>;
|
|
18
26
|
export declare const REQ_EP_STAT: Req<IEPStatReqFilter, IEPStatResult>;
|
|
19
27
|
export declare class MonitorService extends BaseService {
|
|
20
|
-
|
|
28
|
+
projects: Map<string, Map<number, Map<string, IEPStat>>>;
|
|
21
29
|
constructor();
|
|
22
30
|
init(): Promise<void>;
|
|
23
31
|
getEPStat(req: IEPStatReqFilter): Promise<IEPStatResult>;
|
|
@@ -23,14 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.MonitorService = exports.REQ_EP_STAT = exports.S_STAT_REGISTRATE_SERVICE = exports.S_STAT_REGISTRATE_REQUEST = void 0;
|
|
26
|
+
exports.MonitorService = exports.REQ_EP_STAT = exports.S_STAT_REGISTRATE_SERVICE = exports.S_STAT_REGISTRATE_CUSTOM_EVENT = exports.S_STAT_REGISTRATE_REQUEST = void 0;
|
|
27
27
|
const badmfck_signal_1 = __importStar(require("badmfck-signal"));
|
|
28
28
|
const BaseService_1 = require("./BaseService");
|
|
29
29
|
exports.S_STAT_REGISTRATE_REQUEST = new badmfck_signal_1.default();
|
|
30
|
+
exports.S_STAT_REGISTRATE_CUSTOM_EVENT = new badmfck_signal_1.default();
|
|
30
31
|
exports.S_STAT_REGISTRATE_SERVICE = new badmfck_signal_1.default();
|
|
31
32
|
exports.REQ_EP_STAT = new badmfck_signal_1.Req(undefined, "REQ_EP_STAT");
|
|
32
33
|
class MonitorService extends BaseService_1.BaseService {
|
|
33
|
-
|
|
34
|
+
projects = new Map();
|
|
34
35
|
constructor() {
|
|
35
36
|
super("MonitorService");
|
|
36
37
|
exports.S_STAT_REGISTRATE_REQUEST.subscribe(req => this.onStatRegistrate(req));
|
|
@@ -40,10 +41,16 @@ class MonitorService extends BaseService_1.BaseService {
|
|
|
40
41
|
super.init();
|
|
41
42
|
}
|
|
42
43
|
async getEPStat(req) {
|
|
43
|
-
const result =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
const result = [];
|
|
45
|
+
for (let [project, projectSlot] of this.projects) {
|
|
46
|
+
if (req.project && req.project !== project)
|
|
47
|
+
continue;
|
|
48
|
+
let p = result.find(p => p.project === project);
|
|
49
|
+
if (!p) {
|
|
50
|
+
p = { project, dates: [] };
|
|
51
|
+
result.push(p);
|
|
52
|
+
}
|
|
53
|
+
for (let [minute, minuteSlot] of projectSlot) {
|
|
47
54
|
let range = minute + "";
|
|
48
55
|
if (req.range === "hour")
|
|
49
56
|
range = this.pad(this.getDate(minute).getHours());
|
|
@@ -57,42 +64,43 @@ class MonitorService extends BaseService_1.BaseService {
|
|
|
57
64
|
if (range > req.to)
|
|
58
65
|
continue;
|
|
59
66
|
}
|
|
60
|
-
let
|
|
61
|
-
if (!
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
epSlot = { success: 0, fail: 0 };
|
|
68
|
-
resultSlot.set(req.ep, epSlot);
|
|
67
|
+
let dateSlot = p.dates.find(p => p.date === range);
|
|
68
|
+
if (!dateSlot) {
|
|
69
|
+
dateSlot = {
|
|
70
|
+
date: range,
|
|
71
|
+
endpoints: []
|
|
72
|
+
};
|
|
73
|
+
p.dates.push(dateSlot);
|
|
69
74
|
}
|
|
70
|
-
for (let [
|
|
71
|
-
epSlot.
|
|
72
|
-
epSlot
|
|
75
|
+
for (let [epName, epStatSlot] of minuteSlot) {
|
|
76
|
+
let epSlot = dateSlot.endpoints.find(p => p.ep === epName);
|
|
77
|
+
if (!epSlot) {
|
|
78
|
+
epSlot = {
|
|
79
|
+
ep: epName,
|
|
80
|
+
success: 0,
|
|
81
|
+
fail: 0
|
|
82
|
+
};
|
|
83
|
+
dateSlot.endpoints.push(epSlot);
|
|
84
|
+
}
|
|
85
|
+
epSlot.fail += epStatSlot.fail;
|
|
86
|
+
epSlot.success += epStatSlot.success;
|
|
73
87
|
}
|
|
74
88
|
}
|
|
75
89
|
}
|
|
76
|
-
|
|
77
|
-
for (let [date, obj] of result) {
|
|
78
|
-
const stat = {
|
|
79
|
-
date,
|
|
80
|
-
data: []
|
|
81
|
-
};
|
|
82
|
-
for (let [ep, s] of obj) {
|
|
83
|
-
const r = { ep, ...s };
|
|
84
|
-
stat.data.push(r);
|
|
85
|
-
}
|
|
86
|
-
endResult.push(stat);
|
|
87
|
-
}
|
|
88
|
-
return { filter: req, result: endResult, overallcount: this.endpoints.size };
|
|
90
|
+
return { filter: req, result: result };
|
|
89
91
|
}
|
|
90
92
|
onStatRegistrate(data) {
|
|
91
93
|
const minute = this.getMinutes(new Date());
|
|
92
|
-
|
|
94
|
+
const project = data.project ?? "unknown";
|
|
95
|
+
let projectSlot = this.projects.get(project);
|
|
96
|
+
if (!projectSlot) {
|
|
97
|
+
projectSlot = new Map();
|
|
98
|
+
this.projects.set(project, projectSlot);
|
|
99
|
+
}
|
|
100
|
+
let minuteSlot = projectSlot.get(minute);
|
|
93
101
|
if (!minuteSlot) {
|
|
94
102
|
minuteSlot = new Map();
|
|
95
|
-
|
|
103
|
+
projectSlot.set(minute, minuteSlot);
|
|
96
104
|
}
|
|
97
105
|
if (!data.endpoint)
|
|
98
106
|
data.endpoint = "unknown";
|
|
@@ -107,10 +115,10 @@ class MonitorService extends BaseService_1.BaseService {
|
|
|
107
115
|
else {
|
|
108
116
|
epSlot.success++;
|
|
109
117
|
}
|
|
110
|
-
if (
|
|
111
|
-
const firstItem =
|
|
118
|
+
if (projectSlot.size > 3000) {
|
|
119
|
+
const firstItem = projectSlot.keys().next().value;
|
|
112
120
|
if (firstItem)
|
|
113
|
-
|
|
121
|
+
projectSlot.delete(firstItem);
|
|
114
122
|
}
|
|
115
123
|
}
|
|
116
124
|
pad(num) {
|