kempo-server 1.7.3 ā 1.7.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/CONFIG.md +501 -0
- package/README.md +13 -442
- package/UTILS.md +127 -0
- package/dist/defaultConfig.js +1 -1
- package/dist/moduleCache.js +1 -0
- package/dist/router.js +1 -1
- package/dist/serveFile.js +1 -1
- package/dist/utils/cli.js +1 -0
- package/dist/utils/fs-utils.js +1 -0
- package/package.json +7 -2
- package/scripts/build.js +57 -43
- package/tests/router-wildcard-double-asterisk.node-test.js +66 -0
- package/config-examples/development.config.json +0 -24
- package/config-examples/low-memory.config.json +0 -23
- package/config-examples/no-cache.config.json +0 -13
- package/config-examples/production.config.json +0 -38
- package/example-cache.config.json +0 -45
- package/example.config.json +0 -50
- package/utils/cache-demo.js +0 -145
- package/utils/cache-monitor.js +0 -132
package/utils/cache-monitor.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
Cache Monitor Utility
|
|
5
|
-
Displays real-time cache statistics and memory usage
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { spawn } from 'child_process';
|
|
9
|
-
import { pathToFileURL } from 'url';
|
|
10
|
-
import path from 'path';
|
|
11
|
-
import { fileURLToPath } from 'url';
|
|
12
|
-
|
|
13
|
-
const formatBytes = (bytes) => {
|
|
14
|
-
const mb = bytes / 1024 / 1024;
|
|
15
|
-
return `${mb.toFixed(2)}MB`;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const formatPercent = (value) => `${value.toFixed(1)}%`;
|
|
19
|
-
|
|
20
|
-
const clearScreen = () => process.stdout.write('\x1b[2J\x1b[0f');
|
|
21
|
-
|
|
22
|
-
const displayStats = (stats) => {
|
|
23
|
-
clearScreen();
|
|
24
|
-
console.log('='.repeat(60));
|
|
25
|
-
console.log('š¦ KEMPO SERVER - MODULE CACHE MONITOR');
|
|
26
|
-
console.log('='.repeat(60));
|
|
27
|
-
console.log();
|
|
28
|
-
|
|
29
|
-
if (!stats) {
|
|
30
|
-
console.log('ā Cache not available or disabled');
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const { cache, stats: cacheStats, memory, config } = stats;
|
|
35
|
-
|
|
36
|
-
// Cache Status
|
|
37
|
-
console.log('š CACHE STATUS');
|
|
38
|
-
console.log('-'.repeat(30));
|
|
39
|
-
console.log(`Entries: ${cache.size}/${cache.maxSize} (${((cache.size/cache.maxSize)*100).toFixed(1)}%)`);
|
|
40
|
-
console.log(`Memory: ${cache.memoryUsageMB}/${cache.maxMemoryMB}MB (${((cache.memoryUsageMB/cache.maxMemoryMB)*100).toFixed(1)}%)`);
|
|
41
|
-
console.log(`Watchers: ${cache.watchersActive} active`);
|
|
42
|
-
console.log();
|
|
43
|
-
|
|
44
|
-
// Performance Stats
|
|
45
|
-
console.log('ā” PERFORMANCE');
|
|
46
|
-
console.log('-'.repeat(30));
|
|
47
|
-
const total = cacheStats.hits + cacheStats.misses;
|
|
48
|
-
const hitRate = total === 0 ? 0 : (cacheStats.hits / total * 100);
|
|
49
|
-
console.log(`Hit Rate: ${hitRate.toFixed(1)}% (${cacheStats.hits} hits, ${cacheStats.misses} misses)`);
|
|
50
|
-
console.log(`Evictions: ${cacheStats.evictions}`);
|
|
51
|
-
console.log(`File Changes: ${cacheStats.fileChanges}`);
|
|
52
|
-
console.log();
|
|
53
|
-
|
|
54
|
-
// Memory Info
|
|
55
|
-
console.log('š§ NODE.JS MEMORY');
|
|
56
|
-
console.log('-'.repeat(30));
|
|
57
|
-
console.log(`Heap Used: ${memory.heapUsedMB}MB (${memory.heapUsagePercent}%)`);
|
|
58
|
-
console.log(`Heap Total: ${memory.heapTotalMB}MB`);
|
|
59
|
-
console.log(`RSS: ${memory.rssMB}MB`);
|
|
60
|
-
console.log();
|
|
61
|
-
|
|
62
|
-
// Configuration
|
|
63
|
-
console.log('āļø CONFIGURATION');
|
|
64
|
-
console.log('-'.repeat(30));
|
|
65
|
-
console.log(`TTL: ${Math.round(config.ttlMs / 1000)}s`);
|
|
66
|
-
console.log(`Max Heap: ${config.maxHeapUsagePercent}%`);
|
|
67
|
-
console.log(`File Watch: ${config.watchFiles ? 'ā
' : 'ā'}`);
|
|
68
|
-
console.log();
|
|
69
|
-
|
|
70
|
-
console.log(`Last updated: ${new Date().toLocaleTimeString()}`);
|
|
71
|
-
console.log('Press Ctrl+C to exit');
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// Simulate getting stats from a running server
|
|
75
|
-
// In a real implementation, you'd expose an endpoint or use IPC
|
|
76
|
-
const getStatsFromServer = async () => {
|
|
77
|
-
// This is a placeholder - in practice you'd either:
|
|
78
|
-
// 1. Add an admin endpoint to your server that returns cache stats
|
|
79
|
-
// 2. Use process communication to get stats from the running server
|
|
80
|
-
// 3. Log stats to a file that this script reads
|
|
81
|
-
|
|
82
|
-
// For demonstration, return mock stats
|
|
83
|
-
return {
|
|
84
|
-
cache: {
|
|
85
|
-
size: Math.floor(Math.random() * 100),
|
|
86
|
-
maxSize: 100,
|
|
87
|
-
memoryUsageMB: Math.random() * 50,
|
|
88
|
-
maxMemoryMB: 50,
|
|
89
|
-
watchersActive: Math.floor(Math.random() * 50)
|
|
90
|
-
},
|
|
91
|
-
stats: {
|
|
92
|
-
hits: Math.floor(Math.random() * 1000),
|
|
93
|
-
misses: Math.floor(Math.random() * 200),
|
|
94
|
-
evictions: Math.floor(Math.random() * 50),
|
|
95
|
-
fileChanges: Math.floor(Math.random() * 10)
|
|
96
|
-
},
|
|
97
|
-
memory: {
|
|
98
|
-
heapUsedMB: 45 + Math.random() * 20,
|
|
99
|
-
heapTotalMB: 70 + Math.random() * 30,
|
|
100
|
-
heapUsagePercent: 60 + Math.random() * 20,
|
|
101
|
-
rssMB: 80 + Math.random() * 40
|
|
102
|
-
},
|
|
103
|
-
config: {
|
|
104
|
-
ttlMs: 300000,
|
|
105
|
-
maxHeapUsagePercent: 70,
|
|
106
|
-
watchFiles: true
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const main = async () => {
|
|
112
|
-
console.log('Starting cache monitor...');
|
|
113
|
-
|
|
114
|
-
setInterval(async () => {
|
|
115
|
-
try {
|
|
116
|
-
const stats = await getStatsFromServer();
|
|
117
|
-
displayStats(stats);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
console.error('Error getting stats:', error.message);
|
|
120
|
-
}
|
|
121
|
-
}, 2000); // Update every 2 seconds
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// Handle Ctrl+C gracefully
|
|
125
|
-
process.on('SIGINT', () => {
|
|
126
|
-
console.log('\n\nš Cache monitor stopped');
|
|
127
|
-
process.exit(0);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
131
|
-
main();
|
|
132
|
-
}
|