40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\AgentConsumerDelayMonitorService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class AgentConsumerDelayMonitorCommand extends Command
|
|
{
|
|
protected $signature = 'agent-consumer:monitor-delay';
|
|
|
|
protected $description = '检查 Agent 消息消费延迟并发送钉钉告警或恢复通知';
|
|
|
|
public function handle(AgentConsumerDelayMonitorService $service): int
|
|
{
|
|
try {
|
|
$result = $service->check();
|
|
|
|
Log::channel('agent-consumer-monitor')->info('Agent 消费延迟检查完成', $result);
|
|
$this->info(sprintf(
|
|
'检查完成:eventname=%s,延迟=%s 分钟,%d 个新告警,%d 个恢复。',
|
|
$result['event_name'] ?? '-',
|
|
$result['delay_minutes'] ?? '-',
|
|
$result['alerted_count'],
|
|
$result['recovered_count']
|
|
));
|
|
|
|
return self::SUCCESS;
|
|
} catch (\Throwable $e) {
|
|
Log::channel('agent-consumer-monitor')->error('Agent 消费延迟检查失败', [
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
$this->error($e->getMessage());
|
|
|
|
return self::FAILURE;
|
|
}
|
|
}
|
|
}
|