{"id":14983935,"url":"https://github.com/liip/liipmonitorbundle","last_synced_at":"2025-05-14T22:07:33.654Z","repository":{"id":2649430,"uuid":"3639633","full_name":"liip/LiipMonitorBundle","owner":"liip","description":"Integrates the LiipMonitor library into Symfony","archived":false,"fork":false,"pushed_at":"2025-02-26T14:59:12.000Z","size":997,"stargazers_count":471,"open_issues_count":0,"forks_count":104,"subscribers_count":64,"default_branch":"master","last_synced_at":"2025-05-14T22:07:27.791Z","etag":null,"topics":["bundle","php","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"http://liip.ch","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2012-03-06T16:02:48.000Z","updated_at":"2025-05-14T09:46:35.000Z","dependencies_parsed_at":"2024-05-13T20:29:07.234Z","dependency_job_id":"36ebe8aa-b8cd-4f7c-9e30-d9f0b898e7c9","html_url":"https://github.com/liip/LiipMonitorBundle","commit_stats":{"total_commits":400,"total_committers":84,"mean_commits":4.761904761904762,"dds":0.74,"last_synced_commit":"7e34ca48da6a18f3657c8ac4cedbe4f3a5e7195e"},"previous_names":[],"tags_count":73,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liip%2FLiipMonitorBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liip%2FLiipMonitorBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liip%2FLiipMonitorBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liip%2FLiipMonitorBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liip","download_url":"https://codeload.github.com/liip/LiipMonitorBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235696,"owners_count":22036963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bundle","php","symfony","symfony-bundle"],"created_at":"2024-09-24T14:08:12.264Z","updated_at":"2025-05-14T22:07:28.637Z","avatar_url":"https://github.com/liip.png","language":"PHP","readme":"\n# Liip Monitor Bundle #\n\n[![CI Status](https://github.com/liip/LiipMonitorBundle/workflows/CI/badge.svg)](https://github.com/liip/LiipMonitorBundle/actions?query=workflow%3ACI)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/liip/LiipMonitorBundle/badges/quality-score.png?s=ee7a1c39f11955b987b09aefb59b4b826157c754)](https://scrutinizer-ci.com/g/liip/LiipMonitorBundle/)\n\nThis bundle provides a way to run a series of application related health checks.\nHealth checks in the scope of this bundle go beyond simple actions like performing\na _ping_ to a server to see if it's alive. For example a Memcache server can be\nalive and not displaying any errors in your Nagios but you might not be able to\naccess it from your PHP application. Each health check should then implement some\napplication logic that you want to make sure always works. Another usage can be\ntesting for specific requirements, like availability of PHP extensions.\n\nAnother design goal of the bundle was to be able to perform the checks using the\nsame configuration and environment that your application is using. In that way you\ncan make sure that if the health check runs successfully then your app should work\ntoo.\n\nSo each health check will be a class that will implement the `CheckInterface::check`\nmethod which must return a `CheckResult` object. What happens inside that method\nis up to the check developer.\n\nHealth checks are defined as Symfony services and they have to be tagged as\n`liip_monitor.check` in order to be picked up by the _health check runner_. This gives\na lot of flexibility to application and bundle developers when they want to add their\nown checks.\n\nChecks are run via the command line using a Symfony command or via a REST api that\ndelivers the results in JSON format.\n\nHere's the web interface:\n\n![Web Interface](https://raw.githubusercontent.com/liip/LiipMonitorBundle/master/Resources/doc/screenshot.png \"Web Interface\")\n\n## Installation ##\n\nInstall with composer:\n```bash\ncomposer require liip/monitor-bundle\n```\n\nThen register the bundle in the `AppKernel.php` file:\n\n```php\npublic function registerBundles()\n{\n    $bundles = array(\n        // ...\n        new Liip\\MonitorBundle\\LiipMonitorBundle(),\n        // ...\n    );\n\n    return $bundles;\n}\n```\n\nIf you want to enable the REST API provided by the bundle then add the following to your `routing.yml`:\n\n```yml\n_monitor:\n    resource: \"@LiipMonitorBundle/Resources/config/routing.xml\"\n    prefix: /monitor/health\n```\n\nThen, enable the controller in your configuration:\n\n```yml\nliip_monitor:\n    enable_controller: true\n```\n\nAnd finally don't forget to install the bundle assets into your web root:\n\n```bash\n./app/console assets:install web --symlink --relative\n```\n\n## Enabling built-in health checks\n\nTo enable built-in health checks, add them to your `config.yml`\n\n```yml\nliip_monitor:\n    checks:\n        php_extensions: [apc, xdebug]\n```\n\n## Adding Health Checks ##\n\nSee [Writing Custom Checks](https://docs.laminas.dev/laminas-diagnostics/custom-checks/) for instructions\non creating a custom check.\n\nOnce you implemented the class then it's time to register the check service with our service container:\n\n```yml\nservices:\n    monitor.check.php_extensions:\n        class: Acme\\HelloBundle\\Check\\PhpExtensionsCheck\n        arguments:\n            - [ xhprof, apc, memcache ]\n        tags:\n            - { name: liip_monitor.check, alias: php_extensions }\n```\n\nThe important bit there is to remember to tag your services with the `liip_monitor.check` tag.\nBy doing that the check runner will be able to find your checks. Keep in mind that checks\ncan reside either in your bundles or in your app specific code. The location doesn't matter\nas long as the service is properly tagged. The ``alias`` is optional and will then simply\ndefine the ``id`` used when running health checks individually, otherwise the full service\nid must be used in this case.\n\nIf your app's service definition is using `autoconfigure` to discover services then classes \nwhich implement `Laminas\\Diagnostics\\Check\\CheckInterface` will be tagged automatically.\n\n## Available Built-in Health Checks ##\n\nSee \"Full Default Config\" below for a list of all built-in checks and their configuration.\n\n## Running Checks ##\n\nThere are two ways of running the health checks: by using the CLI or by using the REST API\nprovided by the bundle. Let's see what commands we have available for the CLI:\n\n### List Checks ###\n\n    $ ./app/console monitor:list\n\n    monitor.check.jackrabbit\n    monitor.check.redis\n    monitor.check.memcache\n    monitor.check.php_extensions\n\n### Run All the Checks ###\n\n    $ ./app/console monitor:health\n\n    Jackrabbit Health Check: OK\n    Redis Health Check: OK\n    Memcache Health Check: KO - No configuration set for session.save_path\n    PHP Extensions Health Check: OK\n\n### Run Individual Checks ###\n\nTo run an individual check you need to provide the check id to the `health` command:\n\n    $ ./app/console monitor:health monitor.check.php_extensions\n\n    PHP Extensions Health Check: OK\n\n### Run health checks as composer post-install/update scripts\n\nTo run health checks as a composer post-install or post-update script, simply add the\n`Liip\\\\MonitorBundle\\\\Composer\\\\ScriptHandler::checkHealth` ScriptHandler to the\n`post-install-cmd / post-update-cmd` command sections of your `composer.json`:\n\n```json\n\"scripts\": {\n    \"post-install-cmd\": [\n        \"Sensio\\\\Bundle\\\\DistributionBundle\\\\Composer\\\\ScriptHandler::buildBootstrap\",\n        \"Sensio\\\\Bundle\\\\DistributionBundle\\\\Composer\\\\ScriptHandler::clearCache\",\n        \"Sensio\\\\Bundle\\\\DistributionBundle\\\\Composer\\\\ScriptHandler::installAssets\",\n        \"Sensio\\\\Bundle\\\\DistributionBundle\\\\Composer\\\\ScriptHandler::installRequirementsFile\",\n        \"Liip\\\\MonitorBundle\\\\Composer\\\\ScriptHandler::checkHealth\"\n    ],\n    \"post-update-cmd\": [\n        \"Sensio\\\\Bundle\\\\DistributionBundle\\\\Composer\\\\ScriptHandler::buildBootstrap\",\n        \"Sensio\\\\Bundle\\\\DistributionBundle\\\\Composer\\\\ScriptHandler::clearCache\",\n        \"Sensio\\\\Bundle\\\\DistributionBundle\\\\Composer\\\\ScriptHandler::installAssets\",\n        \"Sensio\\\\Bundle\\\\DistributionBundle\\\\Composer\\\\ScriptHandler::installRequirementsFile\",\n        \"Liip\\\\MonitorBundle\\\\Composer\\\\ScriptHandler::checkHealth\"\n    ]\n},\n```\n\n## Adding Additional Reporters ##\n\nThere are two default reporters: `ArrayReporter` for the REST API and `ConsoleReporter` for the CLI command. You can\nadd additional reporters to be used by either of these.\n\nFirst, define an additional reporter service and tag it with `liip_monitor.additional_reporter`:\n\n```yml\nmy_reporter:\n    class: My\\Reporter\n    tags:\n        - { name: liip_monitor.additional_reporter, alias: my_reporter }\n```\n\nTo run additional reporters with the CLI, add `--reporter=...` options for each one:\n```bash\n    ./app/console monitor:health --reporter=my_reporter\n```\nTo run this reporter with the REST API, add a `reporters` query parameter:\n\n    /monitor/health?reporters[]=my_reporter\n\nYou can list available reporters with:\n\n```bash\nbin/console monitor:list --reporters\n```\n\n## Grouping Checks\n\nIt is possible to group the health checks for different environments (e.g. application server, cron runner, ...).\nIf not specified differently, all health checks belong to the `default` group.\n\n### Define groups for build-in checks\n\nTo define groups for built-in health checks, add the following grouping hint to your `config.yml`:\n\n```yml\nliip_monitor:\n    default_group: default\n    checks:\n        groups:\n            default: # checks you may want to execute by default\n                php_extensions: [apc, xdebug]\n            cron: # checks you may want to execute only on cron servers\n                php_extensions: [redis]\n```\n\nThis creates two groups, `default` and `cron`, each having different checks.\n\n### Define groups for tagged Services\n\nTo define groups for tagged services, add a `group` attribute to the respective tags:\n\n```yml\nservices:\n    monitor.check.php_extensions:\n        class: Acme\\HelloBundle\\Check\\PhpExtensionsCheck\n        arguments:\n            - [ xhprof, apc, memcache ]\n        tags:\n            - { name: liip_monitor.check, alias: php_extensions, group: cron }\n            - { name: liip_monitor.check, alias: php_extensions, group: app_server }\n```\n\n`autoconfigure` will place checks into the default group. You must add `autoconfigure: false` to the service\ndefinition to change the group:\n\n```yml\nservices:\n    Acme\\HelloBundle\\Check\\PhpExtensionsCheck:\n        autoconfigure: false\n        tags:\n            - { name: liip_monitor.check, group: app_server }\n```\n\n### Specify group for CLI commands\n\nBoth CLI commands have a `--group=...` option. If it is not given, the default group is used.\n\n```bash\nbin/console monitor:list --group=app_server\nbin/console monitor:health --group=app_server\n```\n\nBoth commands, `monitor:list` and `monitor:health`, have an option `--all` to list or run the checks of all registered\ngroups. Additionally, the `monitor:list` has an option `--groups` to list all registered groups.\n\n## Full Default Config\n\n```yml\nliip_monitor:\n    enable_controller:    false\n    view_template:        null\n    failure_status_code:  502\n    mailer:\n        enabled:              false\n        recipient:            ~ # Required\n        sender:               ~ # Required\n        subject:              ~ # Required\n        send_on_warning:      true\n    default_group:        default\n    checks:\n\n        # Grouping checks\n        groups:\n\n            # Prototype\n            name:\n\n                # Validate that a named extension or a collection of extensions is available\n                php_extensions:       [] # Example: apc, xdebug\n\n                # Pairs of a PHP setting and an expected value\n                php_flags:            # Example: session.use_only_cookies: false\n\n                    # Prototype\n                    setting:              ~\n\n                # Pairs of a version and a comparison operator\n                php_version:          # Example: 5.4.15: \u003e=\n\n                    # Prototype\n                    version:              ~\n\n                # Process name/pid or an array of process names/pids\n                process_running:      ~ # Example: [apache, foo]\n\n                # Validate that a given path (or a collection of paths) is a dir and is readable\n                readable_directory:   [] # Example: [\"%kernel.cache_dir%\"]\n\n                # Validate that a given path (or a collection of paths) is a dir and is writable\n                writable_directory:   [] # Example: [\"%kernel.cache_dir%\"]\n\n                # Validate that a class or a collection of classes is available\n                class_exists:         [] # Example: [\"Lua\", \"My\\Fancy\\Class\"]\n\n                # Benchmark CPU performance and return failure if it is below the given ratio\n                cpu_performance:      ~ # Example: 1.0 # This is the power of an EC2 micro instance\n\n                # Checks to see if the disk usage is below warning/critical percent thresholds\n                disk_usage:\n                    warning:              70\n                    critical:             90\n                    path:                 '%kernel.cache_dir%'\n\n                # Checks Symfony2 requirements file\n                symfony_requirements:\n                    file:                 '%kernel.root_dir%/SymfonyRequirements.php'\n\n                # Checks to see if the OpCache memory usage is below warning/critical thresholds\n                opcache_memory:\n                    warning:              70\n                    critical:             90\n\n                # Checks to see if the APC memory usage is below warning/critical thresholds\n                apc_memory:\n                    warning:              70\n                    critical:             90\n\n                # Checks to see if the APC fragmentation is below warning/critical thresholds\n                apc_fragmentation:\n                    warning:              70\n                    critical:             90\n\n                # Connection name or an array of connection names\n                doctrine_dbal:        null # Example: [default, crm]\n                \n                # Checks to see if migrations from specified configuration file are applied\n                doctrine_migrations:\n                    # Examples:\n                    application_migrations: \n                        configuration_file:  %kernel.root_dir%/Resources/config/migrations.yml\n                        connection:          default\n                    migrations_with_doctrine_bundle: \n                        connection:          default\n                    migrations_with_doctrine_bundle_v2: default\n                    \n                    # Prototype\n                    name:\n                        # Absolute path to doctrine migrations configuration\n                        configuration_file:   ~\n                        # Connection name from doctrine DBAL configuration\n                        connection:           ~ # Required\n                \n                # Connection name or an array of connection names\n                doctrine_mongodb:        null # Example: [default, crm]\n\n                # Check if MemCache extension is loaded and given server is reachable\n                memcache:\n\n                    # Prototype\n                    name:\n                        host:                 localhost\n                        port:                 11211\n\n                # Validate that a Redis service is running\n                redis:\n\n                    # Prototype\n                    name:\n                        host:                 localhost\n                        port:                 6379\n                        password:             null\n                        # or\n                        dsn: redis://localhost:6379\n\n                # Attempt connection to given HTTP host and (optionally) check status code and page content\n                http_service:\n\n                    # Prototype\n                    name:\n                        host:                 localhost\n                        port:                 80\n                        path:                 /\n                        status_code:          200\n                        content:              null\n\n                # Attempt connection using Guzzle to given HTTP host and (optionally) check status code and page content\n                guzzle_http_service:\n\n                    # Prototype\n                    name:\n                        url:                  localhost\n                        headers:              []\n                        options:              []\n                        status_code:          200\n                        content:              null\n                        method:               GET\n                        body:                 null\n\n                # Validate that a RabbitMQ service is running\n                rabbit_mq:\n\n                    # Prototype\n                    name:\n                        host:                 localhost\n                        port:                 5672\n                        user:                 guest\n                        password:             guest\n                        vhost:                /\n                        # or\n                        dsn: amqp://guest:guest@localhost:5672/%2F\n\n                # Checks the version of this app against the latest stable release\n                symfony_version:      ~\n\n                # Checks if error pages have been customized for given error codes\n                custom_error_pages:\n                    # The status codes that should be customized\n                    error_codes:          [] # Required\n\n                    # The directory where your custom error page twig templates are located. Keep as \"%kernel.project_dir%\" to use default location.\n                    path:                 '%kernel.project_dir%'\n\n                # Checks installed composer dependencies against the SensioLabs Security Advisory database\n                security_advisory:\n                    lock_file:            '%kernel.root_dir%/../composer.lock'\n\n                # Validate that a stream wrapper or collection of stream wrappers exists\n                stream_wrapper_exists:  [] # Example: ['zlib', 'bzip2', 'zip']\n\n                # Find and validate INI files\n                file_ini:             [] # Example: ['path/to/my.ini']\n\n                # Find and validate JSON files\n                file_json:            [] # Example: ['path/to/my.json']\n\n                # Find and validate XML files\n                file_xml:             [] # Example: ['path/to/my.xml']\n\n                # Find and validate YAML files\n                file_yaml:            [] # Example: ['path/to/my.yml']\n                \n                # PDO connections to check for connection\n                pdo_connections:\n\n                    # Prototype\n                    name:\n                        dsn:                  null\n                        username:             null\n                        password:             null\n                        timeout:              1\n\n                # Checks that fail/warn when given expression is false (expressions are evaluated with symfony/expression-language)\n                expressions:\n\n                    # Example:\n                    opcache:             \n                        label:               OPcache\n                        warning_expression:  ini('opcache.revalidate_freq') \u003e 0\n                        critical_expression: ini('opcache.enable')\n                        warning_message:     OPcache not optimized for production\n                        critical_message:    OPcache not enabled\n\n                    # Prototype\n                    alias:\n                        label:                ~ # Required\n                        warning_expression:   null # Example: ini('apc.stat') == 0\n                        critical_expression:  null # Example: ini('short_open_tag') == 1\n                        warning_message:      null\n                        critical_message:     null\n\n                # Validate that a messenger transport does not contain more than warning/critical messages\n                # Transport must implement MessageCountAwareInterface\n                messenger_transports:\n                    name: # name of transport\n                        critical_threshold:   10   # required\n                        warning_threshold:    null # optional: warning level\n                        service:              null # defaults to messenger.transport.name \n```\n\n## REST API DOCS ##\n\nFor documentation on the REST API see: [http://myproject.org/monitor/health/](http://myproject.org/monitor/health/).\nDon't forget to add the bundle routes in your `routing.xml` file.\n\n\n## Nagios integration ##\n\nYou can find a simple Nagios check written in Perl and Python in the Resources/scripts directory.\n\n### Perl Version ###\n\nThis is dependent on perl modules available on CPAN Getopt::Std, WWW::Mechanize, and JSON\n\n\nCopy the script into your scripts directory in Nagios and create a command like this:\n\n    define command{\n            command_name    check_symfony_health\n            command_line    $USER1$/check_symfony2.pl -H $HOSTNAME$\n    }\n\nRunning the command with the Hostname flag (-H) will check \"http://$HOSTNAME$/monitor/health/run\".\nYou can also use the Address flag (-A) to check a specified URL:\n\n    command_line    $USER1$/check_symfony2.pl -A https://mysite.org/monitor/health/run\n\nThe plugin can be used with Authentication, Using the Username (-u) and Password (-p) flags:\n\n    command_line    $USER1$/check_symfony2.p1 -H $HOSTNAME$ -u username -p password\n\nYou can also specify the Warning (-w) and Critical (-c) levels for the check using the standard flags\n\n    command_line    $USER1$/check_symfony2.pl -H $HOSTNAME$ -w 1 -c 2\n\nAny flags can be combined except -A and -H. THe -u and -p flags should always be used together.\n\n### Python Version ###\n\nThe Python version depends on the nagiosplugin library \u003c 1.0.0.\n\nCopy the script into your scripts directory in Nagios and create a command like this:\n\n    define command{\n            command_name    check_symfony_health\n            command_line    $USER1$/check_symfony2.py -w 0  -c 0 -u https://$HOSTNAME$\n    }\n\nTo use the plugin with HTTP basic authentication, change the command to:\n\n    command_line    $USER1$/check_symfony2.py -w 0  -c 0 -u https://$HOSTNAME$ -a username:password\n\n### Connecting Check to Host in Nagios ###\n\nAdd a service:\n\n    define service{\n     hostgroup_name         Symfony2\n     service_description    Symfony2 health check\n     check_command          check_symfony_health\n     use                    generic-service\n    }\n\nAnd create a host attached to the Symfony2 hostgroup:\n\n    define host{\n        use              web-host\n        host_name        www.myhost.com\n        address          8.8.8.4\n        hostgroups       Symfony2\n    }\n\nAnd place your host within the Symfony2 hostgroup.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliip%2Fliipmonitorbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliip%2Fliipmonitorbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliip%2Fliipmonitorbundle/lists"}