@be-link/ecommerce-trade-service-node-sdk 0.1.61 → 0.1.62
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.
- package/modules/pos/orderQuery/types.d.ts +6 -0
- package/modules/ros/orderQuery/types.d.ts +31 -10
- package/package.json +1 -1
- package/types.d.ts +1 -0
- package/utils/http.js +72 -259
|
@@ -312,6 +312,9 @@ export declare namespace PosOrderQueryService {
|
|
|
312
312
|
};
|
|
313
313
|
user: {
|
|
314
314
|
userId: string;
|
|
315
|
+
unionId: string;
|
|
316
|
+
/** 用户昵称 */
|
|
317
|
+
nickname?: string;
|
|
315
318
|
memberLevel?: string;
|
|
316
319
|
receiverName: string;
|
|
317
320
|
receiverPhone: string;
|
|
@@ -326,6 +329,9 @@ export declare namespace PosOrderQueryService {
|
|
|
326
329
|
};
|
|
327
330
|
userDetail: {
|
|
328
331
|
userId: string;
|
|
332
|
+
unionId: string;
|
|
333
|
+
/** 用户昵称 */
|
|
334
|
+
nickname?: string;
|
|
329
335
|
memberLevel?: string;
|
|
330
336
|
receiverName: string;
|
|
331
337
|
receiverPhone: string;
|
|
@@ -6,16 +6,35 @@ export declare namespace RosOrderQueryService {
|
|
|
6
6
|
interface IOrderList {
|
|
7
7
|
/** 查询条件 */
|
|
8
8
|
conditions?: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
/** 下单时间范围 */
|
|
10
|
+
createdAt?: {
|
|
11
|
+
start?: number;
|
|
12
|
+
end?: number;
|
|
13
|
+
};
|
|
14
|
+
/** 退款操作时间范围 */
|
|
15
|
+
operateTime?: {
|
|
16
|
+
start?: number;
|
|
17
|
+
end?: number;
|
|
18
|
+
};
|
|
19
|
+
/** 退款申请时间范围 */
|
|
20
|
+
orderTime?: {
|
|
21
|
+
start?: number;
|
|
22
|
+
end?: number;
|
|
23
|
+
};
|
|
24
|
+
/** 退款订单状态列表 */
|
|
25
|
+
statusList?: ENUM.ReverseOrderStatus[];
|
|
26
|
+
/** 退款到账状态列表 */
|
|
27
|
+
arrivalStatusList?: ENUM.ReverseArrivalStatus[];
|
|
28
|
+
/** 退款方式列表 */
|
|
29
|
+
wayList?: ENUM.ReverseRefundWay[];
|
|
30
|
+
/** 退款类型列表 */
|
|
31
|
+
typeList?: ENUM.ReverseRefundType[];
|
|
32
|
+
/** 用户ID列表 */
|
|
33
|
+
userIds?: string[];
|
|
34
|
+
/** 正向订单ID列表 */
|
|
35
|
+
orderIds?: string[];
|
|
36
|
+
/** 门店ID列表 */
|
|
37
|
+
storeIds?: string[];
|
|
19
38
|
};
|
|
20
39
|
/** 分页 */
|
|
21
40
|
pagination: {
|
|
@@ -40,6 +59,8 @@ export declare namespace RosOrderQueryService {
|
|
|
40
59
|
reverseOrderIds?: string[];
|
|
41
60
|
/** 订单ID列表 */
|
|
42
61
|
orderIds?: string[];
|
|
62
|
+
/** 订单类型 */
|
|
63
|
+
orderTypeList?: ENUM.OrderType[];
|
|
43
64
|
/** 用户ID列表 */
|
|
44
65
|
userIds?: string[];
|
|
45
66
|
/** 门店ID列表 */
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
package/utils/http.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -8,109 +41,28 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
41
|
const uuid_1 = require("uuid");
|
|
9
42
|
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
10
43
|
const request_context_1 = require("@fastify/request-context");
|
|
11
|
-
const http_1 = __importDefault(require("http"));
|
|
12
|
-
const https_1 = __importDefault(require("https"));
|
|
13
44
|
const safe_stable_stringify_1 = __importDefault(require("safe-stable-stringify"));
|
|
14
|
-
// 针对高并发优化配置 - 支持2000并发
|
|
15
|
-
const HTTP_CONFIG = {
|
|
16
|
-
maxSockets: 3000, // 每个主机的最大socket连接数(支持2000并发)
|
|
17
|
-
maxFreeSockets: 1000, // 空闲socket保留数(50%复用率,提高连接复用效率)
|
|
18
|
-
maxTotalSockets: 10000, // 所有主机总socket数(单后端场景优化)
|
|
19
|
-
keepAliveMsecs: 30000, // 保持连接30秒(平衡资源占用和连接复用)
|
|
20
|
-
timeout: 5000, // socket超时3秒(高并发场景快速失败)
|
|
21
|
-
requestTimeout: 5000, // 请求超时5秒(快速释放资源,避免慢请求占用连接)
|
|
22
|
-
retryBaseDelay: 200, // 基础重试延迟100ms(给服务恢复时间)
|
|
23
|
-
logThreshold: 1000, // 日志采样率(每1000个请求采样1次,降低日志开销)
|
|
24
|
-
monitorInterval: 5000, // 监控日志间隔(毫秒)
|
|
25
|
-
};
|
|
26
|
-
// 配置 HTTP/HTTPS Agent 以支持高并发连接池和 keepAlive
|
|
27
|
-
const httpAgent = new http_1.default.Agent({
|
|
28
|
-
keepAlive: true,
|
|
29
|
-
keepAliveMsecs: HTTP_CONFIG.keepAliveMsecs,
|
|
30
|
-
maxSockets: HTTP_CONFIG.maxSockets,
|
|
31
|
-
maxFreeSockets: HTTP_CONFIG.maxFreeSockets,
|
|
32
|
-
maxTotalSockets: HTTP_CONFIG.maxTotalSockets,
|
|
33
|
-
timeout: HTTP_CONFIG.timeout,
|
|
34
|
-
scheduling: 'fifo', // 先进先出调度
|
|
35
|
-
});
|
|
36
|
-
const httpsAgent = new https_1.default.Agent({
|
|
37
|
-
keepAlive: true,
|
|
38
|
-
keepAliveMsecs: HTTP_CONFIG.keepAliveMsecs,
|
|
39
|
-
maxSockets: HTTP_CONFIG.maxSockets,
|
|
40
|
-
maxFreeSockets: HTTP_CONFIG.maxFreeSockets,
|
|
41
|
-
maxTotalSockets: HTTP_CONFIG.maxTotalSockets,
|
|
42
|
-
timeout: HTTP_CONFIG.timeout,
|
|
43
|
-
scheduling: 'fifo',
|
|
44
|
-
});
|
|
45
|
-
// 配置 axios 默认使用这些 agent
|
|
46
|
-
axios_1.default.defaults.httpAgent = httpAgent;
|
|
47
|
-
axios_1.default.defaults.httpsAgent = httpsAgent;
|
|
48
|
-
axios_1.default.defaults.timeout = HTTP_CONFIG.requestTimeout;
|
|
49
|
-
axios_1.default.defaults.maxRedirects = 3; // 限制重定向次数
|
|
50
|
-
axios_1.default.defaults.maxContentLength = 50 * 1024 * 1024; // 50MB 最大响应大小
|
|
51
|
-
// 高并发场景下的智能重试配置
|
|
52
45
|
(0, axios_retry_1.default)(axios_1.default, {
|
|
46
|
+
retries: 1,
|
|
53
47
|
retryCondition(error) {
|
|
54
|
-
|
|
55
|
-
const status = error.response?.status;
|
|
56
|
-
const isNetworkError = error.code === 'ECONNRESET' || error.code === 'ETIMEDOUT';
|
|
57
|
-
const isServerError = status === 502 || status === 503 || status === 504;
|
|
58
|
-
const isRateLimited = status === 429;
|
|
59
|
-
return isNetworkError || isServerError || isRateLimited;
|
|
48
|
+
return error.response?.status === 502;
|
|
60
49
|
},
|
|
61
|
-
retryDelay: (retryCount
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (retryAfter) {
|
|
68
|
-
return parseInt(retryAfter) * 1000;
|
|
69
|
-
}
|
|
70
|
-
return 1000 + Math.random() * 1000; // 1-2秒
|
|
71
|
-
}
|
|
72
|
-
// 指数退避:100ms, 200ms, 400ms...
|
|
73
|
-
const exponentialDelay = HTTP_CONFIG.retryBaseDelay * Math.pow(2, retryCount - 1);
|
|
74
|
-
const jitter = Math.random() * 50; // 0-50ms 抖动
|
|
75
|
-
return Math.min(exponentialDelay + jitter, 2000); // 最多延迟2秒
|
|
50
|
+
retryDelay: (retryCount) => {
|
|
51
|
+
console.info(`retryCount: ${retryCount}, retryDelay: ${retryCount * 500}`);
|
|
52
|
+
return retryCount * 500;
|
|
53
|
+
},
|
|
54
|
+
onRetry(retryCount, error, requestConfig) {
|
|
55
|
+
console.info(`retryCount: ${retryCount}, onRetry: ${error.message}, requestHeader: ${(0, safe_stable_stringify_1.default)(requestConfig.headers)}`);
|
|
76
56
|
},
|
|
77
|
-
shouldResetTimeout: true, // 重试时重置超时
|
|
78
57
|
});
|
|
79
|
-
// 连接池状态监控
|
|
80
|
-
let requestCount = 0;
|
|
81
|
-
let activeRequests = 0;
|
|
82
|
-
let peakActiveRequests = 0; // 峰值并发
|
|
83
|
-
// 注意:已移除应用层并发队列限制,完全依赖底层socket连接池控制
|
|
84
|
-
// 这样可以避免应用层排队等待,充分利用socket连接池的并发能力
|
|
85
58
|
async function callApi(url, request) {
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
peakActiveRequests = activeRequests;
|
|
92
|
-
}
|
|
93
|
-
// 批量获取请求上下文,减少函数调用开销
|
|
94
|
-
const ctx = request_context_1.requestContext.get('requestId') ? request_context_1.requestContext : null;
|
|
95
|
-
const requestId = ctx?.get('requestId') || ctx?.get('traceMessageId') || (0, uuid_1.v4)();
|
|
96
|
-
const pandoraUserId = ctx?.get('pandoraUserId') || '';
|
|
97
|
-
const beLinkUserId = ctx?.get('beLinkUserId') || '';
|
|
98
|
-
const pandoraRoleId = ctx?.get('pandoraRoleId') || '';
|
|
99
|
-
const realIp = ctx?.get('realIp') || '';
|
|
100
|
-
// 采样日志决策(提前计算,避免重复判断)
|
|
101
|
-
const shouldLog = currentRequestId % HTTP_CONFIG.logThreshold === 0;
|
|
102
|
-
const startTime = shouldLog ? Date.now() : 0;
|
|
59
|
+
const requestId = request_context_1.requestContext.get('requestId') || request_context_1.requestContext.get('traceMessageId') || (0, uuid_1.v4)();
|
|
60
|
+
const pandoraUserId = request_context_1.requestContext.get('pandoraUserId') || '';
|
|
61
|
+
const beLinkUserId = request_context_1.requestContext.get('beLinkUserId') || '';
|
|
62
|
+
const pandoraRoleId = request_context_1.requestContext.get('pandoraRoleId') || '';
|
|
63
|
+
const realIp = request_context_1.requestContext.get('realIp') || '';
|
|
103
64
|
try {
|
|
104
|
-
|
|
105
|
-
console.log((0, safe_stable_stringify_1.default)({
|
|
106
|
-
message: '发起HTTP请求',
|
|
107
|
-
currentRequestId,
|
|
108
|
-
activeRequests,
|
|
109
|
-
requestId,
|
|
110
|
-
url,
|
|
111
|
-
type: 'http_request_start',
|
|
112
|
-
}));
|
|
113
|
-
}
|
|
65
|
+
console.info(`准备发起ecommerce-trade-service请求[${requestId}]: ${url}, 参数: ${(0, safe_stable_stringify_1.default)(request)}`);
|
|
114
66
|
const response = await axios_1.default.post(url, request, {
|
|
115
67
|
headers: {
|
|
116
68
|
'x-request-id': requestId,
|
|
@@ -118,181 +70,42 @@ async function callApi(url, request) {
|
|
|
118
70
|
'x-belink-userid': beLinkUserId,
|
|
119
71
|
'x-belink-pandora-roleid': pandoraRoleId,
|
|
120
72
|
'x-real-ip': realIp,
|
|
121
|
-
Connection: 'keep-alive',
|
|
122
73
|
},
|
|
123
|
-
timeout: HTTP_CONFIG.requestTimeout,
|
|
124
|
-
httpAgent,
|
|
125
|
-
httpsAgent,
|
|
126
74
|
});
|
|
127
|
-
if (shouldLog) {
|
|
128
|
-
const duration = Date.now() - startTime;
|
|
129
|
-
if (duration > 3000) {
|
|
130
|
-
console.log((0, safe_stable_stringify_1.default)({
|
|
131
|
-
message: '请求完成',
|
|
132
|
-
currentRequestId,
|
|
133
|
-
duration: `${duration}ms`,
|
|
134
|
-
activeRequests,
|
|
135
|
-
type: 'http_request_complete',
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
75
|
const responseData = response.data;
|
|
140
76
|
return responseData.data;
|
|
141
77
|
}
|
|
142
78
|
catch (error) {
|
|
143
79
|
const axiosError = error;
|
|
144
|
-
const duration = startTime ? Date.now() - startTime : 0;
|
|
145
|
-
// 错误始终记录(但简化输出)
|
|
146
|
-
console.error((0, safe_stable_stringify_1.default)({
|
|
147
|
-
message: '请求失败',
|
|
148
|
-
currentRequestId,
|
|
149
|
-
url,
|
|
150
|
-
duration: `${duration}ms`,
|
|
151
|
-
activeRequests,
|
|
152
|
-
errorMessage: axiosError.message,
|
|
153
|
-
type: 'http_request_failed',
|
|
154
|
-
}));
|
|
155
80
|
if (axiosError.response) {
|
|
156
81
|
const response = axiosError.response;
|
|
157
82
|
const data = response.data;
|
|
158
|
-
console.error(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}));
|
|
83
|
+
console.error(`ecommerce-trade-service 异常: ${axiosError.message},requestId: ${requestId}`);
|
|
84
|
+
console.info('响应信息', data.message);
|
|
85
|
+
console.error('异常堆栈', (0, safe_stable_stringify_1.default)(error.stack));
|
|
86
|
+
// throw new Error(data.errorType + ' - ' + data.message)
|
|
87
|
+
throw error;
|
|
164
88
|
}
|
|
89
|
+
// 调用dns模块解析url
|
|
90
|
+
const dns = await Promise.resolve().then(() => __importStar(require('dns')));
|
|
91
|
+
const dnsPromise = new Promise((resolve, reject) => {
|
|
92
|
+
const lookupRes = dns.lookup(url, (err, address) => {
|
|
93
|
+
if (err) {
|
|
94
|
+
console.error(err.message);
|
|
95
|
+
reject(err);
|
|
96
|
+
}
|
|
97
|
+
console.info(`lookup: ${(0, safe_stable_stringify_1.default)(lookupRes)}`);
|
|
98
|
+
resolve(address);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
try {
|
|
102
|
+
const address = await dnsPromise;
|
|
103
|
+
console.info(`address: ${(0, safe_stable_stringify_1.default)(address)}`);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.info(`error: ${(0, safe_stable_stringify_1.default)(error)}`);
|
|
107
|
+
}
|
|
108
|
+
console.error(`ecommerce-trade-service 未知异常: ${axiosError.message}`, error.stack);
|
|
165
109
|
throw error;
|
|
166
110
|
}
|
|
167
|
-
finally {
|
|
168
|
-
// 记录请求完成,减少活跃计数
|
|
169
|
-
activeRequests--;
|
|
170
|
-
}
|
|
171
111
|
}
|
|
172
|
-
// 导出监控函数
|
|
173
|
-
// export function getConnectionStats() {
|
|
174
|
-
// const stats = {
|
|
175
|
-
// // 当前状态
|
|
176
|
-
// activeRequests,
|
|
177
|
-
// totalRequests: requestCount,
|
|
178
|
-
// // 峰值指标
|
|
179
|
-
// peakActiveRequests,
|
|
180
|
-
// // Socket连接池状态(这是真正的并发控制点)
|
|
181
|
-
// httpSockets: {
|
|
182
|
-
// total: Object.keys(httpAgent.sockets).reduce(
|
|
183
|
-
// (sum, host) => sum + (httpAgent.sockets[host]?.length || 0),
|
|
184
|
-
// 0,
|
|
185
|
-
// ),
|
|
186
|
-
// hosts: Object.keys(httpAgent.sockets).length,
|
|
187
|
-
// details: httpAgent.sockets,
|
|
188
|
-
// },
|
|
189
|
-
// httpsSockets: {
|
|
190
|
-
// total: Object.keys(httpsAgent.sockets).reduce(
|
|
191
|
-
// (sum, host) => sum + (httpsAgent.sockets[host]?.length || 0),
|
|
192
|
-
// 0,
|
|
193
|
-
// ),
|
|
194
|
-
// hosts: Object.keys(httpsAgent.sockets).length,
|
|
195
|
-
// details: httpsAgent.sockets,
|
|
196
|
-
// },
|
|
197
|
-
// // 配置信息
|
|
198
|
-
// config: {
|
|
199
|
-
// maxSockets: HTTP_CONFIG.maxSockets,
|
|
200
|
-
// maxTotalSockets: HTTP_CONFIG.maxTotalSockets,
|
|
201
|
-
// requestTimeout: HTTP_CONFIG.requestTimeout,
|
|
202
|
-
// note: '已移除应用层并发队列限制,完全依赖socket连接池',
|
|
203
|
-
// },
|
|
204
|
-
// }
|
|
205
|
-
// return stats
|
|
206
|
-
// }
|
|
207
|
-
// 重置峰值统计(可用于定期重置)
|
|
208
|
-
// export function resetPeakStats() {
|
|
209
|
-
// peakActiveRequests = activeRequests
|
|
210
|
-
// console.log(
|
|
211
|
-
// stringify({
|
|
212
|
-
// message: '峰值统计已重置',
|
|
213
|
-
// type: 'stats_reset',
|
|
214
|
-
// }),
|
|
215
|
-
// )
|
|
216
|
-
// }
|
|
217
|
-
// // 定期监控日志
|
|
218
|
-
// let monitorTimer: NodeJS.Timeout | null = null
|
|
219
|
-
// export function startMonitoring(interval: number = HTTP_CONFIG.monitorInterval) {
|
|
220
|
-
// if (monitorTimer) {
|
|
221
|
-
// console.log(
|
|
222
|
-
// stringify({
|
|
223
|
-
// message: '监控已在运行中',
|
|
224
|
-
// type: 'monitor_already_running',
|
|
225
|
-
// }),
|
|
226
|
-
// )
|
|
227
|
-
// return
|
|
228
|
-
// }
|
|
229
|
-
// console.log(
|
|
230
|
-
// stringify({
|
|
231
|
-
// message: '启动并发监控',
|
|
232
|
-
// interval: `${interval}ms`,
|
|
233
|
-
// type: 'monitor_start',
|
|
234
|
-
// }),
|
|
235
|
-
// )
|
|
236
|
-
// monitorTimer = setInterval(() => {
|
|
237
|
-
// const stats = getConnectionStats()
|
|
238
|
-
// // 只在有活动时打印
|
|
239
|
-
// if (stats.totalRequests === 0) {
|
|
240
|
-
// return
|
|
241
|
-
// }
|
|
242
|
-
// // 检测异常情况(基于socket连接池使用率)
|
|
243
|
-
// const httpSocketsUsage = stats.httpSockets.total / HTTP_CONFIG.maxSockets
|
|
244
|
-
// const httpsSocketsUsage = stats.httpsSockets.total / HTTP_CONFIG.maxSockets
|
|
245
|
-
// const maxSocketUsage = Math.max(httpSocketsUsage, httpsSocketsUsage)
|
|
246
|
-
// // Socket连接池使用率超过80%视为瓶颈
|
|
247
|
-
// const hasIssue = maxSocketUsage > 0.8
|
|
248
|
-
// if (hasIssue) {
|
|
249
|
-
// console.warn(
|
|
250
|
-
// stringify({
|
|
251
|
-
// message: '并发监控检测到瓶颈',
|
|
252
|
-
// 当前并发: stats.activeRequests,
|
|
253
|
-
// 峰值并发: stats.peakActiveRequests,
|
|
254
|
-
// 总请求数: stats.totalRequests,
|
|
255
|
-
// HTTP_Sockets: `${stats.httpSockets.total}/${HTTP_CONFIG.maxSockets} (${Math.round(
|
|
256
|
-
// httpSocketsUsage * 100,
|
|
257
|
-
// )}%)`,
|
|
258
|
-
// HTTPS_Sockets: `${stats.httpsSockets.total}/${HTTP_CONFIG.maxSockets} (${Math.round(
|
|
259
|
-
// httpsSocketsUsage * 100,
|
|
260
|
-
// )}%)`,
|
|
261
|
-
// 建议: 'Socket连接池接近饱和,考虑提高maxSockets配置',
|
|
262
|
-
// type: 'monitor_bottleneck_detected',
|
|
263
|
-
// }),
|
|
264
|
-
// )
|
|
265
|
-
// } else if (stats.totalRequests % 10000 === 0) {
|
|
266
|
-
// // 每1万次请求打印一次正常状态
|
|
267
|
-
// console.log(
|
|
268
|
-
// stringify({
|
|
269
|
-
// message: '并发监控运行正常',
|
|
270
|
-
// 总请求: stats.totalRequests,
|
|
271
|
-
// 当前并发: stats.activeRequests,
|
|
272
|
-
// 峰值并发: stats.peakActiveRequests,
|
|
273
|
-
// HTTP_Sockets使用率: `${Math.round(httpSocketsUsage * 100)}%`,
|
|
274
|
-
// HTTPS_Sockets使用率: `${Math.round(httpsSocketsUsage * 100)}%`,
|
|
275
|
-
// type: 'monitor_normal',
|
|
276
|
-
// }),
|
|
277
|
-
// )
|
|
278
|
-
// }
|
|
279
|
-
// }, interval)
|
|
280
|
-
// }
|
|
281
|
-
// export function stopMonitoring() {
|
|
282
|
-
// if (monitorTimer) {
|
|
283
|
-
// clearInterval(monitorTimer)
|
|
284
|
-
// monitorTimer = null
|
|
285
|
-
// console.log(
|
|
286
|
-
// stringify({
|
|
287
|
-
// message: '监控已停止',
|
|
288
|
-
// type: 'monitor_stop',
|
|
289
|
-
// }),
|
|
290
|
-
// )
|
|
291
|
-
// }
|
|
292
|
-
// }
|
|
293
|
-
// // 自动启动监控(可选,如果不想自动启动可以注释掉)
|
|
294
|
-
// if (process.env.NODE_ENV !== 'test') {
|
|
295
|
-
// setTimeout(() => {
|
|
296
|
-
// startMonitoring()
|
|
297
|
-
// }, 3000) // 延迟3秒启动,避免服务启动时的干扰
|
|
298
|
-
// }
|