feat(logging): update debug logging endpoint and enhance resource stats logging for better diagnostics
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m55s

This commit is contained in:
2026-02-24 13:46:56 +07:00
parent 657c23d237
commit 8035b7751f
5 changed files with 51 additions and 13 deletions
+44
View File
@@ -7,6 +7,25 @@ const { sendError } = require('../middleware/errorHandler');
const { decrypt } = require('../utils/encryption');
const { readServersFromS3 } = require('./serversRoutes');
const { createRosClient } = require('../services/mikrotikApplyService');
const DEBUG_ENDPOINT = 'http://192.168.10.2:7343/ingest/aa002dd6-6968-4a35-b09d-f05302d83266';
function sendDebugLog(location, message, data, hypothesisId = 'H_RS_BACKEND_SLOW') {
// #region agent log
fetch(DEBUG_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '378b5f' },
body: JSON.stringify({
sessionId: '378b5f',
runId: 'resource-stats-investigation',
hypothesisId,
location,
message,
data: data || {},
timestamp: Date.now(),
}),
}).catch(() => {});
// #endregion
}
function getMikrotikCredentials(server) {
if (!server || (server.type !== 'jumphost' && server.type !== 'home')) return null;
@@ -77,6 +96,7 @@ function parseResource(raw) {
* Внутренняя функция: возвращает данные по ресурсам роутеров (без HTTP).
*/
async function getResourceStatsData() {
const startedAt = Date.now();
const servers = await readServersFromS3();
const routers = (Array.isArray(servers) ? servers : []).filter(
(s) =>
@@ -84,9 +104,14 @@ async function getResourceStatsData() {
(String(s.type || '').toLowerCase() === 'jumphost' ||
String(s.type || '').toLowerCase() === 'home')
);
sendDebugLog('backend/routes/resourceStatsRoutes.js:getResourceStatsData-routers', 'Resource stats routers loaded', {
serversCount: Array.isArray(servers) ? servers.length : 0,
routersCount: routers.length,
});
const results = await Promise.all(
routers.map(async (server) => {
const routerStartedAt = Date.now();
const serverId = server.id || server.dns || server.ip;
const name = server.name || server.dns || server.ip || serverId;
const host = server.mikrotikHost || server.ip || server.dns;
@@ -98,6 +123,7 @@ async function getResourceStatsData() {
name,
host,
groupKey: server.groupKey || null,
durationMs: Date.now() - routerStartedAt,
error: 'MikroTik API не настроен или нет пароля',
resource: null,
};
@@ -113,6 +139,7 @@ async function getResourceStatsData() {
name,
host,
groupKey: server.groupKey || null,
durationMs: Date.now() - routerStartedAt,
error: null,
resource,
};
@@ -123,6 +150,7 @@ async function getResourceStatsData() {
name,
host,
groupKey: server.groupKey || null,
durationMs: Date.now() - routerStartedAt,
error: msg,
resource: null,
};
@@ -130,6 +158,22 @@ async function getResourceStatsData() {
})
);
const totalDurationMs = Date.now() - startedAt;
const slowRouters = results
.map((r) => ({
serverId: r.serverId,
durationMs: Number(r.durationMs || 0),
hasError: Boolean(r.error),
}))
.sort((a, b) => b.durationMs - a.durationMs)
.slice(0, 5);
sendDebugLog('backend/routes/resourceStatsRoutes.js:getResourceStatsData-done', 'Resource stats aggregate timing', {
totalDurationMs,
routersCount: results.length,
errorsCount: results.filter((r) => Boolean(r.error)).length,
slowRouters,
});
return { routers: results };
}
+1 -1
View File
@@ -14,7 +14,7 @@ const NETWORK_MAP_CACHE_KEY = 'network-map-cache/latest.json';
const DEFAULT_INTERVAL_MINUTES = 5;
const DEFAULT_LOG_MAX_LINES = 500;
const DEBUG_ENDPOINT = 'http://127.0.0.1:7343/ingest/aa002dd6-6968-4a35-b09d-f05302d83266';
const DEBUG_ENDPOINT = 'http://192.168.10.2:7343/ingest/aa002dd6-6968-4a35-b09d-f05302d83266';
function sendDebugLog(location, message, data, hypothesisId = 'H_STARTUP_SPEEDTEST') {
// #region agent log