claude-flow-novice 2.2.4 ā 2.2.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/package.json +9 -8
- package/scripts/.claude-flow/metrics/agent-metrics.json +1 -0
- package/scripts/.claude-flow/metrics/performance.json +9 -0
- package/scripts/.claude-flow/metrics/task-metrics.json +10 -0
- package/scripts/CLEANUP_OPTIMIZATION_REPORT.json +312 -0
- package/scripts/CLEANUP_PERFORMANCE_OPTIMIZATION.md +387 -0
- package/scripts/CLEANUP_QUICK_START.md +268 -0
- package/scripts/CLEANUP_TEST_RESULTS.md +205 -0
- package/scripts/README.md +339 -0
- package/scripts/ace-query.sh +384 -0
- package/scripts/agent-token-analysis.js +430 -0
- package/scripts/auto-setup.js +332 -0
- package/scripts/build/README.md +167 -0
- package/scripts/build/build-config.js +27 -0
- package/scripts/build/build-prompt-copier.sh +30 -0
- package/scripts/build/performance-monitor.js +869 -0
- package/scripts/build/prepare-publish.js +150 -0
- package/scripts/build/typescript-fixer.js +621 -0
- package/scripts/build/unified-builder.sh +428 -0
- package/scripts/build/update-bin-version.js +32 -0
- package/scripts/build/validate-agents.js +238 -0
- package/scripts/build-index.js +43 -0
- package/scripts/build-orchestrator.js +320 -0
- package/scripts/check-routing-stats.cjs +122 -0
- package/scripts/ci-validation.js +375 -0
- package/scripts/cleanup-blocking-coordination.sh +420 -0
- package/scripts/cleanup-idle-sessions.sh +59 -0
- package/scripts/collect-build-metrics.js +65 -0
- package/scripts/demo/README.md +79 -0
- package/scripts/demo/autoscaling-demo-simplified.js +963 -0
- package/scripts/demo/comprehensive-dashboard-test.js +693 -0
- package/scripts/demo/confidence-log.js +87 -0
- package/scripts/demo/confidence-report.js +82 -0
- package/scripts/demo/demo-multi-swarm-coordination.js +325 -0
- package/scripts/demo/demo-production-deployment.js +399 -0
- package/scripts/demo/demo-visualization-system.js +149 -0
- package/scripts/demo/performance-analysis.cjs +71 -0
- package/scripts/demo/performance-analysis.js +71 -0
- package/scripts/demo/test-autoscaling-demo.js +314 -0
- package/scripts/dependency-optimizer.js +349 -0
- package/scripts/dependency-security-assessment.js +331 -0
- package/scripts/deploy-sdk.sh +176 -0
- package/scripts/deployment-readiness-report.json +179 -0
- package/scripts/dev/README.md +264 -0
- package/scripts/dev/claude-flow-wrapper.sh +35 -0
- package/scripts/dev/claude-monitor.py +419 -0
- package/scripts/dev/claude-sparc.sh +562 -0
- package/scripts/dev/claude-wrapper.sh +17 -0
- package/scripts/dev/demo-phase3-compliance.js +172 -0
- package/scripts/dev/demo-task-system.ts +224 -0
- package/scripts/dev/deployment-validator.js +315 -0
- package/scripts/dev/spawn-claude-terminal.sh +32 -0
- package/scripts/dev/start-portal.sh +506 -0
- package/scripts/dev/start-web-ui.js +15 -0
- package/scripts/dev/stop-portal.sh +311 -0
- package/scripts/dev/validate-examples.ts +288 -0
- package/scripts/dev/validate-phase2.cjs +451 -0
- package/scripts/dev/validate-phase2.js +785 -0
- package/scripts/dev/validate-phase3.cjs +208 -0
- package/scripts/dev/validate-security-remediation.js +1 -0
- package/scripts/ecosystem.config.cjs +90 -0
- package/scripts/fix-js-extensions.js +167 -0
- package/scripts/generate-basic-types.js +73 -0
- package/scripts/generate-changelog.js +318 -0
- package/scripts/git-hooks/pre-commit.sh +143 -0
- package/scripts/health-checks.js +634 -0
- package/scripts/hook-wrapper.sh +54 -0
- package/scripts/install/README.md +375 -0
- package/scripts/install/REDIS_SETUP_VALIDATION.json +245 -0
- package/scripts/install/check-prerequisites.js +303 -0
- package/scripts/install/config-wizard.js +606 -0
- package/scripts/install/dependency-checker.js +385 -0
- package/scripts/install/health-check.js +765 -0
- package/scripts/install/install.js +256 -0
- package/scripts/install/installation-benchmark.js +461 -0
- package/scripts/install/quick-install.js +720 -0
- package/scripts/install/quick-start-wizard.js +295 -0
- package/scripts/install/redis-cli.js +289 -0
- package/scripts/install/redis-install-guides.md +407 -0
- package/scripts/install/redis-setup.js +559 -0
- package/scripts/install/redis-test.js +278 -0
- package/scripts/install/service-manager.js +672 -0
- package/scripts/install/setup.js +832 -0
- package/scripts/install/uninstall.js +526 -0
- package/scripts/install/update.js +461 -0
- package/scripts/install-pre-commit-hook.sh +127 -0
- package/scripts/legacy/README.md +272 -0
- package/scripts/legacy/batch-fix-ts.sh +54 -0
- package/scripts/legacy/build-migration.sh +105 -0
- package/scripts/legacy/build-monitor.js +209 -0
- package/scripts/legacy/build-with-filter.sh +84 -0
- package/scripts/legacy/build-workaround.sh +71 -0
- package/scripts/legacy/fix-ts-advanced.js +358 -0
- package/scripts/legacy/fix-ts-final.sh +50 -0
- package/scripts/legacy/fix-ts-targeted.sh +49 -0
- package/scripts/legacy/fix-typescript-errors.js +305 -0
- package/scripts/legacy/force-build.sh +63 -0
- package/scripts/legacy/optimize-performance.js +400 -0
- package/scripts/legacy/performance-monitor.js +263 -0
- package/scripts/legacy/performance-monitoring.js +532 -0
- package/scripts/legacy/performance-test-runner.js +645 -0
- package/scripts/legacy/quick-fix-ts.js +281 -0
- package/scripts/legacy/safe-build.sh +63 -0
- package/scripts/memory-monitor-coordinator.js +322 -0
- package/scripts/migrate-to-sdk.sh +520 -0
- package/scripts/migration/QUICK-START.md +189 -0
- package/scripts/migration/QUICK-START.md.backup-1760135091363 +189 -0
- package/scripts/migration/README.md +464 -0
- package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md +500 -0
- package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md.backup-1760135091348 +500 -0
- package/scripts/migration/UPDATE-PATHS-README.md +464 -0
- package/scripts/migration/UPDATE-PATHS-README.md.backup-1760135091337 +464 -0
- package/scripts/migration/example-patterns.json +19 -0
- package/scripts/migration/install-arm64.js +78 -0
- package/scripts/migration/install.js +83 -0
- package/scripts/migration/migrate-hooks.js +173 -0
- package/scripts/migration/migration-examples.ts +318 -0
- package/scripts/migration/reorganize-workspace.js +504 -0
- package/scripts/migration/test-update-paths.js +359 -0
- package/scripts/migration/update-paths.js +664 -0
- package/scripts/migration/validate-migration.js +647 -0
- package/scripts/monitor-loop.sh +65 -0
- package/scripts/monitor-memory.sh +47 -0
- package/scripts/monitor-migration.js +339 -0
- package/scripts/monitor.py +43 -0
- package/scripts/monitoring/README.md +178 -0
- package/scripts/monitoring/alert-monitor.sh +220 -0
- package/scripts/monitoring/analyze-resources.sh +199 -0
- package/scripts/monitoring/dashboards/rate-limiting-dashboard.json +211 -0
- package/scripts/monitoring/dynamic-monitor.sh +85 -0
- package/scripts/monitoring/launch-stability-test.sh +184 -0
- package/scripts/monitoring/monitor-test.sh +93 -0
- package/scripts/monitoring/pre-test-validation.sh +208 -0
- package/scripts/monitoring/quick-test-alerting.sh +118 -0
- package/scripts/monitoring/quick-test-rate-limiting.sh +206 -0
- package/scripts/monitoring/rate-limiting-monitor.sh +380 -0
- package/scripts/monitoring/resource-monitor.sh +126 -0
- package/scripts/monitoring/stability-monitor.js +429 -0
- package/scripts/monitoring/test-monitor-quick.sh +54 -0
- package/scripts/monitoring/view-alerts.sh +307 -0
- package/scripts/npm-metrics-collector.js +482 -0
- package/scripts/npm-package-validation.cjs +299 -0
- package/scripts/optimization/build-optimizer.js +438 -0
- package/scripts/optimization/config-validator.js +761 -0
- package/scripts/optimization/test-optimization.js +432 -0
- package/scripts/optimization/unified-activation.js +839 -0
- package/scripts/optimize-package-swarm.js +54 -0
- package/scripts/performance/ACTIVATION_COMMANDS.md +292 -0
- package/scripts/performance/sqlite-enhanced-activation.sh +583 -0
- package/scripts/performance/test-enhanced-backend.sh +504 -0
- package/scripts/performance-monitor.js +644 -0
- package/scripts/performance-test-runner.js +698 -0
- package/scripts/post-deployment-monitoring.js +350 -0
- package/scripts/post-edit-pipeline.js +2091 -0
- package/scripts/post-install-claude-md.js +78 -0
- package/scripts/postinstall.js +79 -0
- package/scripts/pre-publish-validation.cjs +212 -0
- package/scripts/pre-publish-validation.js +429 -0
- package/scripts/redis-lua/cleanup-blocking-coordination.lua +198 -0
- package/scripts/release-announcement.js +425 -0
- package/scripts/release-notification.js +248 -0
- package/scripts/release-rollback.js +376 -0
- package/scripts/release-validation.js +460 -0
- package/scripts/rollback-sdk.sh +66 -0
- package/scripts/run-production-validation.ts +590 -0
- package/scripts/run-stability-validation.sh +687 -0
- package/scripts/security/README.md +339 -0
- package/scripts/security/deployment-validation.cjs +279 -0
- package/scripts/security/envelope-encryption-confidence-report.cjs +422 -0
- package/scripts/security/install-git-hooks.sh +132 -0
- package/scripts/security/install-git-secrets.sh +295 -0
- package/scripts/security/rotate-api-keys.js +469 -0
- package/scripts/security/ruv-swarm-safe.js +74 -0
- package/scripts/security/security-audit.cjs +538 -0
- package/scripts/security/setup-redis-auth.sh +397 -0
- package/scripts/security/validate-envelope-encryption.cjs +340 -0
- package/scripts/security-scan.js +492 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/agent-metrics.json +1 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/performance.json +9 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/task-metrics.json +10 -0
- package/scripts/switch-api.sh +158 -0
- package/scripts/sync-agents.js +290 -0
- package/scripts/test/50-agent-test.js +625 -0
- package/scripts/test/NEW_STABILITY_TEST_GUIDE.md +407 -0
- package/scripts/test/README.md +236 -0
- package/scripts/test/STABILITY_TEST_EXAMPLE.md +347 -0
- package/scripts/test/STABILITY_TEST_README.md +480 -0
- package/scripts/test/agent-worker.js +309 -0
- package/scripts/test/ai-coordination-test.js +650 -0
- package/scripts/test/ai-mesh-coordination-test.js +416 -0
- package/scripts/test/check-links.ts +274 -0
- package/scripts/test/check-performance-regression.ts +168 -0
- package/scripts/test/cli-agent-coordination-test.js +313 -0
- package/scripts/test/coordinator-multilingual-test.js +396 -0
- package/scripts/test/coordinator-transparency-demo.js +585 -0
- package/scripts/test/coverage-report.ts +692 -0
- package/scripts/test/generate-swarm-tests.js +633 -0
- package/scripts/test/integration-test-validation.cjs +253 -0
- package/scripts/test/load-test-swarm.js +576 -0
- package/scripts/test/mesh-coordination-zero-overlap-test.js +740 -0
- package/scripts/test/multilingual-hello-world-test.js +390 -0
- package/scripts/test/quick-multilingual-demo.js +464 -0
- package/scripts/test/real-agent-test.js +312 -0
- package/scripts/test/run-phase3-compliance-tests.js +427 -0
- package/scripts/test/run-stability-test-examples.sh +292 -0
- package/scripts/test/stability-results/stability-metrics.jsonl +83 -0
- package/scripts/test/stability-results/stability-test-report.json +128 -0
- package/scripts/test/stability-results/stability-test.log +1827 -0
- package/scripts/test/stability-test-50-agents.js +734 -0
- package/scripts/test/test-batch-tasks.ts +29 -0
- package/scripts/test/test-byzantine-resolution.js +246 -0
- package/scripts/test/test-claude-spawn-options.sh +63 -0
- package/scripts/test/test-cli-wizard.js +331 -0
- package/scripts/test/test-comprehensive.js +401 -0
- package/scripts/test/test-coordination-features.ts +238 -0
- package/scripts/test/test-fallback-systems.js +276 -0
- package/scripts/test/test-init-command.ts +302 -0
- package/scripts/test/test-mcp.ts +251 -0
- package/scripts/test/test-runner.ts +568 -0
- package/scripts/test/test-swarm-integration.sh +92 -0
- package/scripts/test/test-swarm.ts +142 -0
- package/scripts/test/validation-summary.ts +408 -0
- package/scripts/test-cleanup-performance.sh +416 -0
- package/scripts/test-dashboard-auth.cjs +203 -0
- package/scripts/test-docker-deployment.sh +207 -0
- package/scripts/test-npm-package.cjs +167 -0
- package/scripts/test-provider-routing.cjs +226 -0
- package/scripts/test-routing-telemetry.cjs +147 -0
- package/scripts/test-runner.cjs +154 -0
- package/scripts/test-zai-10k.cjs +81 -0
- package/scripts/test-zai-api.cjs +191 -0
- package/scripts/test-zai-diagnostic.cjs +151 -0
- package/scripts/test-zai-final.cjs +128 -0
- package/scripts/test-zai-with-env.cjs +85 -0
- package/scripts/utils/README.md +261 -0
- package/scripts/utils/clean-build-artifacts.sh +94 -0
- package/scripts/utils/cleanup-root.sh +69 -0
- package/scripts/utils/fix-cliffy-imports.js +307 -0
- package/scripts/utils/fix-duplicate-imports.js +114 -0
- package/scripts/utils/fix-error-handling.cjs +70 -0
- package/scripts/utils/fix-import-paths.js +104 -0
- package/scripts/utils/fix-imports.js +116 -0
- package/scripts/utils/fix-shebang.js +78 -0
- package/scripts/utils/fix-test-modules.js +27 -0
- package/scripts/utils/fix-timezone-issue-246.js +200 -0
- package/scripts/utils/fix-ts-comprehensive.py +182 -0
- package/scripts/utils/fix-ts-targeted-batch.js +250 -0
- package/scripts/utils/remove-benchmark-conflicts.sh +140 -0
- package/scripts/utils/simple-test-fixer.js +190 -0
- package/scripts/utils/validate-metrics-structure.cjs +144 -0
- package/scripts/validate-agent-hooks.js +506 -0
- package/scripts/validate-changelog.js +241 -0
- package/scripts/validate-coordination-cli.js +69 -0
- package/scripts/validate-coordination-toggle-integration.cjs +501 -0
- package/scripts/validate-docker-infrastructure.sh +502 -0
- package/scripts/validate-entry-points.js +300 -0
- package/scripts/validate-stage3-performance.ts +377 -0
- package/scripts/validate-template-bundling.js +180 -0
- package/scripts/validation/README.md +33 -0
- package/scripts/validation/acl-security-validation.cjs +214 -0
- package/scripts/validation/acl-security-validation.js +402 -0
- package/scripts/validation/byzantine-verification.js +407 -0
- package/scripts/validation/final-phase-2-consensus.cjs +219 -0
- package/scripts/validation/final-security-validation.js +791 -0
- package/scripts/validation/final-wasm-validation.cjs +840 -0
- package/scripts/validation/integration-test-analysis.js +105 -0
- package/scripts/validation/phase-0-comprehensive-validation.js +474 -0
- package/scripts/validation/phase-0-consensus-report.js +139 -0
- package/scripts/validation/phase-0-final-report.js +112 -0
- package/scripts/validation/phase-0-redis-consensus-report.js +129 -0
- package/scripts/validation/phase-0-validation-improved.js +490 -0
- package/scripts/validation/phase-0-validation-test.js +65 -0
- package/scripts/validation/phase-1-consensus-report.cjs +342 -0
- package/scripts/validation/phase-1-consensus-validation.cjs +551 -0
- package/scripts/validation/phase-1-consensus-validation.js +551 -0
- package/scripts/validation/phase-2-consensus-report.cjs +186 -0
- package/scripts/validation/phase-2-validation.cjs +171 -0
- package/scripts/validation/phase-2-validation.js +171 -0
- package/scripts/validation/phase-4-consensus-report.js +181 -0
- package/scripts/validation/phase-4-final-validation.js +351 -0
- package/scripts/validation/phase-5-consensus-report.cjs +113 -0
- package/scripts/validation/phase-5-consensus-report.js +113 -0
- package/scripts/validation/security-analysis.js +49 -0
- package/scripts/validation/security-validation.js +492 -0
- package/scripts/validation/simple-security-validation.js +464 -0
- package/scripts/verify-installation.js +112 -0
- package/scripts/verify-mcp-server.js +86 -0
- package/scripts/verify-sdk-phase1.cjs +293 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Resource monitoring script for 100-agent coordination test
|
|
3
|
+
# Tracks memory, CPU, file descriptors, processes, and disk I/O
|
|
4
|
+
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
# Configuration
|
|
8
|
+
SAMPLE_INTERVAL=1
|
|
9
|
+
OUTPUT_DIR="${1:-./monitoring-results}"
|
|
10
|
+
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
|
11
|
+
CSV_FILE="${OUTPUT_DIR}/resource-usage-${TIMESTAMP}.csv"
|
|
12
|
+
LOG_FILE="${OUTPUT_DIR}/monitor-${TIMESTAMP}.log"
|
|
13
|
+
PID_FILE="${OUTPUT_DIR}/monitor.pid"
|
|
14
|
+
|
|
15
|
+
# Create output directory
|
|
16
|
+
mkdir -p "${OUTPUT_DIR}"
|
|
17
|
+
|
|
18
|
+
# Store monitor PID for cleanup
|
|
19
|
+
echo $$ > "${PID_FILE}"
|
|
20
|
+
|
|
21
|
+
# Cleanup function
|
|
22
|
+
cleanup() {
|
|
23
|
+
echo "[$(date +%H:%M:%S)] Monitoring stopped. Results: ${CSV_FILE}" | tee -a "${LOG_FILE}"
|
|
24
|
+
rm -f "${PID_FILE}"
|
|
25
|
+
exit 0
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
trap cleanup SIGINT SIGTERM
|
|
29
|
+
|
|
30
|
+
# Initialize CSV with headers
|
|
31
|
+
echo "timestamp,elapsed_sec,memory_rss_mb,memory_vsz_mb,memory_shm_mb,cpu_percent,fd_count,process_count,node_processes,io_read_mb,io_write_mb" > "${CSV_FILE}"
|
|
32
|
+
|
|
33
|
+
echo "[$(date +%H:%M:%S)] Resource monitoring started" | tee -a "${LOG_FILE}"
|
|
34
|
+
echo "[$(date +%H:%M:%S)] Output: ${CSV_FILE}" | tee -a "${LOG_FILE}"
|
|
35
|
+
echo "[$(date +%H:%M:%S)] Sampling every ${SAMPLE_INTERVAL}s" | tee -a "${LOG_FILE}"
|
|
36
|
+
|
|
37
|
+
# Baseline metrics
|
|
38
|
+
START_TIME=$(date +%s)
|
|
39
|
+
BASELINE_IO_READ=0
|
|
40
|
+
BASELINE_IO_WRITE=0
|
|
41
|
+
|
|
42
|
+
# Get baseline I/O if available
|
|
43
|
+
if [ -f /proc/diskstats ]; then
|
|
44
|
+
BASELINE_IO_READ=$(awk '/sda/ {sum+=$6} END {print sum}' /proc/diskstats 2>/dev/null || echo 0)
|
|
45
|
+
BASELINE_IO_WRITE=$(awk '/sda/ {sum+=$10} END {print sum}' /proc/diskstats 2>/dev/null || echo 0)
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# Monitoring loop
|
|
49
|
+
while true; do
|
|
50
|
+
CURRENT_TIME=$(date +%s)
|
|
51
|
+
ELAPSED=$((CURRENT_TIME - START_TIME))
|
|
52
|
+
TIMESTAMP=$(date +%Y-%m-%d_%H:%M:%S)
|
|
53
|
+
|
|
54
|
+
# Memory metrics (RSS and VSZ for all node processes)
|
|
55
|
+
MEMORY_RSS=0
|
|
56
|
+
MEMORY_VSZ=0
|
|
57
|
+
if pgrep -f "node|npm" > /dev/null 2>&1; then
|
|
58
|
+
MEMORY_RSS=$(ps aux | grep -E "node|npm" | grep -v grep | awk '{sum+=$6} END {print sum/1024}' || echo 0)
|
|
59
|
+
MEMORY_VSZ=$(ps aux | grep -E "node|npm" | grep -v grep | awk '{sum+=$5} END {print sum/1024}' || echo 0)
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
# Shared memory (tmpfs /dev/shm)
|
|
63
|
+
MEMORY_SHM=0
|
|
64
|
+
if [ -d /dev/shm ]; then
|
|
65
|
+
MEMORY_SHM=$(du -sm /dev/shm 2>/dev/null | cut -f1 || echo 0)
|
|
66
|
+
fi
|
|
67
|
+
|
|
68
|
+
# CPU usage (average across all node processes)
|
|
69
|
+
CPU_PERCENT=0
|
|
70
|
+
if pgrep -f "node|npm" > /dev/null 2>&1; then
|
|
71
|
+
CPU_PERCENT=$(ps aux | grep -E "node|npm" | grep -v grep | awk '{sum+=$3} END {print sum}' || echo 0)
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
# File descriptor count (sample from first node process for speed)
|
|
75
|
+
FD_COUNT=0
|
|
76
|
+
FIRST_NODE_PID=$(pgrep -f "node|npm" 2>/dev/null | head -1 | tr -d '\n' || echo "")
|
|
77
|
+
if [ -n "${FIRST_NODE_PID}" ] && [ -d "/proc/${FIRST_NODE_PID}/fd" ]; then
|
|
78
|
+
FD_COUNT=$(ls "/proc/${FIRST_NODE_PID}/fd" 2>/dev/null | wc -l | tr -d '\n' || echo 0)
|
|
79
|
+
fi
|
|
80
|
+
|
|
81
|
+
# Process count (all node/npm processes) - ensure single line
|
|
82
|
+
PROCESS_COUNT=$(pgrep -f "node|npm" 2>/dev/null | wc -l | tr -d '\n' || echo 0)
|
|
83
|
+
NODE_PROCESSES=$(pgrep -f "node" 2>/dev/null | wc -l | tr -d '\n' || echo 0)
|
|
84
|
+
|
|
85
|
+
# Disk I/O (if available via /proc/diskstats)
|
|
86
|
+
IO_READ_MB=0
|
|
87
|
+
IO_WRITE_MB=0
|
|
88
|
+
if [ -f /proc/diskstats ]; then
|
|
89
|
+
CURRENT_IO_READ=$(awk '/sda/ {sum+=$6} END {print sum}' /proc/diskstats 2>/dev/null || echo 0)
|
|
90
|
+
CURRENT_IO_WRITE=$(awk '/sda/ {sum+=$10} END {print sum}' /proc/diskstats 2>/dev/null || echo 0)
|
|
91
|
+
IO_READ_MB=$(echo "scale=2; ($CURRENT_IO_READ - $BASELINE_IO_READ) * 512 / 1024 / 1024" | bc 2>/dev/null || echo 0)
|
|
92
|
+
IO_WRITE_MB=$(echo "scale=2; ($CURRENT_IO_WRITE - $BASELINE_IO_WRITE) * 512 / 1024 / 1024" | bc 2>/dev/null || echo 0)
|
|
93
|
+
fi
|
|
94
|
+
|
|
95
|
+
# Round floating point values
|
|
96
|
+
MEMORY_RSS=$(printf "%.2f" "${MEMORY_RSS}")
|
|
97
|
+
MEMORY_VSZ=$(printf "%.2f" "${MEMORY_VSZ}")
|
|
98
|
+
CPU_PERCENT=$(printf "%.2f" "${CPU_PERCENT}")
|
|
99
|
+
|
|
100
|
+
# Write CSV row
|
|
101
|
+
echo "${TIMESTAMP},${ELAPSED},${MEMORY_RSS},${MEMORY_VSZ},${MEMORY_SHM},${CPU_PERCENT},${FD_COUNT},${PROCESS_COUNT},${NODE_PROCESSES},${IO_READ_MB},${IO_WRITE_MB}" >> "${CSV_FILE}"
|
|
102
|
+
|
|
103
|
+
# Log significant events
|
|
104
|
+
if (( $(echo "${MEMORY_RSS} > 5000" | bc -l 2>/dev/null || echo 0) )); then
|
|
105
|
+
echo "[$(date +%H:%M:%S)] WARNING: High memory usage: ${MEMORY_RSS}MB RSS" | tee -a "${LOG_FILE}"
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
if (( $(echo "${CPU_PERCENT} > 80" | bc -l 2>/dev/null || echo 0) )); then
|
|
109
|
+
echo "[$(date +%H:%M:%S)] WARNING: High CPU usage: ${CPU_PERCENT}%" | tee -a "${LOG_FILE}"
|
|
110
|
+
fi
|
|
111
|
+
|
|
112
|
+
if [ "${FD_COUNT}" -gt 10000 ]; then
|
|
113
|
+
echo "[$(date +%H:%M:%S)] WARNING: High FD count: ${FD_COUNT}" | tee -a "${LOG_FILE}"
|
|
114
|
+
fi
|
|
115
|
+
|
|
116
|
+
if [ "${PROCESS_COUNT}" -gt 500 ]; then
|
|
117
|
+
echo "[$(date +%H:%M:%S)] WARNING: High process count: ${PROCESS_COUNT}" | tee -a "${LOG_FILE}"
|
|
118
|
+
fi
|
|
119
|
+
|
|
120
|
+
# Progress indicator every 10 seconds
|
|
121
|
+
if [ $((ELAPSED % 10)) -eq 0 ] && [ "${ELAPSED}" -gt 0 ]; then
|
|
122
|
+
echo "[$(date +%H:%M:%S)] ${ELAPSED}s | MEM: ${MEMORY_RSS}MB | CPU: ${CPU_PERCENT}% | FD: ${FD_COUNT} | PROC: ${PROCESS_COUNT}" | tee -a "${LOG_FILE}"
|
|
123
|
+
fi
|
|
124
|
+
|
|
125
|
+
sleep "${SAMPLE_INTERVAL}"
|
|
126
|
+
done
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 50-Agent Stability Test Memory Monitor
|
|
4
|
+
* WSL2-optimized, 8-hour duration, <1% overhead
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from 'fs/promises';
|
|
8
|
+
import { createWriteStream } from 'fs';
|
|
9
|
+
import v8 from 'v8';
|
|
10
|
+
import { spawn, execSync } from 'child_process';
|
|
11
|
+
import os from 'os';
|
|
12
|
+
|
|
13
|
+
class StabilityMonitor {
|
|
14
|
+
constructor(config = {}) {
|
|
15
|
+
this.config = {
|
|
16
|
+
outputPath: config.outputPath || './stability-results',
|
|
17
|
+
samplingInterval: config.samplingInterval || 1000, // 1s
|
|
18
|
+
baselineDelay: config.baselineDelay || 120000, // 2 min
|
|
19
|
+
leakThreshold: config.leakThreshold || 0.10, // 10%
|
|
20
|
+
fdThreshold: config.fdThreshold || 10000,
|
|
21
|
+
maxSamples: config.maxSamples || 28800, // 8 hours at 1s
|
|
22
|
+
...config
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
this.baseline = null;
|
|
26
|
+
this.measurements = [];
|
|
27
|
+
this.alerts = [];
|
|
28
|
+
this.jsonlStream = null;
|
|
29
|
+
this.startTime = Date.now();
|
|
30
|
+
this.running = false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async start() {
|
|
34
|
+
console.log('š Starting 8-hour stability test monitor...');
|
|
35
|
+
console.log(` Sampling interval: ${this.config.samplingInterval}ms`);
|
|
36
|
+
console.log(` Leak threshold: ${(this.config.leakThreshold * 100).toFixed(1)}%`);
|
|
37
|
+
console.log(` Output: ${this.config.outputPath}`);
|
|
38
|
+
|
|
39
|
+
// Ensure output directory exists
|
|
40
|
+
await fs.mkdir(this.config.outputPath, { recursive: true });
|
|
41
|
+
|
|
42
|
+
// Initialize JSONL stream
|
|
43
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
44
|
+
const filename = `metrics-${timestamp}.jsonl`;
|
|
45
|
+
this.jsonlStream = createWriteStream(`${this.config.outputPath}/${filename}`);
|
|
46
|
+
console.log(` Log file: ${filename}`);
|
|
47
|
+
|
|
48
|
+
// Establish baseline after delay
|
|
49
|
+
setTimeout(() => this.establishBaseline(), this.config.baselineDelay);
|
|
50
|
+
|
|
51
|
+
// Start collection loop
|
|
52
|
+
this.running = true;
|
|
53
|
+
this.collectionInterval = setInterval(() => this.collect(), this.config.samplingInterval);
|
|
54
|
+
|
|
55
|
+
// Summary reports every 10 minutes
|
|
56
|
+
this.reportInterval = setInterval(() => this.printSummary(), 600000);
|
|
57
|
+
|
|
58
|
+
// Graceful shutdown handlers
|
|
59
|
+
process.on('SIGINT', () => this.shutdown('SIGINT'));
|
|
60
|
+
process.on('SIGTERM', () => this.shutdown('SIGTERM'));
|
|
61
|
+
|
|
62
|
+
console.log('ā
Monitor started. Establishing baseline in 2 minutes...\n');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async collect() {
|
|
66
|
+
if (!this.running) return;
|
|
67
|
+
|
|
68
|
+
const timestamp = Date.now();
|
|
69
|
+
const mem = process.memoryUsage();
|
|
70
|
+
const heap = v8.getHeapStatistics();
|
|
71
|
+
const resources = process.resourceUsage();
|
|
72
|
+
|
|
73
|
+
// Collect metrics
|
|
74
|
+
const metrics = {
|
|
75
|
+
timestamp,
|
|
76
|
+
elapsed: timestamp - this.startTime,
|
|
77
|
+
memory: {
|
|
78
|
+
rss: mem.rss,
|
|
79
|
+
heapUsed: mem.heapUsed,
|
|
80
|
+
heapTotal: mem.heapTotal,
|
|
81
|
+
external: mem.external,
|
|
82
|
+
arrayBuffers: mem.arrayBuffers
|
|
83
|
+
},
|
|
84
|
+
heap: {
|
|
85
|
+
totalSize: heap.total_heap_size,
|
|
86
|
+
usedSize: heap.used_heap_size,
|
|
87
|
+
limit: heap.heap_size_limit,
|
|
88
|
+
mallocedMemory: heap.malloced_memory,
|
|
89
|
+
peakMalloced: heap.peak_malloced_memory
|
|
90
|
+
},
|
|
91
|
+
resources: {
|
|
92
|
+
userCPU: resources.userCPUTime,
|
|
93
|
+
systemCPU: resources.systemCPUTime,
|
|
94
|
+
maxRSS: resources.maxRSS
|
|
95
|
+
},
|
|
96
|
+
fds: await this.getFileDescriptorCount(),
|
|
97
|
+
proc: await this.getProcMemory(),
|
|
98
|
+
system: await this.getSystemMetrics()
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// Store and analyze
|
|
102
|
+
this.measurements.push(metrics);
|
|
103
|
+
|
|
104
|
+
// Keep memory bounded
|
|
105
|
+
if (this.measurements.length > this.config.maxSamples) {
|
|
106
|
+
this.measurements.shift();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Write to JSONL
|
|
110
|
+
this.jsonlStream.write(JSON.stringify(metrics) + '\n');
|
|
111
|
+
|
|
112
|
+
// Leak detection every 5 minutes
|
|
113
|
+
if (this.baseline && this.measurements.length % 300 === 0) {
|
|
114
|
+
const leak = this.detectLeak();
|
|
115
|
+
if (leak.detected) {
|
|
116
|
+
this.alerts.push({ timestamp, type: 'memory_leak', data: leak });
|
|
117
|
+
console.warn(`\nā ļø [${new Date(timestamp).toISOString()}] MEMORY LEAK DETECTED`);
|
|
118
|
+
console.warn(` Growth: ${leak.growthPercent}% (${leak.growthMB} MB)`);
|
|
119
|
+
console.warn(` Severity: ${leak.severity}`);
|
|
120
|
+
console.warn(` Projected 8h: ${leak.projectedGrowth8h.toFixed(2)} MB\n`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// FD leak detection
|
|
125
|
+
if (metrics.fds > this.config.fdThreshold) {
|
|
126
|
+
const fdLeak = {
|
|
127
|
+
timestamp,
|
|
128
|
+
count: metrics.fds,
|
|
129
|
+
growth: this.baseline ? metrics.fds - this.baseline.fds : 0
|
|
130
|
+
};
|
|
131
|
+
this.alerts.push({ timestamp, type: 'fd_leak', data: fdLeak });
|
|
132
|
+
console.warn(`\nā ļø [${new Date(timestamp).toISOString()}] FD LEAK DETECTED`);
|
|
133
|
+
console.warn(` Open FDs: ${metrics.fds} (threshold: ${this.config.fdThreshold})\n`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async getFileDescriptorCount() {
|
|
138
|
+
try {
|
|
139
|
+
const fdPath = `/proc/${process.pid}/fd`;
|
|
140
|
+
const files = await fs.readdir(fdPath);
|
|
141
|
+
return files.length;
|
|
142
|
+
} catch {
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async getProcMemory() {
|
|
148
|
+
try {
|
|
149
|
+
const statusPath = `/proc/${process.pid}/status`;
|
|
150
|
+
const status = await fs.readFile(statusPath, 'utf8');
|
|
151
|
+
|
|
152
|
+
const extract = (key) => {
|
|
153
|
+
const match = status.match(new RegExp(`${key}:\\s+(\\d+)`));
|
|
154
|
+
return match ? parseInt(match[1]) * 1024 : 0; // Convert kB to bytes
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
vmRSS: extract('VmRSS'),
|
|
159
|
+
vmSize: extract('VmSize'),
|
|
160
|
+
rssAnon: extract('RssAnon'),
|
|
161
|
+
rssFile: extract('RssFile')
|
|
162
|
+
};
|
|
163
|
+
} catch {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async getSystemMetrics() {
|
|
169
|
+
try {
|
|
170
|
+
// Memory usage from /proc/meminfo
|
|
171
|
+
const meminfo = await fs.readFile('/proc/meminfo', 'utf8');
|
|
172
|
+
const memTotal = parseInt(meminfo.match(/MemTotal:\s+(\d+)/)[1]) * 1024;
|
|
173
|
+
const memAvailable = parseInt(meminfo.match(/MemAvailable:\s+(\d+)/)[1]) * 1024;
|
|
174
|
+
const memUsed = memTotal - memAvailable;
|
|
175
|
+
|
|
176
|
+
// tmpfs usage
|
|
177
|
+
const tmpfsOutput = execSync('df -B1 /dev/shm', { encoding: 'utf8' });
|
|
178
|
+
const tmpfsLines = tmpfsOutput.trim().split('\n');
|
|
179
|
+
const tmpfsParts = tmpfsLines[1].split(/\s+/);
|
|
180
|
+
const tmpfsTotal = parseInt(tmpfsParts[1]);
|
|
181
|
+
const tmpfsUsed = parseInt(tmpfsParts[2]);
|
|
182
|
+
|
|
183
|
+
// Load average
|
|
184
|
+
const loadavg = os.loadavg();
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
memory: {
|
|
188
|
+
total: memTotal,
|
|
189
|
+
used: memUsed,
|
|
190
|
+
available: memAvailable,
|
|
191
|
+
utilizationPct: (memUsed / memTotal * 100).toFixed(1)
|
|
192
|
+
},
|
|
193
|
+
tmpfs: {
|
|
194
|
+
total: tmpfsTotal,
|
|
195
|
+
used: tmpfsUsed,
|
|
196
|
+
available: tmpfsTotal - tmpfsUsed,
|
|
197
|
+
utilizationPct: (tmpfsUsed / tmpfsTotal * 100).toFixed(1)
|
|
198
|
+
},
|
|
199
|
+
loadavg: {
|
|
200
|
+
'1min': loadavg[0],
|
|
201
|
+
'5min': loadavg[1],
|
|
202
|
+
'15min': loadavg[2]
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
} catch (error) {
|
|
206
|
+
console.error('Failed to get system metrics:', error.message);
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
establishBaseline() {
|
|
212
|
+
if (this.measurements.length === 0) return;
|
|
213
|
+
|
|
214
|
+
this.baseline = this.measurements[this.measurements.length - 1];
|
|
215
|
+
console.log('š Baseline established:');
|
|
216
|
+
console.log(` RSS: ${(this.baseline.memory.rss / 1024 / 1024).toFixed(2)} MB`);
|
|
217
|
+
console.log(` Heap: ${(this.baseline.memory.heapUsed / 1024 / 1024).toFixed(2)} MB`);
|
|
218
|
+
console.log(` FDs: ${this.baseline.fds}`);
|
|
219
|
+
if (this.baseline.system) {
|
|
220
|
+
console.log(` System memory: ${this.baseline.system.memory.utilizationPct}%`);
|
|
221
|
+
console.log(` tmpfs: ${this.baseline.system.tmpfs.utilizationPct}%`);
|
|
222
|
+
}
|
|
223
|
+
console.log('');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
detectLeak() {
|
|
227
|
+
if (!this.baseline || this.measurements.length < 300) {
|
|
228
|
+
return { detected: false };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const current = this.measurements[this.measurements.length - 1];
|
|
232
|
+
const growth = (current.memory.rss - this.baseline.memory.rss) / this.baseline.memory.rss;
|
|
233
|
+
|
|
234
|
+
// Calculate trend (linear regression on last 5 minutes)
|
|
235
|
+
const recentWindow = this.measurements.slice(-300);
|
|
236
|
+
const slope = this.calculateSlope(recentWindow.map(m => m.memory.rss));
|
|
237
|
+
|
|
238
|
+
const projectedGrowth8h = (slope * 28800) / 1024 / 1024;
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
detected: growth > this.config.leakThreshold || slope > 0.001,
|
|
242
|
+
growthPercent: (growth * 100).toFixed(2),
|
|
243
|
+
growthMB: ((current.memory.rss - this.baseline.memory.rss) / 1024 / 1024).toFixed(2),
|
|
244
|
+
slopePerSecond: slope,
|
|
245
|
+
projectedGrowth8h,
|
|
246
|
+
severity: this.assessSeverity(growth, slope)
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
calculateSlope(values) {
|
|
251
|
+
const n = values.length;
|
|
252
|
+
if (n < 2) return 0;
|
|
253
|
+
|
|
254
|
+
const sumX = (n * (n - 1)) / 2;
|
|
255
|
+
const sumY = values.reduce((a, b) => a + b, 0);
|
|
256
|
+
const sumXY = values.reduce((sum, y, x) => sum + x * y, 0);
|
|
257
|
+
const sumX2 = (n * (n - 1) * (2 * n - 1)) / 6;
|
|
258
|
+
|
|
259
|
+
return (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
assessSeverity(growth, slope) {
|
|
263
|
+
if (growth > 0.15 || slope > 0.002) return 'CRITICAL';
|
|
264
|
+
if (growth > 0.10 || slope > 0.001) return 'HIGH';
|
|
265
|
+
if (growth > 0.05 || slope > 0.0005) return 'MEDIUM';
|
|
266
|
+
return 'LOW';
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
printSummary() {
|
|
270
|
+
if (this.measurements.length === 0) return;
|
|
271
|
+
|
|
272
|
+
const current = this.measurements[this.measurements.length - 1];
|
|
273
|
+
const elapsed = (current.timestamp - this.startTime) / 1000 / 3600; // hours
|
|
274
|
+
|
|
275
|
+
console.log(`\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
276
|
+
console.log(`š STABILITY TEST SUMMARY (${elapsed.toFixed(2)}h elapsed)`);
|
|
277
|
+
console.log(`āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
278
|
+
console.log(`Memory RSS: ${(current.memory.rss / 1024 / 1024).toFixed(2)} MB`);
|
|
279
|
+
console.log(`Heap Used: ${(current.memory.heapUsed / 1024 / 1024).toFixed(2)} MB`);
|
|
280
|
+
console.log(`Open FDs: ${current.fds}`);
|
|
281
|
+
console.log(`Samples: ${this.measurements.length}`);
|
|
282
|
+
console.log(`Alerts: ${this.alerts.length}`);
|
|
283
|
+
|
|
284
|
+
if (this.baseline) {
|
|
285
|
+
const growth = ((current.memory.rss - this.baseline.memory.rss) / this.baseline.memory.rss * 100).toFixed(2);
|
|
286
|
+
console.log(`Growth: ${growth}% (threshold: ${(this.config.leakThreshold * 100).toFixed(1)}%)`);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (current.system) {
|
|
290
|
+
console.log(`System RAM: ${current.system.memory.utilizationPct}%`);
|
|
291
|
+
console.log(`tmpfs: ${current.system.tmpfs.utilizationPct}%`);
|
|
292
|
+
console.log(`Load (1m): ${current.system.loadavg['1min'].toFixed(2)}`);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
console.log(`āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async shutdown(signal) {
|
|
299
|
+
console.log(`\n\nš Received ${signal}, shutting down gracefully...`);
|
|
300
|
+
this.running = false;
|
|
301
|
+
|
|
302
|
+
clearInterval(this.collectionInterval);
|
|
303
|
+
clearInterval(this.reportInterval);
|
|
304
|
+
|
|
305
|
+
if (this.jsonlStream) {
|
|
306
|
+
this.jsonlStream.end();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Generate final report
|
|
310
|
+
await this.generateReport();
|
|
311
|
+
|
|
312
|
+
console.log('ā
Monitor stopped. Report generated.');
|
|
313
|
+
process.exit(0);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
async generateReport() {
|
|
317
|
+
if (this.measurements.length === 0) return;
|
|
318
|
+
|
|
319
|
+
const first = this.measurements[0];
|
|
320
|
+
const last = this.measurements[this.measurements.length - 1];
|
|
321
|
+
const maxRss = this.measurements.reduce((max, m) => Math.max(max, m.memory.rss), 0);
|
|
322
|
+
const avgRss = this.measurements.reduce((sum, m) => sum + m.memory.rss, 0) / this.measurements.length;
|
|
323
|
+
const maxFds = this.measurements.reduce((max, m) => Math.max(max, m.fds), 0);
|
|
324
|
+
|
|
325
|
+
const report = {
|
|
326
|
+
test: {
|
|
327
|
+
duration: (last.timestamp - first.timestamp) / 1000,
|
|
328
|
+
samples: this.measurements.length,
|
|
329
|
+
startTime: new Date(first.timestamp).toISOString(),
|
|
330
|
+
endTime: new Date(last.timestamp).toISOString(),
|
|
331
|
+
samplingInterval: this.config.samplingInterval
|
|
332
|
+
},
|
|
333
|
+
memory: {
|
|
334
|
+
initial: first.memory.rss,
|
|
335
|
+
final: last.memory.rss,
|
|
336
|
+
max: maxRss,
|
|
337
|
+
avg: avgRss,
|
|
338
|
+
growth: ((last.memory.rss - first.memory.rss) / first.memory.rss * 100).toFixed(2) + '%',
|
|
339
|
+
growthMB: ((last.memory.rss - first.memory.rss) / 1024 / 1024).toFixed(2)
|
|
340
|
+
},
|
|
341
|
+
heap: {
|
|
342
|
+
initial: first.memory.heapUsed,
|
|
343
|
+
final: last.memory.heapUsed,
|
|
344
|
+
growth: ((last.memory.heapUsed - first.memory.heapUsed) / first.memory.heapUsed * 100).toFixed(2) + '%'
|
|
345
|
+
},
|
|
346
|
+
fds: {
|
|
347
|
+
initial: first.fds,
|
|
348
|
+
final: last.fds,
|
|
349
|
+
max: maxFds,
|
|
350
|
+
growth: last.fds - first.fds
|
|
351
|
+
},
|
|
352
|
+
system: last.system,
|
|
353
|
+
alerts: this.alerts,
|
|
354
|
+
result: this.determineResult()
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
358
|
+
const reportFile = `${this.config.outputPath}/report-${timestamp}.json`;
|
|
359
|
+
await fs.writeFile(reportFile, JSON.stringify(report, null, 2));
|
|
360
|
+
|
|
361
|
+
console.log('\n' + JSON.stringify(report, null, 2));
|
|
362
|
+
console.log(`\nš Report saved to: ${reportFile}`);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
determineResult() {
|
|
366
|
+
if (!this.baseline || this.measurements.length < 10) {
|
|
367
|
+
return { status: 'INSUFFICIENT_DATA', message: 'Test ran for less than 10 seconds' };
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const last = this.measurements[this.measurements.length - 1];
|
|
371
|
+
const growth = (last.memory.rss - this.baseline.memory.rss) / this.baseline.memory.rss;
|
|
372
|
+
const fdGrowth = last.fds - this.baseline.fds;
|
|
373
|
+
|
|
374
|
+
const memoryLeak = growth >= this.config.leakThreshold;
|
|
375
|
+
const fdLeak = last.fds >= this.config.fdThreshold;
|
|
376
|
+
const hasAlerts = this.alerts.length > 0;
|
|
377
|
+
|
|
378
|
+
const passed = !memoryLeak && !fdLeak && !hasAlerts;
|
|
379
|
+
|
|
380
|
+
return {
|
|
381
|
+
status: passed ? 'PASS' : 'FAIL',
|
|
382
|
+
memoryLeakDetected: memoryLeak,
|
|
383
|
+
fdLeakDetected: fdLeak,
|
|
384
|
+
alertCount: this.alerts.length,
|
|
385
|
+
memoryGrowthPercent: (growth * 100).toFixed(2),
|
|
386
|
+
fdGrowth: fdGrowth,
|
|
387
|
+
message: passed ? 'All stability criteria met' : 'Stability issues detected'
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// CLI interface
|
|
393
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
394
|
+
const args = process.argv.slice(2);
|
|
395
|
+
const config = {};
|
|
396
|
+
|
|
397
|
+
// Parse command line arguments
|
|
398
|
+
for (let i = 0; i < args.length; i++) {
|
|
399
|
+
if (args[i] === '--output' && args[i + 1]) {
|
|
400
|
+
config.outputPath = args[++i];
|
|
401
|
+
} else if (args[i] === '--interval' && args[i + 1]) {
|
|
402
|
+
config.samplingInterval = parseInt(args[++i]);
|
|
403
|
+
} else if (args[i] === '--threshold' && args[i + 1]) {
|
|
404
|
+
config.leakThreshold = parseFloat(args[++i]);
|
|
405
|
+
} else if (args[i] === '--fd-threshold' && args[i + 1]) {
|
|
406
|
+
config.fdThreshold = parseInt(args[++i]);
|
|
407
|
+
} else if (args[i] === '--help') {
|
|
408
|
+
console.log(`
|
|
409
|
+
Usage: node stability-monitor.js [options]
|
|
410
|
+
|
|
411
|
+
Options:
|
|
412
|
+
--output <path> Output directory for results (default: ./stability-results)
|
|
413
|
+
--interval <ms> Sampling interval in milliseconds (default: 1000)
|
|
414
|
+
--threshold <percent> Memory leak threshold (default: 0.10 = 10%)
|
|
415
|
+
--fd-threshold <count> File descriptor leak threshold (default: 10000)
|
|
416
|
+
--help Show this help
|
|
417
|
+
|
|
418
|
+
Example:
|
|
419
|
+
node stability-monitor.js --output ./test-results --interval 5000 --threshold 0.05
|
|
420
|
+
`);
|
|
421
|
+
process.exit(0);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const monitor = new StabilityMonitor(config);
|
|
426
|
+
monitor.start();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export default StabilityMonitor;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Quick test to verify monitoring scripts work correctly
|
|
3
|
+
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
|
|
6
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
7
|
+
TEST_DIR="${SCRIPT_DIR}/../../reports/monitoring/test-quick"
|
|
8
|
+
|
|
9
|
+
echo "Quick Monitoring Test"
|
|
10
|
+
echo "====================="
|
|
11
|
+
echo ""
|
|
12
|
+
|
|
13
|
+
# Cleanup old test data
|
|
14
|
+
rm -rf "${TEST_DIR}"
|
|
15
|
+
mkdir -p "${TEST_DIR}"
|
|
16
|
+
|
|
17
|
+
# Start monitor
|
|
18
|
+
echo "Starting monitor for 10 seconds..."
|
|
19
|
+
"${SCRIPT_DIR}/resource-monitor.sh" "${TEST_DIR}" &
|
|
20
|
+
MONITOR_PID=$!
|
|
21
|
+
|
|
22
|
+
# Wait for monitor to initialize
|
|
23
|
+
sleep 2
|
|
24
|
+
|
|
25
|
+
# Let it collect some samples
|
|
26
|
+
sleep 8
|
|
27
|
+
|
|
28
|
+
# Stop monitor
|
|
29
|
+
echo "Stopping monitor..."
|
|
30
|
+
kill -TERM "${MONITOR_PID}" 2>/dev/null || true
|
|
31
|
+
wait "${MONITOR_PID}" 2>/dev/null || true
|
|
32
|
+
|
|
33
|
+
# Find CSV file
|
|
34
|
+
CSV_FILE=$(find "${TEST_DIR}" -name "resource-usage-*.csv" -type f | head -1)
|
|
35
|
+
|
|
36
|
+
if [ ! -f "${CSV_FILE}" ]; then
|
|
37
|
+
echo "ERROR: CSV file not created"
|
|
38
|
+
exit 1
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
echo ""
|
|
42
|
+
echo "CSV created: ${CSV_FILE}"
|
|
43
|
+
echo "Sample count: $(tail -n +2 "${CSV_FILE}" | wc -l)"
|
|
44
|
+
echo ""
|
|
45
|
+
|
|
46
|
+
# Analyze
|
|
47
|
+
echo "Running analysis..."
|
|
48
|
+
"${SCRIPT_DIR}/analyze-resources.sh" "${CSV_FILE}"
|
|
49
|
+
|
|
50
|
+
echo ""
|
|
51
|
+
echo "ā
Monitoring test complete"
|
|
52
|
+
echo ""
|
|
53
|
+
echo "Files created:"
|
|
54
|
+
ls -lh "${TEST_DIR}"
|