44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
|
|
/**
|
|||
|
|
* 健康檢查夜間監控
|
|||
|
|
*
|
|||
|
|
* 此測試用於 Production 環境,持續監控系統健康狀態。
|
|||
|
|
* 測試重點:系統可用性監控,識別性能退化。
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
import { healthCheck } from '../../scenarios/apis/health.js';
|
|||
|
|
|
|||
|
|
export const options = {
|
|||
|
|
scenarios: {
|
|||
|
|
nightly_health: {
|
|||
|
|
executor: 'constant-arrival-rate',
|
|||
|
|
rate: 1, // 每秒 1 個請求
|
|||
|
|
timeUnit: '1s',
|
|||
|
|
duration: '10m', // 執行 10 分鐘
|
|||
|
|
preAllocatedVUs: 2,
|
|||
|
|
maxVUs: 5,
|
|||
|
|
tags: { test_type: 'nightly', api: 'health', environment: 'prod' },
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
thresholds: {
|
|||
|
|
checks: ['rate==1.0'], // 所有檢查必須通過
|
|||
|
|
http_req_duration: ['p(95)<500'], // 95% 的請求應在 500ms 內完成
|
|||
|
|
health_check_success: ['rate==1.0'], // 健康檢查成功率應為 100%
|
|||
|
|
http_req_failed: ['rate==0'], // 不允許失敗
|
|||
|
|
},
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
export default function () {
|
|||
|
|
const baseUrl = __ENV.BASE_URL || 'http://localhost:8888';
|
|||
|
|
|
|||
|
|
const result = healthCheck({ baseUrl });
|
|||
|
|
|
|||
|
|
if (!result.success) {
|
|||
|
|
console.error(`Health check failed: Status ${result.status}, Response time ${result.responseTime}ms`);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 記錄健康檢查結果(在實際環境中,這可以發送到監控系統)
|
|||
|
|
console.log(`Health check passed: Status ${result.status}, Response time ${result.responseTime}ms`);
|
|||
|
|
}
|
|||
|
|
|