定制 gritzkoo/php-health-checker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gritzkoo/php-health-checker

Composer 安装命令:

composer require gritzkoo/php-health-checker

包简介

Simple package to health-check

README 文档

README

test Coverage Status GitHub issues GitHub pull requests GitHub GitHub repo size Packagist Downloads GitHub tag (latest by date) Packagist Stars GitHub language count

This is a PHP package that allows you to track the health of your application, providing two methods of checking $checkt->liveness() and $checker->readiness():

How to install

composer require gritzkoo/php-health-checker

Bootstrapping the checker

<?php

require 'vendor/autoload.php';

use Gritzkoo\HealthChecker\Check;
use Gritzkoo\HealthChecker\HealthChecker;

$checker = new HealthChecker([
    // optional prop, will be used to readiness response
    'name' => 'My application name', 
    // version is used in liveness and readiness actions
    'version' => 'v1.0.0', // more details in version section of this document!
    // the list of checks you whant to test, is just an array of array with name and handle function
    'integrations' => [
        [
            // the name of the integration you are trying to verify
            'name' => 'github status check',
            // here is just an example of how to make your own check
            // you can inject this function the way you want, you only need to return
            // a instance of Gritzkoo\HealthChecker\Check
            // The HealthCheker will interpret your check fails when the $check->error is not empty
            'handle' => function () {
                $check = new Check([
                    'url' => 'https://github.com/status'
                ]);
                $ch = curl_init($check->url);
                try {
                    $response = curl_exec($ch);
                } catch (Exception $e) {
                    $check->error = $e;
                }
                $info = curl_getinfo($ch);
                curl_close($ch);
                if ($info['http_code'] != 200) {
                    $check->error = [
                        'response' => $response,
                        'info' => $info
                    ];
                }
                return $check;
            }
        ]
    ]
]);

Example of use

You can view this full Laravel application, with this package installed in:

https://github.com/gritzkoo/php-health-checker-example-app

$checker->liveness()

Will return an ARRAY that you can convert to JSON as below and that allows you to check if your application is OK without checking any kind of integration.

{
    "status": "fully functional", 
    "version": "v1.0.0"
}

$checker->readiness()

Will return an ARRAY that you can convert to JSON as below and that allows you to check if your application is up and running and check if all of your integrations informed in the configuration list are up and running.

{
    "name": "My application name",
    "version": "v1.0.0",
    // the main status checks, will return true when all integrations does not fail
    "status": true, 
    // ISO 8601 date
    "date": "2022-06-25T11:52:56-03:00",
    "duration": 0.08681011199951172,
    "integrations": [
        {
            "name": "github status check",
            "status": true,
            "response_time": 0.08406686782836914,
            "url": "https://github.com/status",
            "error": null
        }
    ]
}

Create a HTTP inteface to expose probs

Using Laravel application example https://github.com/gritzkoo/php-health-checker-example-app

Once you create an instance of Gritzkoo\HealthChecker\HealthChecker you should create 2 routes in your application to expose liveness and readiness actions like:

And then, you could call these endpoints manually to see your application health, but, if you are using modern Kubernetes deployment, you can config your chart to check your application with the setup below:

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-http
spec:
  containers:
  - name: liveness
    image: 'node' #your application image
    args:
    - /server
    livenessProbe:
      httpGet:
        path: /health-check/liveness
        port: 80
        httpHeaders:
        - name: Custom-Header
          value: Awesome
      initialDelaySeconds: 3
      periodSeconds: 3
  - name: readiness
    image: 'node' #your application image
    args:
    - /server
    readinessProbe:
      httpGet:
        path: /health-check/readiness
        port: 80
        httpHeaders:
        - name: Custom-Header
          value: Awesome
      initialDelaySeconds: 3
      periodSeconds: 3

gritzkoo/php-health-checker 适用场景与选型建议

gritzkoo/php-health-checker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「healthcheck」 「k8s」 「health-check」 「probe」 「readiness」 「healthz」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gritzkoo/php-health-checker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gritzkoo/php-health-checker 我们能提供哪些服务?
定制开发 / 二次开发

基于 gritzkoo/php-health-checker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 35
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-25