Giter Club home page Giter Club logo

laravel-healthchecks's Introduction

Laravel Healthchecks

CI codecov StyleCI Latest Stable Version Total Downloads Monthly Downloads License

Laravel Healthchecks is a simple controller class that helps you build your own healthchecks endpoint without issues.

๐Ÿค Supporting

If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with Github Sponsors. ๐Ÿ“ฆ

๐Ÿš€ Installation

You can install the package via composer:

composer require renoki-co/laravel-healthchecks

๐Ÿ™Œ Usage

First of all, you should create your own Controller for healthchecks, that extends the RenokiCo\LaravelHealthchecks\Http\Controllers\HealthcheckController.

use Illuminate\Http\Request;
use RenokiCo\LaravelHealthchecks\Http\Controllers\HealthcheckController;

class MyHealthcheckController extends HealthcheckController
{
    /**
     * Register the healthchecks.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return void
     */
    public function registerHealthchecks(Request $request)
    {
        $this->addHealthcheck('mysql', function (Request $request) {
            // Try testing the MySQL connection here
            // and return true/false for pass/fail.

            return true;
        });
    }
}
// In your routes
Route::get('/healthcheck', [MyHealthcheckController::class, 'handle']);

Registering healthchecks

Within the controller, you should register the healthchecks closures in the registerHealthchecks method, like the example stated above.

You can add as many healthchecks as you want.

public function registerHealthchecks(Request $request)
{
    $this->addHealthcheck('mysql', function (Request $request) {
        //
    });

    $this->addHealthcheck('redis', function (Request $request) {
        //
    });

    $this->addHealthcheck('some_check', function (Request $request) {
        //
    });

    $this->addHealthcheck('another_check_here', function (Request $request) {
        //
    });
}

Status Codes

In case of failure, the response is 500. For all successful responses, the status code is 200.

To change the http codes being sent out, specify this in your registerHealthchecks method:

public function registerHealthchecks(Request $request)
{
    $this->setPassingHttpCode(203);

    $this->setFailingHttpCode(403);

    $this->addHealthcheck('mysql', function (Request $request) {
        return true;
    });
}

Outputs

By default, the output will be OK or FAIL as string, but in case you want to debug the healthchecks, you can get a JSON with each registered healthchecks and their pass/fail closures.

You have just to call withOutput():

public function registerHealthchecks(Request $request)
{
    $this->withOutput();

    $this->addHealthcheck('mysql', function (Request $request) {
        return true;
    });

    $this->addHealthcheck('redis', function (Request $request) {
        return false;
    });
}

The output in the browser would be like this:

{
    "mysql": true,
    "redis": false
}

๐Ÿ› Testing

vendor/bin/phpunit

๐Ÿค Contributing

Please see CONTRIBUTING for details.

๐Ÿ”’ Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

๐ŸŽ‰ Credits

laravel-healthchecks's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar laravel-shift avatar rennokki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-healthchecks's Issues

Publish version 1.2.0 to packagist

Hi, first of all thanks for this project, it's really helpful!

After the release of Laravel 8 and trying to upgrade, we've checked the tags and there's a 1.2.0 version, however when running composer update it says it can't find this version.

It's probably just a packagist release that's needed.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.