PHPackages                             cpsit/monitoring - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. cpsit/monitoring

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

cpsit/monitoring
================

Generic monitoring solution for web applications

2.0.0(5mo ago)13.1k↓36.4%[1 issues](https://github.com/CPS-IT/monitoring/issues)GPL-3.0-or-laterPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Dec 17Pushed 1mo ago5 watchersCompare

[ Source](https://github.com/CPS-IT/monitoring)[ Packagist](https://packagist.org/packages/cpsit/monitoring)[ RSS](/packages/cpsit-monitoring/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (18)Versions (6)Used By (0)

Monitoring
==========

[](#monitoring)

[![Coverage](https://camo.githubusercontent.com/bb5a03131695aa147c7bcc1927c9a86f2710e07bdbc1f6f177cccbe879164945/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c73436f7665726167652f6769746875622f4350532d49542f6d6f6e69746f72696e673f6c6f676f3d636f766572616c6c73)](https://coveralls.io/github/CPS-IT/monitoring)[![CGL](https://camo.githubusercontent.com/b9d0a5275b2e93e6581e5a96d36a4cbb844274b9e7ddcb1ada1765f771b0afca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4350532d49542f6d6f6e69746f72696e672f63676c2e79616d6c3f6c6162656c3d63676c266c6f676f3d676974687562)](https://github.com/CPS-IT/monitoring/actions/workflows/cgl.yaml)[![Tests](https://camo.githubusercontent.com/98592b54c12d76fd7f6e925be04d001f52a52a0d81060dc0ae73efd32bb4d14d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4350532d49542f6d6f6e69746f72696e672f74657374732e79616d6c3f6c6162656c3d7465737473266c6f676f3d676974687562)](https://github.com/CPS-IT/monitoring/actions/workflows/tests.yaml)[![Supported PHP Versions](https://camo.githubusercontent.com/95723d99707b2a364a78192f8e4e596845619b8beb7d27ca58a2af0063e9e696/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f63707369742f6d6f6e69746f72696e672f7068703f6c6f676f3d706870)](https://packagist.org/packages/cpsit/monitoring)

This package provides a generic monitoring solution for web applications. It can be used to monitor various parts of your application by implementing a set of monitoring providers and exposing their health state by using a dedicated monitoring route. The package is highly customizable in terms of implementing custom monitoring providers and authorization solutions.

🔥 Installation
--------------

[](#-installation)

[![Packagist](https://camo.githubusercontent.com/c91a4e3d80ccb6e38f9fda1a1bdfa6f193adb8d673d24c4cca1daf2db0a9a46b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63707369742f6d6f6e69746f72696e673f6c6162656c3d76657273696f6e266c6f676f3d7061636b6167697374)](https://packagist.org/packages/cpsit/monitoring)[![Packagist Downloads](https://camo.githubusercontent.com/0dd7caca14dc337ade1346c4f8144ff4b1b845235e8783fb6606603b98556cc8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63707369742f6d6f6e69746f72696e673f636f6c6f723d627269676874677265656e)](https://packagist.org/packages/cpsit/monitoring)

```
composer require cpsit/monitoring
```

⚡ Usage
-------

[](#-usage)

### Monitoring service

[](#monitoring-service)

The package ships a [`Monitoring`](src/Monitoring.php) class which can be used to check health of various services.

Services can be defined using the [`MonitoringProvider`](src/Provider/MonitoringProvider.php)interface. Each provider can reveal the health state of the underlain service using the `isHealthy()`method.

```
namespace My\Vendor\Monitoring\Provider;

use CPSIT\Monitoring\Provider\MonitoringProvider;
use My\Vendor\Service\ApiService;

final class ApiMonitoringProvider implements MonitoringProvider
{
    public function __construct(
        private readonly ApiService $apiService,
    ) {}

    public function getName(): string
    {
        return 'api';
    }

    public function isHealthy(): bool
    {
        try {
            $response = $this->apiService->request('/health', 'HEAD');
            return $response->getStatusCode() < 400;
        } catch (\Exception) {
            return false;
        }
    }
}
```

### Report errors

[](#report-errors)

In addition to the normal health state, providers might also be able to report errors which occurred during health check. For this, an [`ExceptionAwareMonitoringProvider`](src/Provider/ExceptionAwareMonitoringProvider.php)interface exists. It allows to fetch errors using the `getLastException()` method.

```
 namespace My\Vendor\Monitoring\Provider;

-use CPSIT\Monitoring\Provider\MonitoringProvider;
+use CPSIT\Monitoring\Provider\ExceptionAwareMonitoringProvider;
 use My\Vendor\Service\ApiService;

-final class ApiMonitoringProvider implements MonitoringProvider
+final class ApiMonitoringProvider implements ExceptionAwareMonitoringProvider
 {
+    private ?\Throwable $lastException = null;
+
     public function __construct(
         private readonly ApiService $apiService,
     ) {}

     public function getName(): string
     {
         return 'api';
     }

     public function isHealthy(): bool
     {
         try {
             $response = $this->apiService->request('/health', 'HEAD');
             return $response->getStatusCode() < 400;
-        } catch (\Exception) {
+        } catch (\Exception $exception) {
+            $this->lastException = $exception;
             return false;
         }
     }
+
+    public function getLastException(): ?\Throwable
+    {
+        return $this->lastException;
+    }
 }
```

### Provide individual status information

[](#provide-individual-status-information)

Each provider can be extended to return individual status information. This is possible once the [`StatusInformationAwareMonitoringProvider`](src/Provider/StatusInformationAwareMonitoringProvider.php)interface is implemented within a concrete provider.

```
 namespace My\Vendor\Monitoring\Provider;

-use CPSIT\Monitoring\Provider\MonitoringProvider;
+use CPSIT\Monitoring\Provider\StatusInformationAwareMonitoringProvider;
 use My\Vendor\Service\ApiService;

-final class ApiMonitoringProvider implements MonitoringProvider
+final class ApiMonitoringProvider implements StatusInformationAwareMonitoringProvider
 {
     public function __construct(
         private readonly ApiService $apiService,
     ) {}

     public function getName(): string
     {
         return 'api';
     }

     public function isHealthy(): bool
     {
         try {
             $response = $this->apiService->request('/health', 'HEAD');
             return $response->getStatusCode() < 400;
         } catch (\Exception) {
             return false;
         }
     }
+
+    /**
+     * @return array
+     */
+    public function getStatusInformation(): array
+    {
+        $lastProcessDate = $this->apiService->getLastProcessDate();
+
+        return [
+            'last_process_date' => $lastProcessDate->format(\DateTimeInterface::RFC2822),
+        ];
+    }
 }
```

### Middleware

[](#middleware)

Additionally, a middleware [`MonitoringMiddleware`](src/Middleware/MonitoringMiddleware.php) exists. It can be used to make health checks available using the middleware stack of a web application. A set of monitoring providers needs to be provided when constructing the middleware. This can be best achieved with a PSR-11 service container, e.g. within a Symfony or Symfony-based application.

In case the monitoring result is healthy, a `200 OK` response will be returned, otherwise the response is `424 Failed Dependency`. All responses are in JSON format and contain the serialized monitoring result. If an internal error occurs (such as failed JSON encoding), the response is `500 Internal Server Error`and the response body contains the error message in JSON format.

#### Validators

[](#validators)

The middleware acts only on valid requests. The decision as to whether a request is valid is in the hands of so called *validators*. Each validator must implement the [`Validator`](src/Validation/Validator.php) interface.

The package already provides the [`RouteValidator`](src/Validation/RouteValidator.php). It can be configured to allow only requests to a given route, which is `/monitor/health` by default. In case this route is matched, the request is valid and therefore the monitoring process will be triggered.

#### Authorizers

[](#authorizers)

Requests handled by the provided middleware can be secured using a list of *authorizers*. Authorizers are classes which implement the [`Authorizer`](src/Authorization/Authorizer.php) interface. Each authorizer must implement the `isAuthorized()` method. In case any authorizer returns `true`, the request will be processed as is. If no authorizer is able to give the appropriate authorization, a `401 Unauthorized` response will be returned.

Authorizers can be prioritized by defining an explicit priority using the `getPriority()` method. Authorizers with higher priority will be executed first.

### Dependency injection

[](#dependency-injection)

The package already provides a ready-made container configuration for dependency injection based on [Symfony dependency injection](https://symfony.com/doc/current/components/dependency_injection.html). This is particularly helpful if several monitoring providers are to be automatically configured on the middleware.

For this purpose, it is necessary to install the following packages via Composer:

```
composer require symfony/config symfony/dependency-injection symfony/yaml
```

Note

The dependency injection configuration is an **optional component** of this package. Therefore, required Composer packages are not explicitly required, but only suggested. You must install them **by your own**.

The next step is to load the configuration into the container. For this, the package provides a helper class [`ServiceConfigurator`](src/DependencyInjection/ServiceConfigurator.php):

```
use CPSIT\Monitoring\DependencyInjection\ServiceConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;

return static function (ContainerBuilder $container): void {
    ServiceConfigurator::configure($container);
};
```

All classes that are configured in the service container and implement the `MonitoringProvider` interface are now automatically tagged with `monitoring.provider`. The [`MonitoringProviderCompilerPass`](src/DependencyInjection/MonitoringProviderCompilerPass.php)then takes care of the autoconfiguration of all tagged monitoring providers at the `MonitoringMiddleware` class.

🧑‍💻 Contributing
----------------

[](#‍-contributing)

Please have a look at [`CONTRIBUTING.md`](CONTRIBUTING.md).

⭐ License
---------

[](#-license)

This project is licensed under [GNU General Public License 3.0 (or later)](LICENSE).

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance61

Regular maintenance activity

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 85.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~351 days

Total

2

Last Release

167d ago

Major Versions

1.0.0 → 2.0.02025-12-03

PHP version history (2 changes)1.0.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

2.0.0PHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/144cefe55242b883c87cb537463f3ba75a0f8198fc5b602b50c838aae31fe7ee?d=identicon)[eliashaeussler](/maintainers/eliashaeussler)

![](https://www.gravatar.com/avatar/a664c83f7a6760600d2a325f751b2a206f686b3dcb2f1dce5655ead343dc5a24?d=identicon)[cps](/maintainers/cps)

---

Top Contributors

[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (196 commits)")[![eliashaeussler](https://avatars.githubusercontent.com/u/16313625?v=4)](https://github.com/eliashaeussler "eliashaeussler (34 commits)")

---

Tags

checkcomposer-packagehealthmonitoring

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cpsit-monitoring/health.svg)

```
[![Health](https://phpackages.com/badges/cpsit-monitoring/health.svg)](https://phpackages.com/packages/cpsit-monitoring)
```

###  Alternatives

[google/cloud

Google Cloud Client Library

1.2k16.2M53](/packages/google-cloud)[neuron-core/neuron-ai

The PHP Agentic Framework.

1.8k245.3k21](/packages/neuron-core-neuron-ai)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[neos/flow-development-collection

Flow packages in a joined repository for pull requests.

144179.3k3](/packages/neos-flow-development-collection)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[eliashaeussler/typo3-warming

Warming - Warms up Frontend caches based on an XML sitemap. Cache warmup can be triggered via TYPO3 backend or using a console command. Supports multiple languages and custom crawler implementations.

20229.9k](/packages/eliashaeussler-typo3-warming)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
