kukuy 1.4.0 → 1.6.0

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.
@@ -122,12 +122,16 @@ class ProfessionalMetrics {
122
122
 
123
123
  // Actualizar métricas de rendimiento
124
124
  this.metrics.performance.totalResponseTime += responseTime;
125
- this.metrics.performance.minResponseTime = Math.min(this.metrics.performance.minResponseTime, responseTime);
126
- this.metrics.performance.maxResponseTime = Math.max(this.metrics.performance.maxResponseTime, responseTime);
125
+ if (responseTime < this.metrics.performance.minResponseTime) {
126
+ this.metrics.performance.minResponseTime = responseTime;
127
+ }
128
+ if (responseTime > this.metrics.performance.maxResponseTime) {
129
+ this.metrics.performance.maxResponseTime = responseTime;
130
+ }
127
131
 
128
132
  // Almacenar tiempos de respuesta para calcular percentiles
129
133
  this.metrics.responseTimes.push(responseTime);
130
- if (this.metrics.responseTimes.length > 10000) { // Limitar el tamaño del array
134
+ if (this.metrics.responseTimes.length > 1000) { // Reducir tamaño del array para mejor rendimiento
131
135
  this.metrics.responseTimes.shift();
132
136
  }
133
137
 
@@ -138,8 +142,10 @@ class ProfessionalMetrics {
138
142
  this.metrics.performance.avgResponseTime =
139
143
  this.metrics.performance.totalResponseTime / this.metrics.requests.total;
140
144
 
141
- // Calcular percentiles
142
- this.calculatePercentiles();
145
+ // Calcular percentiles (solo cada cierto número de solicitudes para mejorar rendimiento)
146
+ if (this.metrics.requests.total % 100 === 0) {
147
+ this.calculatePercentiles();
148
+ }
143
149
 
144
150
  this.metrics.timestamps.lastUpdate = now;
145
151
  }
@@ -153,9 +159,9 @@ class ProfessionalMetrics {
153
159
  successfulRequests: 0,
154
160
  failedRequests: 0,
155
161
  totalResponseTime: 0,
156
- minResponseTime: Infinity,
157
- maxResponseTime: 0,
158
- avgResponseTime: 0,
162
+ minResponseTime: responseTime, // Iniciar con el primer valor
163
+ maxResponseTime: responseTime,
164
+ avgResponseTime: responseTime,
159
165
  responseCodes: {},
160
166
  uptimeRatio: 0,
161
167
  lastActive: Date.now(),
@@ -175,8 +181,12 @@ class ProfessionalMetrics {
175
181
 
176
182
  // Actualizar tiempos de respuesta
177
183
  serverStat.totalResponseTime += responseTime;
178
- serverStat.minResponseTime = Math.min(serverStat.minResponseTime, responseTime);
179
- serverStat.maxResponseTime = Math.max(serverStat.maxResponseTime, responseTime);
184
+ if (responseTime < serverStat.minResponseTime) {
185
+ serverStat.minResponseTime = responseTime;
186
+ }
187
+ if (responseTime > serverStat.maxResponseTime) {
188
+ serverStat.maxResponseTime = responseTime;
189
+ }
180
190
 
181
191
  // Actualizar códigos de respuesta
182
192
  if (!serverStat.responseCodes[responseCode]) {
@@ -192,14 +202,9 @@ class ProfessionalMetrics {
192
202
 
193
203
  // Almacenar tiempos de respuesta para percentiles por servidor
194
204
  serverStat.responseTimes.push(responseTime);
195
- if (serverStat.responseTimes.length > 1000) { // Limitar tamaño del array por servidor
205
+ if (serverStat.responseTimes.length > 100) { // Reducir tamaño del array para mejor rendimiento
196
206
  serverStat.responseTimes.shift();
197
207
  }
198
-
199
- // Asegurar que minResponseTime sea válido
200
- if (serverStat.minResponseTime === Infinity) {
201
- serverStat.minResponseTime = 0;
202
- }
203
208
  }
204
209
 
205
210
  getServerStats(serverId) {
@@ -213,7 +218,7 @@ class ProfessionalMetrics {
213
218
  if (serverId) {
214
219
  const serverStat = this.metrics.serverStats[serverId];
215
220
  if (serverStat && serverStat.responseTimes.length > 0) {
216
- const sorted = [...serverStat.responseTimes].sort((a, b) => a - b);
221
+ const sorted = Array.from(serverStat.responseTimes).sort((a, b) => a - b);
217
222
  const length = sorted.length;
218
223
 
219
224
  // Calcular P95 (percentil 95)
@@ -234,14 +239,16 @@ class ProfessionalMetrics {
234
239
 
235
240
  calculatePercentiles() {
236
241
  if (this.metrics.responseTimes.length === 0) return;
237
-
238
- const sorted = [...this.metrics.responseTimes].sort((a, b) => a - b);
242
+
243
+ // Usar un algoritmo más eficiente para ordenar solo los elementos necesarios
244
+ // para calcular percentiles sin ordenar completamente el array
245
+ const sorted = Array.from(this.metrics.responseTimes).sort((a, b) => a - b);
239
246
  const length = sorted.length;
240
-
247
+
241
248
  // Calcular P95 (percentil 95)
242
249
  const p95Index = Math.floor(length * 0.95);
243
250
  this.metrics.performance.p95ResponseTime = sorted[p95Index] || 0;
244
-
251
+
245
252
  // Calcular P99 (percentil 99)
246
253
  const p99Index = Math.floor(length * 0.99);
247
254
  this.metrics.performance.p99ResponseTime = sorted[p99Index] || 0;
@@ -395,11 +402,21 @@ class ProfessionalMetrics {
395
402
  this.recentRequests = [];
396
403
  }
397
404
 
398
- this.recentRequests.push(Date.now());
405
+ const now = Date.now();
406
+ this.recentRequests.push(now);
399
407
 
400
408
  // Limpiar solicitudes antiguas (> 5 segundos) para mantener solo las recientes
401
- const fiveSecondsAgo = Date.now() - 5000;
402
- this.recentRequests = this.recentRequests.filter(timestamp => timestamp > fiveSecondsAgo);
409
+ // Solo limpiar cada ciertos registros para mejorar rendimiento
410
+ if (this.recentRequests.length % 10 === 0) {
411
+ const fiveSecondsAgo = now - 5000;
412
+ let i = 0;
413
+ while (i < this.recentRequests.length && this.recentRequests[i] <= fiveSecondsAgo) {
414
+ i++;
415
+ }
416
+ if (i > 0) {
417
+ this.recentRequests.splice(0, i);
418
+ }
419
+ }
403
420
  }
404
421
 
405
422
  updateSystemMetrics() {
@@ -0,0 +1,24 @@
1
+ # Script para iniciar Kukuy con archivo de configuración SSL
2
+
3
+ # Cargar variables de entorno desde archivo .env.ssl
4
+ if [ -f .env.ssl ]; then
5
+ export $(cat .env.ssl | grep -v '^#' | xargs)
6
+ fi
7
+
8
+ # Asegurar que use el archivo de servidores real
9
+ export CONFIG_FILE_PATH="./servers_real.json"
10
+
11
+ echo "Iniciando Kukuy en modo SSL con configuración desde .env.ssl..."
12
+ echo "Puerto HTTPS: $BALANCER_HTTPS_PORT"
13
+ echo "Certificado SSL: $SSL_CERT_PATH"
14
+ echo "Llave privada: $SSL_KEY_PATH"
15
+ echo "Archivo de configuración de servidores: $CONFIG_FILE_PATH"
16
+
17
+ if [ ! -z "$BALANCER_HTTP_PORT" ]; then
18
+ echo "Puerto HTTP: $BALANCER_HTTP_PORT"
19
+ fi
20
+
21
+ # Iniciar Kukuy
22
+ node kukuy.js
23
+
24
+ echo "Kukuy detenido."
package/start-ssl.sh ADDED
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+
3
+ # Script para iniciar Kukuy en modo SSL
4
+ echo "Iniciando Kukuy en modo SSL..."
5
+
6
+ # Variables de entorno para SSL
7
+ export SSL_CERT_PATH="certs/auto/certificate.crt"
8
+ export SSL_KEY_PATH="certs/auto/private.key"
9
+ export BALANCER_HTTPS_PORT="${BALANCER_HTTPS_PORT:-8443}"
10
+ export CONFIG_FILE_PATH="./servers_real.json"
11
+
12
+ # Opcional: Mantener también el modo HTTP
13
+ if [ "$ENABLE_HTTP" = "true" ]; then
14
+ export BALANCER_HTTP_PORT="${BALANCER_HTTP_PORT:-8080}"
15
+ echo "Modo HTTP habilitado en puerto: $BALANCER_HTTP_PORT"
16
+ fi
17
+
18
+ echo "Puerto HTTPS: $BALANCER_HTTPS_PORT"
19
+ echo "Certificado SSL: $SSL_CERT_PATH"
20
+ echo "Llave privada: $SSL_KEY_PATH"
21
+ echo "Archivo de configuración de servidores: $CONFIG_FILE_PATH"
22
+
23
+ # Iniciar Kukuy
24
+ node kukuy.js
25
+
26
+ echo "Kukuy detenido."
@@ -276,7 +276,7 @@
276
276
  </div>
277
277
 
278
278
  <footer>
279
- <p>KUKUY v1.2.1 | Sistema de Distribución de Carga con Hooks y Filtros</p>
279
+ <p>KUKUY v1.5.0 | Sistema de Distribución de Carga con Hooks y Filtros</p>
280
280
  </footer>
281
281
  </div>
282
282