katmore/healthsvc

健康Web服务

v1.0.3 2018-12-15 03:39 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:28:40 UTC


README

Healthsvc是一个具有RESTful API接口的系统健康状况服务。它可以独立使用,也可以集成到现有项目中。它旨在与DevOps工作流程、功能测试、监控软件等一起使用。

作为独立服务使用

  • 下载healthsvc

    git clone https://github.com/katmore/healthsvc.git
  • 使用Composer更新

    cd healthsvc
    composer update
  • 使用host-sanity-config.php命令行工具打印可用的“主机健康”测试列表

    bin/host-sanity-config.php --print-bin-list
  • 使用host-sanity-config.php命令行工具添加带有标签“free-space”的“主机健康”测试

    bin/host-sanity-config.php --bin free-space free-space-check /tmp
  • 配置用于HTTP服务器的端点

    • 仅限开发使用

      bin/webservice
    • 生产或开发

      • 在现有的HTTP根目录中创建指向healthsvc/web目录的符号链接
      ln -s /var/www/healthsvc/web /var/www/html/healthsvc
      # nginx example
      server {
      ...
          root   /var/www/healthsvc/web;
      ...
      }
  • 测试web/host-sanity.php Web服务端点

    • 例如,使用curl命令行工具
      curl https://:8000/host-sanity.php
  • web/host-sanity.php响应体示例,当测试处于“成功”状态时(200/OK响应代码)

    {
     "hostname": "my-host",
     "exec_exit_status": [],
     "health_status_time": "2018-12-11T21:51:36-08:00",
     "health_status_ttl": 0,
     "message": "total success",
     "health_info": {
         "free-space": {
             "stdout": [
                 "ok: '\/tmp' has 81% free disk space"
             ]
         }
     },
     "health_success": [
         "free-space"
     ],
     "health_warn": [],
     "health_failure": []
    }
  • web/host-sanity.php响应体示例,当一个或多个测试处于“失败”状态时(500/内部服务器错误响应代码)

    {
     "hostname": "my-host",
     "exec_exit_status": {
         "free-space": 3
     },
     "health_status_time": "2018-12-11T21:58:45-08:00",
     "health_status_ttl": 0,
     "message": "one or more failures",
     "health_info": [],
     "health_success": [],
     "health_warn": [],
     "health_failure": {
         "free-space": {
             "stdout": [
                 "'\/tmp' has only 10% free disk space (20% is minimum required)"
             ]
         }
     }
    }

在现有项目中使用

  • 有关更多详细信息,请参阅PHP使用文档

  • 使用Composer将其添加到现有项目中。

    composer require katmore/healthsvc

单元测试

要执行单元测试,请在vendor/bin目录中执行phpunit。

vendor/bin/phpunit

提供tests.sh包装脚本以方便使用。

./tests.sh

法律

"Healthsvc"根据MIT许可证GPLv3许可证的条款进行分发。

版权(c)2018-2019,Doug Bird。保留所有权利。