Skip to content

Commit 39bf25e

Browse files
committed
first commit
0 parents  commit 39bf25e

38 files changed

+1767
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea/
2+
vendor/
3+
composer.lock
4+
.phpunit.result.cache

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Ali Tolouei
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Laravel Health Monitor
2+
A lightweight, extendable Laravel package for monitoring the health of internal services like Database, Redis, Queue, Cache, Filesystem, and any third-party APIs.
3+
4+
Built for developers who care about observability and application resilience.
5+
6+
## Installation
7+
Install the package via Composer:
8+
```
9+
composer require mrtolouei/laravel-health-monitor
10+
```
11+
Publish the configuration and provider stub:
12+
```
13+
php artisan vendor:publish --tag=health-monitor-config
14+
php artisan vendor:publish --tag=health-monitor-provider
15+
```
16+
17+
## Configuration
18+
The config file will be published to:
19+
20+
`config/health-monitor.php`
21+
22+
It contains two main sections:
23+
### ✅ App Services
24+
You can enable/disable health checkers and configure each one:
25+
```php
26+
'app-services' => [
27+
'database' => [
28+
'enabled' => true,
29+
'inspector' => HealthMonitor\Monitors\DatabaseHealthChecker::class,
30+
'arguments' => [
31+
'connection' => config('database.default', 'sqlite')
32+
],
33+
],
34+
'filesystem' => [
35+
'enabled' => true,
36+
'inspector' => HealthMonitor\Monitors\FilesystemHealthChecker::class,
37+
'arguments' => [
38+
'disk' => config('filesystems.default', 'local')
39+
],
40+
],
41+
...
42+
],
43+
```
44+
45+
### 🌐 Third-Party APIs
46+
You can define any number of third-party HTTP APIs to monitor:
47+
48+
```php
49+
'third-party-services' => [
50+
'json-test-api' => [
51+
'enabled' => true,
52+
'url' => 'https://jsonplaceholder.typicode.com/todos/1',
53+
'method' => 'GET',
54+
'headers' => [
55+
'Accept' => 'application/json',
56+
],
57+
'auth' => null,
58+
'timeout' => 5,
59+
'expected_status' => 200,
60+
],
61+
],
62+
```
63+
64+
Supported authentication types:
65+
66+
- `none`
67+
- `basic` (username & password)
68+
- `bearer` (token)
69+
- `ntlm`
70+
71+
### 🔒 Access Control
72+
A `Gate` is registered automatically to restrict access to non-local environments.
73+
74+
You can customize allowed users in `config/health-monitor.php`:
75+
```php
76+
'allowed_emails' => [
77+
78+
79+
],
80+
```
81+
82+
### 📡 Routes
83+
This package registers two routes (behind the `viewHealthMonitor` gate):
84+
85+
| Route | Method | Description |
86+
|--------------------|--------|-------------------------------------|
87+
| `/api-service-health`| `GET` | Returns JSON of health check status|
88+
| `/service-health` | `GET` | Shows a Blade view of statuses |
89+
90+
### 🧪 Add Custom Checkers
91+
Create a new class that implements the `HealthCheckerInterface`:
92+
93+
```php
94+
use HealthMonitor\Contracts\HealthCheckerInterface;
95+
use HealthMonitor\Dto\HealthResult;
96+
97+
class CustomChecker implements HealthCheckerInterface {
98+
public function monitor(): HealthResult {
99+
return new HealthResult('My Checker', 'custom', true);
100+
}
101+
102+
public function getConnectionDriver(): string|null {
103+
return 'custom';
104+
}
105+
}
106+
```
107+
Then register it in the config file.
108+
109+
### 📂 Directory Structure (short overview)
110+
```text
111+
laravel-health-monitor/
112+
├── config/
113+
├── src/
114+
│ ├── Contracts/
115+
│ ├── Dto/
116+
│ ├── Monitors/
117+
│ ├── Facades/
118+
│ ├── Factories/
119+
│ └── HealthMonitorExecutor.php
120+
└── routes/web.php
121+
```
122+
123+
### 🙌 Credits
124+
Developed and maintained by [Ali Tolouei](https://github.com/mrtolouei)
125+
126+
Feel free to contribute or suggest features via issues and PRs!
127+
128+
### 📄 License
129+
This package is open-sourced software licensed under the [MIT license](LICENSE).

composer.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "mrtolouei/laravel-health-monitor",
3+
"description": "Lightweight Laravel health check monitor.",
4+
"type": "library",
5+
"minimum-stability": "stable",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Ali Tolouei",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"require": {
14+
"php": ">=8.0",
15+
"illuminate/support": ">=9.0",
16+
"guzzlehttp/guzzle": "^7.0",
17+
"guzzlehttp/psr7": "^2.0"
18+
},
19+
"require-dev": {
20+
"pestphp/pest": "^2.0",
21+
"pestphp/pest-plugin-laravel": "^2.0",
22+
"mockery/mockery": "^1.5",
23+
"orchestra/testbench": "^8.0"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"HealthMonitor\\": "src/"
28+
}
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"HealthMonitor\\Tests\\": "tests/"
33+
}
34+
},
35+
"scripts": {
36+
"test": "pest"
37+
},
38+
"extra": {
39+
"laravel": {
40+
"providers": [
41+
"HealthMonitor\\HealthMonitorServiceProvider"
42+
]
43+
}
44+
},
45+
"config": {
46+
"allow-plugins": {
47+
"pestphp/pest-plugin": true
48+
}
49+
}
50+
}

config/health-monitor.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
4+
return [
5+
'app-services' => [
6+
'database' => [
7+
'enabled' => true,
8+
'inspector' => HealthMonitor\Monitors\DatabaseHealthChecker::class,
9+
'arguments' => [
10+
'connection' => config('database.default', 'sqlite')
11+
],
12+
],
13+
'filesystem' => [
14+
'enabled' => true,
15+
'inspector' => HealthMonitor\Monitors\FilesystemHealthChecker::class,
16+
'arguments' => [
17+
'disk' => config('filesystems.default', 'local')
18+
],
19+
],
20+
'cache' => [
21+
'enabled' => true,
22+
'inspector' => HealthMonitor\Monitors\CacheHealthChecker::class,
23+
'arguments' => [],
24+
],
25+
'queue' => [
26+
'enabled' => true,
27+
'inspector' => HealthMonitor\Monitors\QueueHealthChecker::class,
28+
'arguments' => [],
29+
],
30+
'redis' => [
31+
'enabled' => true,
32+
'inspector' => HealthMonitor\Monitors\RedisHealthChecker::class,
33+
'arguments' => [],
34+
],
35+
],
36+
'third-party-services' => [
37+
'json-test-api' => [
38+
'enabled' => true,
39+
'url' => 'https://jsonplaceholder.typicode.com/todos/1',
40+
'method' => 'GET',
41+
'headers' => [
42+
'Accept' => 'application/json',
43+
],
44+
'auth' => null,
45+
'timeout' => 5,
46+
'expected_status' => 200,
47+
],
48+
],
49+
];

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
>
7+
<testsuites>
8+
<testsuite name="Test Suite">
9+
<directory suffix="Test.php">./tests</directory>
10+
</testsuite>
11+
</testsuites>
12+
<source>
13+
<include>
14+
<directory suffix=".php">./app</directory>
15+
<directory suffix=".php">./src</directory>
16+
</include>
17+
</source>
18+
</phpunit>

0 commit comments

Comments
 (0)