zenstruck / messenger-monitor-bundle

Batteries included UI to monitor your Messenger workers, transports, schedules, and messages.
MIT License
153 stars 16 forks source link

feat: add check for LiipMonitoring-Bundle (WIP) #61

Open Chris53897 opened 9 months ago

Chris53897 commented 9 months ago

i try to add checks for LiipMonitoring-Bundle https://github.com/zenstruck/messenger-monitor-bundle/issues/11

But i am a bit stucked here.

I followed the example from here https://github.com/kbond/LiipMonitorBundle/tree/feat/ohdear#custom-checks and took this Check as example https://github.com/kbond/LiipMonitorBundle/blob/feat/ohdear/src/Check/Symfony/SymfonyVersionCheck.php

I thought i could activated it like this.

liip_monitor:
    checks:
        symfony_worker_running: true

And see it with php bin/console monitor:list

But i will get an error, that symfony_worker_running is not registered unter checks.

@kbond Maybe you can give me a little push to the right direction?

kbond commented 8 months ago

Ah yes, this is a bit tricky and we'll have to make a decision on "where the config should live".

Option 1 - Config lives in liip_monitor: For this, we'd need a way to bundles (like this one), to announce to LiipMonitorBundle that it has a configurable check. I do something similar in ZenstruckBackupBundle but it isn't extensible (the extra config options are hard-coded). What we need is sort of a pre-compile container that has the liip_monitor check config factories tagged. I'm not sure this is possible - we might have to use composer.json config - in LiipMonitorBundle's extension, look for all installed packages that have a specific key in their composer.json. This will probably get complex...

Option 2 - Config lives in this bundle: For this, we'd add a liip_monitor key to this bundle's config that's only available when LiipMonitorBundle is enabled. You can then have WorkerRunningCheck implement Liip\Monitor\DependencyInjection\ConfigurableCheck but we'd have to add the config manually to this bundle.

Option 1 seems ideal but 2 seems easiest.

Chris53897 commented 8 months ago

Thanks for the info. I will have a deeper look, as soon i have some free time.

Chris53897 commented 3 months ago

If someone is interested in a quick solution in userland code. I added a check via https://github.com/ohdearapp/health-check-results

use Zenstruck\Messenger\Monitor\Twig\ViewHelper;

public function __construct(private readonly ViewHelper $viewHelper)
    {}

 ...
        $amountWorkers = $this->viewHelper->workers->count();

        if($amountWorkers == 0)
        {
            $checkResult = new CheckResult(
                name: 'SymfonyMessengerWorker',
                label: 'Running SymfonyMessengerWorker',
                notificationMessage: 'There are '.$amountWorkers.' workers running',
                shortSummary: $amountWorkers.' running',
                status: CheckResult::STATUS_FAILED,
                meta: ['workers' => $amountWorkers]
            );

            $checkResults->addCheckResult($checkResult);
        }