jskelet 0.6.3 → 0.6.5
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/AGENTS.md +136 -136
- package/CHANGELOG.md +633 -620
- package/LICENSE +21 -21
- package/README.md +2 -0
- package/bin/jskelet.mjs +130 -130
- package/docs/01-baslangic.md +291 -291
- package/docs/02-mimari.md +310 -310
- package/docs/03-routing.md +515 -515
- package/docs/04-render-ve-sablonlar.md +700 -661
- package/docs/05-islands.md +486 -486
- package/docs/06-cache.md +1467 -1443
- package/docs/07-yapilandirma.md +1208 -1197
- package/docs/08-build.md +429 -429
- package/docs/09-dev-araclari.md +364 -364
- package/docs/10-dagitim.md +351 -338
- package/docs/12-panel-ve-oturum.md +479 -478
- package/docs/README.md +83 -83
- package/docs/en/01-getting-started.md +298 -298
- package/docs/en/02-architecture.md +329 -329
- package/docs/en/03-routing.md +531 -531
- package/docs/en/04-rendering.md +708 -669
- package/docs/en/05-islands.md +497 -497
- package/docs/en/06-caching.md +1476 -1453
- package/docs/en/07-configuration.md +1229 -1219
- package/docs/en/08-build.md +447 -447
- package/docs/en/09-dev-tools.md +373 -373
- package/docs/en/10-deployment.md +355 -340
- package/docs/en/11-migration.md +398 -398
- package/docs/en/12-dashboards-and-sessions.md +489 -488
- package/docs/en/README.md +87 -87
- package/package.json +137 -137
- package/src/build/ensure-build.mjs +19 -19
- package/src/build/paths.mjs +153 -153
- package/src/build/resolve-peer.mjs +36 -36
- package/src/build/tasks/client.mjs +349 -349
- package/src/build/tasks/css.mjs +235 -235
- package/src/build/tasks/fonts.mjs +146 -146
- package/src/build/tasks/icons.mjs +357 -357
- package/src/build/tasks/images.mjs +244 -244
- package/src/build/tasks/precompress.mjs +78 -78
- package/src/build/tasks/templates.mjs +20 -20
- package/src/client/admin/i18n.js +764 -764
- package/src/client/admin/login.html +74 -74
- package/src/client/admin/panel.css +809 -809
- package/src/client/admin/panel.html +495 -495
- package/src/client/admin/panel.js +1251 -1251
- package/src/client/devtools/report.html +185 -185
- package/src/client/devtools/report.js +745 -745
- package/src/client/devtools/seo.js +628 -628
- package/src/client/dom.js +95 -95
- package/src/client/form.js +192 -192
- package/src/client/index.js +45 -45
- package/src/client/registry.js +305 -305
- package/src/client/safe-image.js +91 -91
- package/src/client/shared-cookie.js +225 -225
- package/src/client/store.js +36 -36
- package/src/client/swap.js +188 -188
- package/src/compile/codegen.js +336 -336
- package/src/compile/compile-all.js +149 -149
- package/src/compile/errors.js +66 -66
- package/src/compile/expr.js +409 -409
- package/src/compile/index.js +17 -17
- package/src/compile/parse.js +541 -541
- package/src/compile/resolve.js +211 -211
- package/src/compile/scan-exports.js +51 -51
- package/src/config/defaults.js +541 -534
- package/src/config/index.js +1500 -1469
- package/src/config/pattern.js +107 -107
- package/src/generate.mjs +163 -163
- package/src/http/control-flow.js +71 -71
- package/src/http/cookies-entry.js +21 -21
- package/src/http/cookies.js +277 -277
- package/src/http/request-cache.js +46 -46
- package/src/http/request-context.js +165 -165
- package/src/http/shared-cookie.js +178 -178
- package/src/index.js +101 -101
- package/src/init.mjs +232 -230
- package/src/migrate/apply.mjs +262 -262
- package/src/migrate/babel.mjs +79 -79
- package/src/migrate/classify.mjs +155 -155
- package/src/migrate/config.mjs +126 -126
- package/src/migrate/fs-walk.mjs +191 -191
- package/src/migrate/parse.mjs +26 -26
- package/src/migrate/scan.mjs +177 -177
- package/src/migrate/transform/expr-source.mjs +168 -168
- package/src/migrate/transform/island.mjs +67 -67
- package/src/migrate/transform/jsx-to-component.mjs +302 -302
- package/src/migrate/transform/jsx-to-jsk.mjs +330 -330
- package/src/migrate/transform/page-split.mjs +435 -435
- package/src/migrate/write.mjs +81 -81
- package/src/migrate.mjs +171 -171
- package/src/runtime/alias-hooks.mjs +119 -119
- package/src/runtime/register.mjs +4 -4
- package/src/server/admin/actions.js +229 -229
- package/src/server/admin/auth.js +125 -125
- package/src/server/admin/event-log.js +151 -151
- package/src/server/admin/gate.js +209 -209
- package/src/server/admin/inventory.js +188 -188
- package/src/server/admin/mount.js +56 -56
- package/src/server/admin/router.js +216 -216
- package/src/server/admin/snapshot.js +241 -241
- package/src/server/assets.js +147 -147
- package/src/server/auth/handoff.js +309 -309
- package/src/server/cache-blob.js +70 -70
- package/src/server/cache-control.js +45 -0
- package/src/server/cache-deps.js +42 -42
- package/src/server/cache-vary.js +113 -113
- package/src/server/cloudflare.js +607 -607
- package/src/server/create-app.js +366 -366
- package/src/server/data-cache.js +553 -553
- package/src/server/dev/report.js +485 -485
- package/src/server/dev/socket.js +170 -170
- package/src/server/dev/version-check.mjs +139 -139
- package/src/server/disk-cache.js +233 -233
- package/src/server/ejs-adapter.js +59 -59
- package/src/server/html-cache.js +1196 -1196
- package/src/server/image-optimizer.js +500 -500
- package/src/server/logs/access-middleware.js +66 -66
- package/src/server/logs/file-sink.js +193 -193
- package/src/server/logs/pipeline.js +165 -165
- package/src/server/logs/s3-put.js +214 -214
- package/src/server/logs/s3-sink.js +112 -112
- package/src/server/metadata.js +102 -102
- package/src/server/middleware/compression.js +205 -205
- package/src/server/middleware/csrf.js +134 -134
- package/src/server/middleware/dev-gate.js +75 -75
- package/src/server/middleware/headers.js +37 -37
- package/src/server/middleware/redirects.js +32 -32
- package/src/server/middleware/robots-txt.js +341 -341
- package/src/server/middleware/static-precompressed.js +121 -121
- package/src/server/middleware/trailing-slash.js +53 -53
- package/src/server/middleware/upstream-proxy.js +141 -141
- package/src/server/og-image.js +965 -356
- package/src/server/og-raster.mjs +21 -0
- package/src/server/port-guard.js +255 -255
- package/src/server/prewarm.js +1082 -1082
- package/src/server/redis.js +588 -588
- package/src/server/render.js +910 -910
- package/src/server/router.js +157 -157
- package/src/server/status-page.js +265 -265
- package/src/server/upstream-limiter.js +376 -376
- package/src/server/upstream-tracking.js +166 -166
- package/src/shared/cookie-domain.js +66 -66
- package/src/start.mjs +22 -22
- package/src/templates/layout.ejs +30 -30
- package/src/templates/layout.jsk +30 -30
- package/src/version.mjs +31 -31
- package/src/views/components/loader.js +101 -101
- package/src/views/helpers/html.js +102 -102
- package/src/views/helpers/tags.js +375 -375
- package/types/config/defaults.d.ts +6 -0
- package/types/config/index.d.ts +6 -0
- package/types/server/cache-control.d.ts +28 -0
- package/types/server/og-image.d.ts +51 -3
|
@@ -1,241 +1,241 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Admin paneli cache / host / process dökümü.
|
|
3
|
-
*
|
|
4
|
-
* HTML gövdesi ve veri değerleri dönmez — yalnızca meta.
|
|
5
|
-
* System sayfasındaki çubuklar **bu sürecin** payını gösterir (makine
|
|
6
|
-
* toplamına oranla), host'un genel doluluğunu değil.
|
|
7
|
-
*/
|
|
8
|
-
import fs from "node:fs";
|
|
9
|
-
import os from "node:os";
|
|
10
|
-
import path from "node:path";
|
|
11
|
-
import process from "node:process";
|
|
12
|
-
import { getConfig } from "../../config/index.js";
|
|
13
|
-
import {
|
|
14
|
-
FRAMEWORK_HOMEPAGE,
|
|
15
|
-
FRAMEWORK_LICENSE,
|
|
16
|
-
FRAMEWORK_NODE_RANGE,
|
|
17
|
-
FRAMEWORK_VERSION,
|
|
18
|
-
} from "../../version.mjs";
|
|
19
|
-
import {
|
|
20
|
-
getHtmlCacheEntries,
|
|
21
|
-
getHtmlCacheSize,
|
|
22
|
-
} from "../html-cache.js";
|
|
23
|
-
import {
|
|
24
|
-
getDataCacheEntries,
|
|
25
|
-
getDataCacheSize,
|
|
26
|
-
} from "../data-cache.js";
|
|
27
|
-
import { getRedisDetails, getRedisStatus } from "../redis.js";
|
|
28
|
-
import { getUpstreamLimiterStatus } from "../upstream-limiter.js";
|
|
29
|
-
import { getCloudflareStatus } from "../cloudflare.js";
|
|
30
|
-
import { prewarmProgress } from "../prewarm.js";
|
|
31
|
-
|
|
32
|
-
/** Listelerin üst sınırı: veri önbelleğinde on binlerce anahtar olabiliyor. */
|
|
33
|
-
const MAX_LISTED = 500;
|
|
34
|
-
|
|
35
|
-
/** Disk ölçümünde atlanan dizinler — node_modules her poll'da taranmasın. */
|
|
36
|
-
const SKIP_DIRS = new Set([
|
|
37
|
-
"node_modules",
|
|
38
|
-
".git",
|
|
39
|
-
".hg",
|
|
40
|
-
".svn",
|
|
41
|
-
"coverage",
|
|
42
|
-
".turbo",
|
|
43
|
-
".next",
|
|
44
|
-
]);
|
|
45
|
-
|
|
46
|
-
export const BOOT_ID = `${Date.now()}-${process.pid}`;
|
|
47
|
-
|
|
48
|
-
/** @type {{ usage: NodeJS.CpuUsage; at: number } | null} */
|
|
49
|
-
let cpuSample = null;
|
|
50
|
-
|
|
51
|
-
/** @type {{ at: number, bytes: number, root: string } | null} */
|
|
52
|
-
let diskSample = null;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @param {string} query Anahtar filtresi (boş → filtre yok).
|
|
56
|
-
* @returns {Promise<object>}
|
|
57
|
-
*/
|
|
58
|
-
export async function snapshot(query) {
|
|
59
|
-
const term = query.trim().toLowerCase();
|
|
60
|
-
/** @param {{ key: string }} entry */
|
|
61
|
-
const matches = (entry) => !term || entry.key.toLowerCase().includes(term);
|
|
62
|
-
|
|
63
|
-
const html = getHtmlCacheEntries();
|
|
64
|
-
const data = getDataCacheEntries();
|
|
65
|
-
|
|
66
|
-
const htmlMatched = html.filter(matches);
|
|
67
|
-
const dataMatched = data.filter(matches);
|
|
68
|
-
const usage = process.memoryUsage();
|
|
69
|
-
const host = await hostStatus();
|
|
70
|
-
const cpuPercent = sampleProcessCpu(host.cpus);
|
|
71
|
-
const appDiskBytes = await sampleAppDisk(getConfig().root);
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
boot: BOOT_ID,
|
|
75
|
-
generatedAt: Date.now(),
|
|
76
|
-
release: {
|
|
77
|
-
version: FRAMEWORK_VERSION,
|
|
78
|
-
license: FRAMEWORK_LICENSE,
|
|
79
|
-
node: FRAMEWORK_NODE_RANGE,
|
|
80
|
-
homepage: FRAMEWORK_HOMEPAGE,
|
|
81
|
-
},
|
|
82
|
-
host,
|
|
83
|
-
process: {
|
|
84
|
-
pid: process.pid,
|
|
85
|
-
node: process.version,
|
|
86
|
-
uptime: process.uptime(),
|
|
87
|
-
env: process.env.NODE_ENV ?? "production",
|
|
88
|
-
memory: { rss: usage.rss, heapUsed: usage.heapUsed },
|
|
89
|
-
/** 0–100: bu sürecin tüm çekirdek kapasitesine oranı. */
|
|
90
|
-
cpuPercent,
|
|
91
|
-
/** Proje kökünün (node_modules hariç) disk boyutu. */
|
|
92
|
-
diskBytes: appDiskBytes,
|
|
93
|
-
},
|
|
94
|
-
html: {
|
|
95
|
-
size: getHtmlCacheSize(),
|
|
96
|
-
maxEntries: getConfig().htmlMaxEntries,
|
|
97
|
-
bytes: html.reduce((total, entry) => total + entry.bytes, 0),
|
|
98
|
-
stale: html.filter((entry) => entry.stale).length,
|
|
99
|
-
matched: htmlMatched.length,
|
|
100
|
-
entries: htmlMatched
|
|
101
|
-
.sort((a, b) => b.bytes - a.bytes)
|
|
102
|
-
.slice(0, MAX_LISTED)
|
|
103
|
-
.map((entry) => ({
|
|
104
|
-
...entry,
|
|
105
|
-
url: entry.key.endsWith("?") ? entry.key.slice(0, -1) : entry.key,
|
|
106
|
-
})),
|
|
107
|
-
},
|
|
108
|
-
data: {
|
|
109
|
-
size: getDataCacheSize(),
|
|
110
|
-
maxEntries: Number(getConfig().data?.maxEntries) || 0,
|
|
111
|
-
stale: data.filter((entry) => entry.stale).length,
|
|
112
|
-
matched: dataMatched.length,
|
|
113
|
-
entries: dataMatched
|
|
114
|
-
.sort((a, b) => a.expiresIn - b.expiresIn)
|
|
115
|
-
.slice(0, MAX_LISTED),
|
|
116
|
-
},
|
|
117
|
-
redis: { ...getRedisStatus(), ...getRedisDetails() },
|
|
118
|
-
cloudflare: getCloudflareStatus(),
|
|
119
|
-
upstream: getUpstreamLimiterStatus(),
|
|
120
|
-
prewarm: { ...prewarmProgress },
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* İki örnek arasındaki `process.cpuUsage` farkından süreç CPU yüzdesi.
|
|
126
|
-
* İlk çağrıda örnek alınır ve 0 döner — panelin bir sonraki turunda anlamlı.
|
|
127
|
-
*
|
|
128
|
-
* @param {number} cores
|
|
129
|
-
* @returns {number}
|
|
130
|
-
*/
|
|
131
|
-
function sampleProcessCpu(cores) {
|
|
132
|
-
const now = Date.now();
|
|
133
|
-
const current = process.cpuUsage();
|
|
134
|
-
|
|
135
|
-
if (!cpuSample) {
|
|
136
|
-
cpuSample = { usage: current, at: now };
|
|
137
|
-
return 0;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const elapsedMs = now - cpuSample.at;
|
|
141
|
-
const delta = process.cpuUsage(cpuSample.usage);
|
|
142
|
-
cpuSample = { usage: current, at: now };
|
|
143
|
-
|
|
144
|
-
if (elapsedMs <= 0 || cores <= 0) return 0;
|
|
145
|
-
|
|
146
|
-
// user+system mikro-saniye → ms; duvar süresi × çekirdek = kapasite.
|
|
147
|
-
const cpuMs = (delta.user + delta.system) / 1000;
|
|
148
|
-
const capacityMs = elapsedMs * cores;
|
|
149
|
-
return Math.max(0, Math.min(100, (cpuMs / capacityMs) * 100));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Proje kökünün boyutu (ağır dizinler atlanır). 60 sn önbellek.
|
|
154
|
-
*
|
|
155
|
-
* @param {string} root
|
|
156
|
-
* @returns {Promise<number>}
|
|
157
|
-
*/
|
|
158
|
-
async function sampleAppDisk(root) {
|
|
159
|
-
if (diskSample && diskSample.root === root && Date.now() - diskSample.at < 60_000) {
|
|
160
|
-
return diskSample.bytes;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const bytes = await measureDir(root);
|
|
164
|
-
diskSample = { at: Date.now(), bytes, root };
|
|
165
|
-
return bytes;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @param {string} dir
|
|
170
|
-
* @returns {Promise<number>}
|
|
171
|
-
*/
|
|
172
|
-
async function measureDir(dir) {
|
|
173
|
-
let total = 0;
|
|
174
|
-
|
|
175
|
-
/** @type {string[]} */
|
|
176
|
-
const stack = [dir];
|
|
177
|
-
|
|
178
|
-
while (stack.length) {
|
|
179
|
-
const current = stack.pop();
|
|
180
|
-
if (!current) continue;
|
|
181
|
-
|
|
182
|
-
let entries;
|
|
183
|
-
try {
|
|
184
|
-
entries = await fs.promises.readdir(current, { withFileTypes: true });
|
|
185
|
-
} catch {
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
for (const entry of entries) {
|
|
190
|
-
if (entry.name === "." || entry.name === "..") continue;
|
|
191
|
-
if (entry.isDirectory() && SKIP_DIRS.has(entry.name)) continue;
|
|
192
|
-
|
|
193
|
-
const full = path.join(current, entry.name);
|
|
194
|
-
if (entry.isDirectory()) {
|
|
195
|
-
stack.push(full);
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
if (!entry.isFile()) continue;
|
|
199
|
-
|
|
200
|
-
try {
|
|
201
|
-
const stats = await fs.promises.stat(full);
|
|
202
|
-
total += stats.size;
|
|
203
|
-
} catch {
|
|
204
|
-
// silinmiş / erişilemeyen dosya
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return total;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* @returns {Promise<object>}
|
|
214
|
-
*/
|
|
215
|
-
async function hostStatus() {
|
|
216
|
-
const total = os.totalmem();
|
|
217
|
-
const free = os.freemem();
|
|
218
|
-
|
|
219
|
-
/** @type {{ path: string, total: number, free: number } | null} */
|
|
220
|
-
let disk = null;
|
|
221
|
-
|
|
222
|
-
try {
|
|
223
|
-
const root = getConfig().root;
|
|
224
|
-
const stats = await fs.promises.statfs(root);
|
|
225
|
-
disk = {
|
|
226
|
-
path: root,
|
|
227
|
-
total: stats.blocks * stats.bsize,
|
|
228
|
-
free: stats.bavail * stats.bsize,
|
|
229
|
-
};
|
|
230
|
-
} catch {
|
|
231
|
-
disk = null;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return {
|
|
235
|
-
platform: `${os.platform()} ${os.arch()}`,
|
|
236
|
-
cpus: os.cpus().length,
|
|
237
|
-
load: os.loadavg()[0],
|
|
238
|
-
memory: { total, free, used: total - free },
|
|
239
|
-
disk,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Admin paneli cache / host / process dökümü.
|
|
3
|
+
*
|
|
4
|
+
* HTML gövdesi ve veri değerleri dönmez — yalnızca meta.
|
|
5
|
+
* System sayfasındaki çubuklar **bu sürecin** payını gösterir (makine
|
|
6
|
+
* toplamına oranla), host'un genel doluluğunu değil.
|
|
7
|
+
*/
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import process from "node:process";
|
|
12
|
+
import { getConfig } from "../../config/index.js";
|
|
13
|
+
import {
|
|
14
|
+
FRAMEWORK_HOMEPAGE,
|
|
15
|
+
FRAMEWORK_LICENSE,
|
|
16
|
+
FRAMEWORK_NODE_RANGE,
|
|
17
|
+
FRAMEWORK_VERSION,
|
|
18
|
+
} from "../../version.mjs";
|
|
19
|
+
import {
|
|
20
|
+
getHtmlCacheEntries,
|
|
21
|
+
getHtmlCacheSize,
|
|
22
|
+
} from "../html-cache.js";
|
|
23
|
+
import {
|
|
24
|
+
getDataCacheEntries,
|
|
25
|
+
getDataCacheSize,
|
|
26
|
+
} from "../data-cache.js";
|
|
27
|
+
import { getRedisDetails, getRedisStatus } from "../redis.js";
|
|
28
|
+
import { getUpstreamLimiterStatus } from "../upstream-limiter.js";
|
|
29
|
+
import { getCloudflareStatus } from "../cloudflare.js";
|
|
30
|
+
import { prewarmProgress } from "../prewarm.js";
|
|
31
|
+
|
|
32
|
+
/** Listelerin üst sınırı: veri önbelleğinde on binlerce anahtar olabiliyor. */
|
|
33
|
+
const MAX_LISTED = 500;
|
|
34
|
+
|
|
35
|
+
/** Disk ölçümünde atlanan dizinler — node_modules her poll'da taranmasın. */
|
|
36
|
+
const SKIP_DIRS = new Set([
|
|
37
|
+
"node_modules",
|
|
38
|
+
".git",
|
|
39
|
+
".hg",
|
|
40
|
+
".svn",
|
|
41
|
+
"coverage",
|
|
42
|
+
".turbo",
|
|
43
|
+
".next",
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
export const BOOT_ID = `${Date.now()}-${process.pid}`;
|
|
47
|
+
|
|
48
|
+
/** @type {{ usage: NodeJS.CpuUsage; at: number } | null} */
|
|
49
|
+
let cpuSample = null;
|
|
50
|
+
|
|
51
|
+
/** @type {{ at: number, bytes: number, root: string } | null} */
|
|
52
|
+
let diskSample = null;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {string} query Anahtar filtresi (boş → filtre yok).
|
|
56
|
+
* @returns {Promise<object>}
|
|
57
|
+
*/
|
|
58
|
+
export async function snapshot(query) {
|
|
59
|
+
const term = query.trim().toLowerCase();
|
|
60
|
+
/** @param {{ key: string }} entry */
|
|
61
|
+
const matches = (entry) => !term || entry.key.toLowerCase().includes(term);
|
|
62
|
+
|
|
63
|
+
const html = getHtmlCacheEntries();
|
|
64
|
+
const data = getDataCacheEntries();
|
|
65
|
+
|
|
66
|
+
const htmlMatched = html.filter(matches);
|
|
67
|
+
const dataMatched = data.filter(matches);
|
|
68
|
+
const usage = process.memoryUsage();
|
|
69
|
+
const host = await hostStatus();
|
|
70
|
+
const cpuPercent = sampleProcessCpu(host.cpus);
|
|
71
|
+
const appDiskBytes = await sampleAppDisk(getConfig().root);
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
boot: BOOT_ID,
|
|
75
|
+
generatedAt: Date.now(),
|
|
76
|
+
release: {
|
|
77
|
+
version: FRAMEWORK_VERSION,
|
|
78
|
+
license: FRAMEWORK_LICENSE,
|
|
79
|
+
node: FRAMEWORK_NODE_RANGE,
|
|
80
|
+
homepage: FRAMEWORK_HOMEPAGE,
|
|
81
|
+
},
|
|
82
|
+
host,
|
|
83
|
+
process: {
|
|
84
|
+
pid: process.pid,
|
|
85
|
+
node: process.version,
|
|
86
|
+
uptime: process.uptime(),
|
|
87
|
+
env: process.env.NODE_ENV ?? "production",
|
|
88
|
+
memory: { rss: usage.rss, heapUsed: usage.heapUsed },
|
|
89
|
+
/** 0–100: bu sürecin tüm çekirdek kapasitesine oranı. */
|
|
90
|
+
cpuPercent,
|
|
91
|
+
/** Proje kökünün (node_modules hariç) disk boyutu. */
|
|
92
|
+
diskBytes: appDiskBytes,
|
|
93
|
+
},
|
|
94
|
+
html: {
|
|
95
|
+
size: getHtmlCacheSize(),
|
|
96
|
+
maxEntries: getConfig().htmlMaxEntries,
|
|
97
|
+
bytes: html.reduce((total, entry) => total + entry.bytes, 0),
|
|
98
|
+
stale: html.filter((entry) => entry.stale).length,
|
|
99
|
+
matched: htmlMatched.length,
|
|
100
|
+
entries: htmlMatched
|
|
101
|
+
.sort((a, b) => b.bytes - a.bytes)
|
|
102
|
+
.slice(0, MAX_LISTED)
|
|
103
|
+
.map((entry) => ({
|
|
104
|
+
...entry,
|
|
105
|
+
url: entry.key.endsWith("?") ? entry.key.slice(0, -1) : entry.key,
|
|
106
|
+
})),
|
|
107
|
+
},
|
|
108
|
+
data: {
|
|
109
|
+
size: getDataCacheSize(),
|
|
110
|
+
maxEntries: Number(getConfig().data?.maxEntries) || 0,
|
|
111
|
+
stale: data.filter((entry) => entry.stale).length,
|
|
112
|
+
matched: dataMatched.length,
|
|
113
|
+
entries: dataMatched
|
|
114
|
+
.sort((a, b) => a.expiresIn - b.expiresIn)
|
|
115
|
+
.slice(0, MAX_LISTED),
|
|
116
|
+
},
|
|
117
|
+
redis: { ...getRedisStatus(), ...getRedisDetails() },
|
|
118
|
+
cloudflare: getCloudflareStatus(),
|
|
119
|
+
upstream: getUpstreamLimiterStatus(),
|
|
120
|
+
prewarm: { ...prewarmProgress },
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* İki örnek arasındaki `process.cpuUsage` farkından süreç CPU yüzdesi.
|
|
126
|
+
* İlk çağrıda örnek alınır ve 0 döner — panelin bir sonraki turunda anlamlı.
|
|
127
|
+
*
|
|
128
|
+
* @param {number} cores
|
|
129
|
+
* @returns {number}
|
|
130
|
+
*/
|
|
131
|
+
function sampleProcessCpu(cores) {
|
|
132
|
+
const now = Date.now();
|
|
133
|
+
const current = process.cpuUsage();
|
|
134
|
+
|
|
135
|
+
if (!cpuSample) {
|
|
136
|
+
cpuSample = { usage: current, at: now };
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const elapsedMs = now - cpuSample.at;
|
|
141
|
+
const delta = process.cpuUsage(cpuSample.usage);
|
|
142
|
+
cpuSample = { usage: current, at: now };
|
|
143
|
+
|
|
144
|
+
if (elapsedMs <= 0 || cores <= 0) return 0;
|
|
145
|
+
|
|
146
|
+
// user+system mikro-saniye → ms; duvar süresi × çekirdek = kapasite.
|
|
147
|
+
const cpuMs = (delta.user + delta.system) / 1000;
|
|
148
|
+
const capacityMs = elapsedMs * cores;
|
|
149
|
+
return Math.max(0, Math.min(100, (cpuMs / capacityMs) * 100));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Proje kökünün boyutu (ağır dizinler atlanır). 60 sn önbellek.
|
|
154
|
+
*
|
|
155
|
+
* @param {string} root
|
|
156
|
+
* @returns {Promise<number>}
|
|
157
|
+
*/
|
|
158
|
+
async function sampleAppDisk(root) {
|
|
159
|
+
if (diskSample && diskSample.root === root && Date.now() - diskSample.at < 60_000) {
|
|
160
|
+
return diskSample.bytes;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const bytes = await measureDir(root);
|
|
164
|
+
diskSample = { at: Date.now(), bytes, root };
|
|
165
|
+
return bytes;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @param {string} dir
|
|
170
|
+
* @returns {Promise<number>}
|
|
171
|
+
*/
|
|
172
|
+
async function measureDir(dir) {
|
|
173
|
+
let total = 0;
|
|
174
|
+
|
|
175
|
+
/** @type {string[]} */
|
|
176
|
+
const stack = [dir];
|
|
177
|
+
|
|
178
|
+
while (stack.length) {
|
|
179
|
+
const current = stack.pop();
|
|
180
|
+
if (!current) continue;
|
|
181
|
+
|
|
182
|
+
let entries;
|
|
183
|
+
try {
|
|
184
|
+
entries = await fs.promises.readdir(current, { withFileTypes: true });
|
|
185
|
+
} catch {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
for (const entry of entries) {
|
|
190
|
+
if (entry.name === "." || entry.name === "..") continue;
|
|
191
|
+
if (entry.isDirectory() && SKIP_DIRS.has(entry.name)) continue;
|
|
192
|
+
|
|
193
|
+
const full = path.join(current, entry.name);
|
|
194
|
+
if (entry.isDirectory()) {
|
|
195
|
+
stack.push(full);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (!entry.isFile()) continue;
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
const stats = await fs.promises.stat(full);
|
|
202
|
+
total += stats.size;
|
|
203
|
+
} catch {
|
|
204
|
+
// silinmiş / erişilemeyen dosya
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return total;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @returns {Promise<object>}
|
|
214
|
+
*/
|
|
215
|
+
async function hostStatus() {
|
|
216
|
+
const total = os.totalmem();
|
|
217
|
+
const free = os.freemem();
|
|
218
|
+
|
|
219
|
+
/** @type {{ path: string, total: number, free: number } | null} */
|
|
220
|
+
let disk = null;
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
const root = getConfig().root;
|
|
224
|
+
const stats = await fs.promises.statfs(root);
|
|
225
|
+
disk = {
|
|
226
|
+
path: root,
|
|
227
|
+
total: stats.blocks * stats.bsize,
|
|
228
|
+
free: stats.bavail * stats.bsize,
|
|
229
|
+
};
|
|
230
|
+
} catch {
|
|
231
|
+
disk = null;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
platform: `${os.platform()} ${os.arch()}`,
|
|
236
|
+
cpus: os.cpus().length,
|
|
237
|
+
load: os.loadavg()[0],
|
|
238
|
+
memory: { total, free, used: total - free },
|
|
239
|
+
disk,
|
|
240
|
+
};
|
|
241
|
+
}
|