create-fluxstack 1.7.5 โ 1.8.3
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/.dockerignore +82 -0
- package/.env.example +19 -0
- package/Dockerfile +70 -0
- package/README.md +6 -3
- package/app/client/SIMPLIFICATION.md +140 -0
- package/app/client/frontend-only.ts +1 -1
- package/app/client/src/App.tsx +148 -283
- package/app/client/src/index.css +5 -20
- package/app/client/src/lib/eden-api.ts +53 -220
- package/app/client/src/main.tsx +2 -3
- package/app/server/app.ts +20 -5
- package/app/server/backend-only.ts +15 -12
- package/app/server/controllers/users.controller.ts +57 -31
- package/app/server/index.ts +86 -96
- package/app/server/live/register-components.ts +18 -7
- package/app/server/routes/env-test.ts +110 -0
- package/app/server/routes/index.ts +1 -8
- package/app/server/routes/users.routes.ts +192 -91
- package/config/app.config.ts +2 -54
- package/config/client.config.ts +95 -0
- package/config/fluxstack.config.ts +2 -2
- package/config/index.ts +57 -22
- package/config/monitoring.config.ts +114 -0
- package/config/plugins.config.ts +80 -0
- package/config/runtime.config.ts +0 -17
- package/config/server.config.ts +50 -30
- package/core/build/bundler.ts +17 -16
- package/core/build/flux-plugins-generator.ts +34 -23
- package/core/build/index.ts +32 -31
- package/core/build/live-components-generator.ts +44 -30
- package/core/build/optimizer.ts +37 -17
- package/core/cli/command-registry.ts +4 -14
- package/core/cli/commands/plugin-deps.ts +8 -8
- package/core/cli/generators/component.ts +3 -3
- package/core/cli/generators/controller.ts +4 -4
- package/core/cli/generators/index.ts +8 -8
- package/core/cli/generators/interactive.ts +4 -4
- package/core/cli/generators/plugin.ts +3 -3
- package/core/cli/generators/prompts.ts +1 -1
- package/core/cli/generators/route.ts +27 -11
- package/core/cli/generators/service.ts +5 -5
- package/core/cli/generators/template-engine.ts +1 -1
- package/core/cli/generators/types.ts +1 -1
- package/core/cli/index.ts +158 -189
- package/core/cli/plugin-discovery.ts +3 -3
- package/core/client/hooks/index.ts +2 -2
- package/core/client/hooks/state-validator.ts +1 -1
- package/core/client/hooks/useAuth.ts +1 -1
- package/core/client/hooks/useChunkedUpload.ts +1 -1
- package/core/client/hooks/useHybridLiveComponent.ts +1 -1
- package/core/client/hooks/useWebSocket.ts +1 -1
- package/core/config/env.ts +5 -1
- package/core/config/runtime-config.ts +12 -10
- package/core/config/schema.ts +33 -2
- package/core/framework/server.ts +30 -14
- package/core/framework/types.ts +2 -2
- package/core/index.ts +31 -23
- package/core/live/ComponentRegistry.ts +1 -1
- package/core/plugins/built-in/live-components/commands/create-live-component.ts +1 -1
- package/core/plugins/built-in/live-components/index.ts +1 -1
- package/core/plugins/built-in/monitoring/index.ts +65 -161
- package/core/plugins/built-in/static/index.ts +75 -277
- package/core/plugins/built-in/swagger/index.ts +301 -231
- package/core/plugins/built-in/vite/index.ts +342 -377
- package/core/plugins/config.ts +2 -2
- package/core/plugins/dependency-manager.ts +2 -2
- package/core/plugins/discovery.ts +1 -1
- package/core/plugins/executor.ts +2 -2
- package/core/plugins/manager.ts +19 -4
- package/core/plugins/module-resolver.ts +1 -1
- package/core/plugins/registry.ts +25 -21
- package/core/plugins/types.ts +147 -5
- package/core/server/backend-entry.ts +51 -0
- package/core/server/framework.ts +2 -2
- package/core/server/live/ComponentRegistry.ts +9 -26
- package/core/server/live/FileUploadManager.ts +1 -1
- package/core/server/live/auto-generated-components.ts +26 -0
- package/core/server/live/websocket-plugin.ts +211 -19
- package/core/server/middleware/errorHandling.ts +1 -1
- package/core/server/middleware/index.ts +4 -4
- package/core/server/plugins/database.ts +1 -2
- package/core/server/plugins/static-files-plugin.ts +259 -231
- package/core/server/plugins/swagger.ts +1 -1
- package/core/server/services/BaseService.ts +1 -1
- package/core/server/services/ServiceContainer.ts +1 -1
- package/core/server/services/index.ts +4 -4
- package/core/server/standalone.ts +16 -1
- package/core/testing/index.ts +1 -1
- package/core/testing/setup.ts +1 -1
- package/core/types/plugin.ts +6 -0
- package/core/utils/build-logger.ts +324 -0
- package/core/utils/config-schema.ts +2 -6
- package/core/utils/helpers.ts +14 -9
- package/core/utils/logger/startup-banner.ts +7 -33
- package/core/utils/regenerate-files.ts +69 -0
- package/core/utils/version.ts +6 -6
- package/create-fluxstack.ts +68 -25
- package/fluxstack.config.ts +138 -252
- package/package.json +3 -18
- package/plugins/crypto-auth/index.ts +52 -47
- package/plugins/crypto-auth/server/AuthMiddleware.ts +1 -1
- package/plugins/crypto-auth/server/middlewares/helpers.ts +16 -1
- package/vitest.config.ts +17 -26
- package/app/client/src/App.css +0 -883
- package/app/client/src/components/ErrorBoundary.tsx +0 -107
- package/app/client/src/components/ErrorDisplay.css +0 -365
- package/app/client/src/components/ErrorDisplay.tsx +0 -258
- package/app/client/src/components/FluxStackConfig.tsx +0 -1321
- package/app/client/src/components/HybridLiveCounter.tsx +0 -140
- package/app/client/src/components/LiveClock.tsx +0 -286
- package/app/client/src/components/MainLayout.tsx +0 -388
- package/app/client/src/components/SidebarNavigation.tsx +0 -391
- package/app/client/src/components/StateDemo.tsx +0 -178
- package/app/client/src/components/SystemMonitor.tsx +0 -1044
- package/app/client/src/components/UserProfile.tsx +0 -809
- package/app/client/src/hooks/useAuth.ts +0 -39
- package/app/client/src/hooks/useNotifications.ts +0 -56
- package/app/client/src/lib/errors.ts +0 -340
- package/app/client/src/lib/hooks/useErrorHandler.ts +0 -258
- package/app/client/src/lib/index.ts +0 -45
- package/app/client/src/pages/ApiDocs.tsx +0 -182
- package/app/client/src/pages/CryptoAuthPage.tsx +0 -394
- package/app/client/src/pages/Demo.tsx +0 -174
- package/app/client/src/pages/HybridLive.tsx +0 -263
- package/app/client/src/pages/Overview.tsx +0 -155
- package/app/client/src/store/README.md +0 -43
- package/app/client/src/store/index.ts +0 -16
- package/app/client/src/store/slices/uiSlice.ts +0 -151
- package/app/client/src/store/slices/userSlice.ts +0 -161
- package/app/client/src/test/README.md +0 -257
- package/app/client/src/test/setup.ts +0 -70
- package/app/client/src/test/types.ts +0 -12
- package/app/server/live/CounterComponent.ts +0 -191
- package/app/server/live/FluxStackConfig.ts +0 -534
- package/app/server/live/SidebarNavigation.ts +0 -157
- package/app/server/live/SystemMonitor.ts +0 -595
- package/app/server/live/SystemMonitorIntegration.ts +0 -151
- package/app/server/live/UserProfileComponent.ts +0 -141
- package/app/server/middleware/auth.ts +0 -136
- package/app/server/middleware/errorHandling.ts +0 -252
- package/app/server/middleware/index.ts +0 -10
- package/app/server/middleware/rateLimit.ts +0 -193
- package/app/server/middleware/requestLogging.ts +0 -215
- package/app/server/middleware/validation.ts +0 -270
- package/app/server/routes/config.ts +0 -145
- package/app/server/routes/crypto-auth-demo.routes.ts +0 -167
- package/app/server/routes/example-with-crypto-auth.routes.ts +0 -235
- package/app/server/routes/exemplo-posts.routes.ts +0 -161
- package/app/server/routes/upload.ts +0 -92
- package/app/server/services/NotificationService.ts +0 -302
- package/app/server/services/UserService.ts +0 -222
- package/app/server/services/index.ts +0 -46
- package/app/server/types/index.ts +0 -1
- package/config/build.config.ts +0 -24
|
@@ -1,595 +0,0 @@
|
|
|
1
|
-
// ๐ฅ System Monitor Live Component
|
|
2
|
-
|
|
3
|
-
import { LiveComponent } from '@/core/types/types'
|
|
4
|
-
import { componentRegistry } from '@/core/server/live/ComponentRegistry'
|
|
5
|
-
|
|
6
|
-
export interface SystemMonitorState {
|
|
7
|
-
// Real-time metrics
|
|
8
|
-
totalComponents: number
|
|
9
|
-
activeConnections: number
|
|
10
|
-
totalRooms: number
|
|
11
|
-
messagesPerSecond: number
|
|
12
|
-
averageResponseTime: number
|
|
13
|
-
|
|
14
|
-
// Component breakdown
|
|
15
|
-
componentsByType: Record<string, number>
|
|
16
|
-
roomDetails: Record<string, number>
|
|
17
|
-
|
|
18
|
-
// Performance metrics
|
|
19
|
-
memoryUsage: {
|
|
20
|
-
used: number
|
|
21
|
-
total: number
|
|
22
|
-
percentage: number
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Recent activity
|
|
26
|
-
recentConnections: Array<{
|
|
27
|
-
id: string
|
|
28
|
-
timestamp: number
|
|
29
|
-
componentType: string
|
|
30
|
-
status: 'connected' | 'disconnected' | 'rehydrated'
|
|
31
|
-
}>
|
|
32
|
-
|
|
33
|
-
recentMessages: Array<{
|
|
34
|
-
id: string
|
|
35
|
-
timestamp: number
|
|
36
|
-
type: string
|
|
37
|
-
componentId: string
|
|
38
|
-
success: boolean
|
|
39
|
-
responseTime?: number
|
|
40
|
-
}>
|
|
41
|
-
|
|
42
|
-
// System health
|
|
43
|
-
systemHealth: {
|
|
44
|
-
status: 'healthy' | 'warning' | 'critical'
|
|
45
|
-
uptime: number
|
|
46
|
-
lastRestart: number
|
|
47
|
-
errors: number
|
|
48
|
-
warnings: number
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Auto-refresh settings
|
|
52
|
-
autoRefresh: boolean
|
|
53
|
-
refreshInterval: number
|
|
54
|
-
lastUpdated: number
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export class SystemMonitor extends LiveComponent<SystemMonitorState> {
|
|
58
|
-
private refreshTimer: NodeJS.Timeout | null = null
|
|
59
|
-
private pushTimer: NodeJS.Timeout | null = null
|
|
60
|
-
private messageCount = 0
|
|
61
|
-
private lastMessageTime = Date.now()
|
|
62
|
-
private responseTimes: number[] = []
|
|
63
|
-
private startTime = Date.now()
|
|
64
|
-
private pushInterval = 1000 // Push every 1 second
|
|
65
|
-
private isActive = true // Control flag for stopping all activities
|
|
66
|
-
private version = 1 // Component version
|
|
67
|
-
|
|
68
|
-
constructor(initialState: SystemMonitorState, ws: any, options?: any) {
|
|
69
|
-
super(initialState, ws, options)
|
|
70
|
-
|
|
71
|
-
// Set default state
|
|
72
|
-
this.state = {
|
|
73
|
-
totalComponents: 0,
|
|
74
|
-
activeConnections: 0,
|
|
75
|
-
totalRooms: 0,
|
|
76
|
-
messagesPerSecond: 0,
|
|
77
|
-
averageResponseTime: 0,
|
|
78
|
-
componentsByType: {},
|
|
79
|
-
roomDetails: {},
|
|
80
|
-
memoryUsage: {
|
|
81
|
-
used: 0,
|
|
82
|
-
total: 0,
|
|
83
|
-
percentage: 0
|
|
84
|
-
},
|
|
85
|
-
recentConnections: [],
|
|
86
|
-
recentMessages: [],
|
|
87
|
-
systemHealth: {
|
|
88
|
-
status: 'healthy',
|
|
89
|
-
uptime: 0,
|
|
90
|
-
lastRestart: Date.now(),
|
|
91
|
-
errors: 0,
|
|
92
|
-
warnings: 0
|
|
93
|
-
},
|
|
94
|
-
autoRefresh: true,
|
|
95
|
-
refreshInterval: 2000, // 2 seconds
|
|
96
|
-
lastUpdated: Date.now(),
|
|
97
|
-
...initialState
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Start auto-refresh if enabled
|
|
101
|
-
if (this.state.autoRefresh) {
|
|
102
|
-
this.startAutoRefresh()
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Start automatic push timer
|
|
106
|
-
this.startAutoPush()
|
|
107
|
-
|
|
108
|
-
// Initial data collection with push
|
|
109
|
-
this.collectMetricsWithPush()
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Start auto-refresh timer
|
|
113
|
-
async startAutoRefresh() {
|
|
114
|
-
if (this.refreshTimer) {
|
|
115
|
-
clearInterval(this.refreshTimer)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
this.refreshTimer = setInterval(() => {
|
|
119
|
-
this.collectMetricsWithPush()
|
|
120
|
-
}, this.state.refreshInterval)
|
|
121
|
-
|
|
122
|
-
console.log(`๐ SystemMonitor: Auto-refresh started (${this.state.refreshInterval}ms)`)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Stop auto-refresh timer
|
|
126
|
-
async stopAutoRefresh() {
|
|
127
|
-
if (this.refreshTimer) {
|
|
128
|
-
clearInterval(this.refreshTimer)
|
|
129
|
-
this.refreshTimer = null
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
console.log('โน๏ธ SystemMonitor: Auto-refresh stopped')
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Start automatic push timer
|
|
136
|
-
async startAutoPush() {
|
|
137
|
-
if (this.pushTimer) {
|
|
138
|
-
clearInterval(this.pushTimer)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
this.pushTimer = setInterval(() => {
|
|
142
|
-
this.sendLiveUpdate()
|
|
143
|
-
}, this.pushInterval)
|
|
144
|
-
|
|
145
|
-
console.log(`๐ก SystemMonitor: Auto-push started (${this.pushInterval}ms)`)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Stop automatic push timer
|
|
149
|
-
async stopAutoPush() {
|
|
150
|
-
if (this.pushTimer) {
|
|
151
|
-
clearInterval(this.pushTimer)
|
|
152
|
-
this.pushTimer = null
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
console.log('โน๏ธ SystemMonitor: Auto-push stopped')
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Send live update to frontend
|
|
159
|
-
private sendLiveUpdate() {
|
|
160
|
-
if (!this.isActive) {
|
|
161
|
-
return // Stop sending updates if component is not active
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
try {
|
|
165
|
-
const quickMetrics = {
|
|
166
|
-
timestamp: Date.now(),
|
|
167
|
-
uptime: Math.round((Date.now() - this.startTime) / 1000),
|
|
168
|
-
connections: componentRegistry.getStats().connections,
|
|
169
|
-
components: componentRegistry.getStats().components,
|
|
170
|
-
memoryPercentage: this.state.memoryUsage.percentage,
|
|
171
|
-
healthStatus: this.state.systemHealth.status,
|
|
172
|
-
lastActivity: Math.max(
|
|
173
|
-
...this.state.recentMessages.map(m => m.timestamp),
|
|
174
|
-
...this.state.recentConnections.map(c => c.timestamp),
|
|
175
|
-
0
|
|
176
|
-
)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
this.pushUpdate({
|
|
180
|
-
type: 'LIVE_UPDATE',
|
|
181
|
-
...quickMetrics
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
} catch (error: any) {
|
|
185
|
-
console.warn('โ ๏ธ SystemMonitor: Failed to send live update:', error.message)
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Toggle auto-refresh
|
|
190
|
-
async toggleAutoRefresh() {
|
|
191
|
-
const newAutoRefresh = !this.state.autoRefresh
|
|
192
|
-
|
|
193
|
-
this.setState({
|
|
194
|
-
autoRefresh: newAutoRefresh
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
if (newAutoRefresh) {
|
|
198
|
-
this.startAutoRefresh()
|
|
199
|
-
this.startAutoPush() // Also restart push when enabling
|
|
200
|
-
} else {
|
|
201
|
-
this.stopAutoRefresh()
|
|
202
|
-
this.stopAutoPush() // Also stop push when disabling
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
this.emit('AUTO_REFRESH_TOGGLED', {
|
|
206
|
-
enabled: newAutoRefresh,
|
|
207
|
-
timestamp: Date.now()
|
|
208
|
-
})
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Set refresh interval
|
|
212
|
-
async setRefreshInterval(data: { interval: number }) {
|
|
213
|
-
if (data.interval < 500 || data.interval > 60000) {
|
|
214
|
-
throw new Error('Refresh interval must be between 500ms and 60s')
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
this.setState({
|
|
218
|
-
refreshInterval: data.interval
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
// Restart auto-refresh with new interval
|
|
222
|
-
if (this.state.autoRefresh) {
|
|
223
|
-
this.startAutoRefresh()
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
this.emit('REFRESH_INTERVAL_CHANGED', {
|
|
227
|
-
interval: data.interval,
|
|
228
|
-
timestamp: Date.now()
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
console.log(`โฑ๏ธ SystemMonitor: Refresh interval set to ${data.interval}ms`)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Set push interval for live updates
|
|
235
|
-
async setPushInterval(data: { interval: number }) {
|
|
236
|
-
if (data.interval < 100 || data.interval > 10000) {
|
|
237
|
-
throw new Error('Push interval must be between 100ms and 10s')
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
this.pushInterval = data.interval
|
|
241
|
-
|
|
242
|
-
// Restart push timer with new interval
|
|
243
|
-
this.startAutoPush()
|
|
244
|
-
|
|
245
|
-
this.emit('PUSH_INTERVAL_CHANGED', {
|
|
246
|
-
interval: data.interval,
|
|
247
|
-
timestamp: Date.now()
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
console.log(`๐ก SystemMonitor: Push interval set to ${data.interval}ms`)
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Collect all system metrics
|
|
254
|
-
async collectMetrics() {
|
|
255
|
-
try {
|
|
256
|
-
const registryStats = componentRegistry.getStats()
|
|
257
|
-
const memUsage = process.memoryUsage()
|
|
258
|
-
const uptime = Date.now() - this.startTime
|
|
259
|
-
|
|
260
|
-
// Calculate messages per second
|
|
261
|
-
const now = Date.now()
|
|
262
|
-
const timeDiff = (now - this.lastMessageTime) / 1000
|
|
263
|
-
const messagesPerSecond = timeDiff > 0 ? this.messageCount / timeDiff : 0
|
|
264
|
-
|
|
265
|
-
// Calculate average response time
|
|
266
|
-
const avgResponseTime = this.responseTimes.length > 0
|
|
267
|
-
? this.responseTimes.reduce((a, b) => a + b, 0) / this.responseTimes.length
|
|
268
|
-
: 0
|
|
269
|
-
|
|
270
|
-
// Determine system health
|
|
271
|
-
const systemHealth = this.calculateSystemHealth(registryStats, memUsage)
|
|
272
|
-
|
|
273
|
-
// Update state with new metrics
|
|
274
|
-
this.setState({
|
|
275
|
-
totalComponents: registryStats.components,
|
|
276
|
-
activeConnections: registryStats.connections,
|
|
277
|
-
totalRooms: registryStats.rooms,
|
|
278
|
-
messagesPerSecond: Math.round(messagesPerSecond * 100) / 100,
|
|
279
|
-
averageResponseTime: Math.round(avgResponseTime * 100) / 100,
|
|
280
|
-
componentsByType: this.getComponentsByType(),
|
|
281
|
-
roomDetails: registryStats.roomDetails,
|
|
282
|
-
memoryUsage: {
|
|
283
|
-
used: Math.round(memUsage.heapUsed / 1024 / 1024 * 100) / 100, // MB
|
|
284
|
-
total: Math.round(memUsage.heapTotal / 1024 / 1024 * 100) / 100, // MB
|
|
285
|
-
percentage: Math.round((memUsage.heapUsed / memUsage.heapTotal) * 100)
|
|
286
|
-
},
|
|
287
|
-
systemHealth: {
|
|
288
|
-
...this.state.systemHealth,
|
|
289
|
-
status: systemHealth.status,
|
|
290
|
-
uptime: Math.round(uptime / 1000), // seconds
|
|
291
|
-
},
|
|
292
|
-
lastUpdated: Date.now()
|
|
293
|
-
})
|
|
294
|
-
|
|
295
|
-
// Push automatic update to frontend
|
|
296
|
-
this.pushUpdate({
|
|
297
|
-
type: 'METRICS_UPDATED',
|
|
298
|
-
timestamp: Date.now(),
|
|
299
|
-
metrics: {
|
|
300
|
-
components: registryStats.components,
|
|
301
|
-
connections: registryStats.connections,
|
|
302
|
-
rooms: registryStats.rooms,
|
|
303
|
-
messagesPerSecond: Math.round(messagesPerSecond * 100) / 100,
|
|
304
|
-
memoryUsage: this.state.memoryUsage,
|
|
305
|
-
systemHealth: this.state.systemHealth
|
|
306
|
-
}
|
|
307
|
-
})
|
|
308
|
-
|
|
309
|
-
this.emit('METRICS_UPDATED', {
|
|
310
|
-
timestamp: Date.now(),
|
|
311
|
-
metrics: {
|
|
312
|
-
components: registryStats.components,
|
|
313
|
-
connections: registryStats.connections,
|
|
314
|
-
rooms: registryStats.rooms,
|
|
315
|
-
messagesPerSecond: Math.round(messagesPerSecond * 100) / 100
|
|
316
|
-
}
|
|
317
|
-
})
|
|
318
|
-
|
|
319
|
-
} catch (error: any) {
|
|
320
|
-
console.error('โ SystemMonitor: Error collecting metrics:', error.message)
|
|
321
|
-
this.incrementErrorCount()
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// Calculate system health based on metrics
|
|
326
|
-
private calculateSystemHealth(stats: any, memUsage: any) {
|
|
327
|
-
let status: 'healthy' | 'warning' | 'critical' = 'healthy'
|
|
328
|
-
|
|
329
|
-
// Check memory usage
|
|
330
|
-
const memPercentage = (memUsage.heapUsed / memUsage.heapTotal) * 100
|
|
331
|
-
if (memPercentage > 90) {
|
|
332
|
-
status = 'critical'
|
|
333
|
-
} else if (memPercentage > 75) {
|
|
334
|
-
status = 'warning'
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// Check connection count (arbitrary thresholds)
|
|
338
|
-
if (stats.connections > 100) {
|
|
339
|
-
status = status === 'critical' ? 'critical' : 'warning'
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// Check error rate
|
|
343
|
-
if (this.state.systemHealth.errors > 10) {
|
|
344
|
-
status = 'critical'
|
|
345
|
-
} else if (this.state.systemHealth.errors > 5) {
|
|
346
|
-
status = status === 'critical' ? 'critical' : 'warning'
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return { status }
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// Get component breakdown by type
|
|
353
|
-
private getComponentsByType(): Record<string, number> {
|
|
354
|
-
// This would ideally be integrated with the registry
|
|
355
|
-
// For now, return mock data based on known components
|
|
356
|
-
return {
|
|
357
|
-
'UserProfile': 1,
|
|
358
|
-
'SidebarNavigation': 1,
|
|
359
|
-
'SystemMonitor': 1,
|
|
360
|
-
'Counter': 0,
|
|
361
|
-
'TestComponent': 0
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// Record a new connection event
|
|
366
|
-
async recordConnection(data: { componentType: string; status: 'connected' | 'disconnected' | 'rehydrated' }) {
|
|
367
|
-
const connectionEvent = {
|
|
368
|
-
id: `conn-${Date.now()}-${Math.random().toString(36).substr(2, 6)}`,
|
|
369
|
-
timestamp: Date.now(),
|
|
370
|
-
componentType: data.componentType,
|
|
371
|
-
status: data.status
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Add to recent connections (keep last 50)
|
|
375
|
-
const recentConnections = [connectionEvent, ...this.state.recentConnections].slice(0, 50)
|
|
376
|
-
|
|
377
|
-
this.setState({ recentConnections })
|
|
378
|
-
|
|
379
|
-
this.emit('CONNECTION_RECORDED', connectionEvent)
|
|
380
|
-
|
|
381
|
-
console.log(`๐ SystemMonitor: Recorded ${data.status} for ${data.componentType}`)
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// Record a new message event
|
|
385
|
-
async recordMessage(data: { type: string; componentId: string; success: boolean; responseTime?: number }) {
|
|
386
|
-
const messageEvent = {
|
|
387
|
-
id: `msg-${Date.now()}-${Math.random().toString(36).substr(2, 6)}`,
|
|
388
|
-
timestamp: Date.now(),
|
|
389
|
-
type: data.type,
|
|
390
|
-
componentId: data.componentId,
|
|
391
|
-
success: data.success,
|
|
392
|
-
responseTime: data.responseTime
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// Add to recent messages (keep last 100)
|
|
396
|
-
const recentMessages = [messageEvent, ...this.state.recentMessages].slice(0, 100)
|
|
397
|
-
|
|
398
|
-
this.setState({ recentMessages })
|
|
399
|
-
|
|
400
|
-
// Update response time tracking
|
|
401
|
-
if (data.responseTime) {
|
|
402
|
-
this.responseTimes.push(data.responseTime)
|
|
403
|
-
if (this.responseTimes.length > 100) {
|
|
404
|
-
this.responseTimes = this.responseTimes.slice(-100)
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// Update message count for rate calculation
|
|
409
|
-
this.messageCount++
|
|
410
|
-
|
|
411
|
-
this.emit('MESSAGE_RECORDED', messageEvent)
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// Increment error count
|
|
415
|
-
private incrementErrorCount() {
|
|
416
|
-
this.setState({
|
|
417
|
-
systemHealth: {
|
|
418
|
-
...this.state.systemHealth,
|
|
419
|
-
errors: this.state.systemHealth.errors + 1
|
|
420
|
-
}
|
|
421
|
-
})
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// Clear all recent activity
|
|
425
|
-
async clearActivity() {
|
|
426
|
-
this.setState({
|
|
427
|
-
recentConnections: [],
|
|
428
|
-
recentMessages: [],
|
|
429
|
-
systemHealth: {
|
|
430
|
-
...this.state.systemHealth,
|
|
431
|
-
errors: 0,
|
|
432
|
-
warnings: 0
|
|
433
|
-
}
|
|
434
|
-
})
|
|
435
|
-
|
|
436
|
-
// Reset counters
|
|
437
|
-
this.messageCount = 0
|
|
438
|
-
this.lastMessageTime = Date.now()
|
|
439
|
-
this.responseTimes = []
|
|
440
|
-
|
|
441
|
-
this.emit('ACTIVITY_CLEARED', {
|
|
442
|
-
timestamp: Date.now()
|
|
443
|
-
})
|
|
444
|
-
|
|
445
|
-
console.log('๐งน SystemMonitor: Activity cleared')
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// Get detailed system info
|
|
449
|
-
async getSystemInfo() {
|
|
450
|
-
const info = {
|
|
451
|
-
nodeVersion: process.version,
|
|
452
|
-
platform: process.platform,
|
|
453
|
-
arch: process.arch,
|
|
454
|
-
uptime: process.uptime(),
|
|
455
|
-
pid: process.pid,
|
|
456
|
-
execPath: process.execPath,
|
|
457
|
-
cwd: process.cwd(),
|
|
458
|
-
timestamp: Date.now()
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
this.emit('SYSTEM_INFO_REQUESTED', info)
|
|
462
|
-
|
|
463
|
-
return info
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// Force metrics refresh
|
|
467
|
-
async refreshMetrics() {
|
|
468
|
-
await this.collectMetrics()
|
|
469
|
-
|
|
470
|
-
this.emit('METRICS_REFRESHED', {
|
|
471
|
-
timestamp: Date.now()
|
|
472
|
-
})
|
|
473
|
-
|
|
474
|
-
console.log('๐ SystemMonitor: Metrics refreshed manually')
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// Emergency stop - stops everything immediately
|
|
478
|
-
async emergencyStop() {
|
|
479
|
-
console.log('๐จ SystemMonitor: EMERGENCY STOP activated')
|
|
480
|
-
|
|
481
|
-
// Stop all timers
|
|
482
|
-
this.isActive = false
|
|
483
|
-
|
|
484
|
-
if (this.refreshTimer) {
|
|
485
|
-
clearInterval(this.refreshTimer)
|
|
486
|
-
this.refreshTimer = null
|
|
487
|
-
}
|
|
488
|
-
if (this.pushTimer) {
|
|
489
|
-
clearInterval(this.pushTimer)
|
|
490
|
-
this.pushTimer = null
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// Update state
|
|
494
|
-
this.setState({
|
|
495
|
-
autoRefresh: false
|
|
496
|
-
})
|
|
497
|
-
|
|
498
|
-
this.emit('EMERGENCY_STOP', {
|
|
499
|
-
timestamp: Date.now(),
|
|
500
|
-
reason: 'Manual emergency stop'
|
|
501
|
-
})
|
|
502
|
-
|
|
503
|
-
console.log('๐ SystemMonitor: All activities stopped via emergency stop')
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
// Push automatic updates to frontend
|
|
507
|
-
private pushUpdate(data: any) {
|
|
508
|
-
if (!this.isActive) {
|
|
509
|
-
return // Stop all push updates if component is not active
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
try {
|
|
513
|
-
// Force state synchronization to frontend
|
|
514
|
-
this.emit('AUTO_UPDATE', data)
|
|
515
|
-
|
|
516
|
-
// Also trigger a state change notification
|
|
517
|
-
this.sendStateUpdate()
|
|
518
|
-
|
|
519
|
-
console.log('๐ก SystemMonitor: Pushed automatic update to frontend', {
|
|
520
|
-
type: data.type,
|
|
521
|
-
timestamp: data.timestamp,
|
|
522
|
-
connections: data.metrics?.connections || 0
|
|
523
|
-
})
|
|
524
|
-
|
|
525
|
-
} catch (error: any) {
|
|
526
|
-
console.warn('โ ๏ธ SystemMonitor: Failed to push update to frontend:', error.message)
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// Send state update to all connected clients
|
|
531
|
-
private sendStateUpdate() {
|
|
532
|
-
try {
|
|
533
|
-
// This will trigger the useHybridLiveComponent hook to update
|
|
534
|
-
const stateUpdate = {
|
|
535
|
-
componentId: this.id,
|
|
536
|
-
state: this.state,
|
|
537
|
-
timestamp: Date.now(),
|
|
538
|
-
version: this.version || 1
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
// Emit state change to trigger frontend update
|
|
542
|
-
this.emit('STATE_CHANGED', stateUpdate)
|
|
543
|
-
|
|
544
|
-
} catch (error: any) {
|
|
545
|
-
console.warn('โ ๏ธ SystemMonitor: Failed to send state update:', error.message)
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// Enhanced metrics collection with automatic frontend push
|
|
550
|
-
async collectMetricsWithPush() {
|
|
551
|
-
await this.collectMetrics()
|
|
552
|
-
|
|
553
|
-
// Additional push with real-time data
|
|
554
|
-
this.pushUpdate({
|
|
555
|
-
type: 'REAL_TIME_METRICS',
|
|
556
|
-
timestamp: Date.now(),
|
|
557
|
-
realTimeData: {
|
|
558
|
-
uptime: Math.round((Date.now() - this.startTime) / 1000),
|
|
559
|
-
lastUpdated: this.state.lastUpdated,
|
|
560
|
-
autoRefreshActive: this.state.autoRefresh,
|
|
561
|
-
recentActivityCount: this.state.recentMessages.length + this.state.recentConnections.length
|
|
562
|
-
}
|
|
563
|
-
})
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
// Stop all activities (method to be called externally)
|
|
567
|
-
async stopAllActivities() {
|
|
568
|
-
this.isActive = false
|
|
569
|
-
|
|
570
|
-
if (this.refreshTimer) {
|
|
571
|
-
clearInterval(this.refreshTimer)
|
|
572
|
-
this.refreshTimer = null
|
|
573
|
-
}
|
|
574
|
-
if (this.pushTimer) {
|
|
575
|
-
clearInterval(this.pushTimer)
|
|
576
|
-
this.pushTimer = null
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
console.log('๐ SystemMonitor: All activities stopped')
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
// Cleanup on destroy
|
|
583
|
-
destroy() {
|
|
584
|
-
this.isActive = false
|
|
585
|
-
|
|
586
|
-
if (this.refreshTimer) {
|
|
587
|
-
clearInterval(this.refreshTimer)
|
|
588
|
-
}
|
|
589
|
-
if (this.pushTimer) {
|
|
590
|
-
clearInterval(this.pushTimer)
|
|
591
|
-
}
|
|
592
|
-
super.destroy()
|
|
593
|
-
console.log('๐ฅ SystemMonitor: Destroyed and cleanup completed')
|
|
594
|
-
}
|
|
595
|
-
}
|