feat: usar arranque como último cambio e introducir métrica de edad

Co-authored-by: aider (openrouter/openai/gpt-5) <aider@aider.chat>
main
brobert 1 month ago
parent de9bfba9aa
commit 844204f60a

@ -9,6 +9,7 @@ export class MaintenanceService {
private static _lastRestartAttempt: number = 0; private static _lastRestartAttempt: number = 0;
private static _lastEvolutionState: string | null = null; private static _lastEvolutionState: string | null = null;
private static _lastStateChangeTs: number = 0; private static _lastStateChangeTs: number = 0;
private static readonly _processStartSec: number = Math.floor(Date.now() / 1000);
private static get retentionDays(): number { private static get retentionDays(): number {
const v = Number(process.env.GROUP_MEMBERS_INACTIVE_RETENTION_DAYS); const v = Number(process.env.GROUP_MEMBERS_INACTIVE_RETENTION_DAYS);
@ -160,8 +161,8 @@ export class MaintenanceService {
// Logging solo en primer muestreo o cuando cambie // Logging solo en primer muestreo o cuando cambie
if (!prev) { if (!prev) {
console.log(`[HealthCheck] Estado inicial de la instancia '${instance}': ${newState}`); console.log(`[HealthCheck] Estado inicial de la instancia '${instance}': ${newState}`);
this._lastStateChangeTs = nowSec; this._lastStateChangeTs = this._processStartSec;
try { Metrics.set('evolution_instance_last_state_change_ts', nowSec, { instance: String(instance || '') }); } catch {} try { Metrics.set('evolution_instance_last_state_change_ts', this._processStartSec, { instance: String(instance || '') }); } catch {}
} else if (prev !== newState) { } else if (prev !== newState) {
console.log(`[HealthCheck] Cambio de estado en instancia '${instance}': ${prev}${newState}`); console.log(`[HealthCheck] Cambio de estado en instancia '${instance}': ${prev}${newState}`);
this._lastStateChangeTs = nowSec; this._lastStateChangeTs = nowSec;
@ -172,6 +173,9 @@ export class MaintenanceService {
} }
this._lastEvolutionState = newState; this._lastEvolutionState = newState;
try {
Metrics.set('evolution_instance_state_age_seconds', Math.max(0, nowSec - this._lastStateChangeTs), { instance: String(instance || '') });
} catch {}
}; };
try { try {

Loading…
Cancel
Save