net_bazzline/php_component_apache_server_status_parser

该软件包已被弃用,不再维护。没有建议的替代软件包。

PHP 组件,用于简化读取和处理 Apache 服务器状态(mod_status)

0.3.1 2017-11-02 14:25 UTC

This package is auto-updated.

Last update: 2021-07-01 00:13:47 UTC


README

我仍然喜欢这个想法,但目前没有再开发它的用例。

PHP Apache 服务器状态解析组件

本项目旨在提供一个易于使用的组件,用于读取配置主机列表的 Apache 服务器状态,并获取相关信息。

该组件依赖于 apache mod_status 和未文档化的查询 "?notable" ("?auto" 不包含 pid 信息)。

当前主分支的构建状态由 Travis CI 跟踪:Build Status Latest stable

scrutinizer 状态为: code quality

请查看 openhub.net

当前变更日志可在 此处 找到。

项目目标

  • 提供对进程信息(处理字符串)的简单访问
  • 提供对所有信息的详细访问(构建大量对象)

为什么?

让我给你一个我桌上的场景,我需要解决它。

给定

作为多个 Apache HTTP 服务器的维护者,我需要知道一个给定的进程(通过其 pid、一个基础设施范围内的唯一标识符及其 uri)是否仍在运行。有时我知道运行进程的服务器的 IP 地址,通常我只有 pid、唯一标识符和 uri。最后,允许使用 Apache 服务器状态,但不能执行 ssh 命令。

如何使用

由于与构建器一起发货,因此开始使用非常简单。如果您想使用应用程序实例池,请使用构建器作为手动将事物组合在一起的方法。

有两种不同类型的构建器,第一种(AbstractStorageBuilder)让您控制从哪里获取信息和获取多少信息。第二种(ParserBuilder)简单地将第一个的结果解析成域对象。

//If you want to parse the whole apache server status
//  and create domain objects out of the information.

//begin of dependencies
$parserBuilderFactory       = new \Net\Bazzline\Component\ApacheServerStatusParser\Service\Builder\ParserBuilderFactory();
$storageBuilder             = new \Net\Bazzline\Component\ApacheServerStatusParser\Service\Builder\RemoteStorageBuilder();

$parserBuilder  = $parserBuilderFactory->create();
//end of dependencies

//begin of business logic
//  the following five logical lines are doing the trick
$storageBuilder->setUrlToTheApacheStatusFileToParseUpfront('<the url to your apache server status>');
$storageBuilder->selectParseModeAllUpfront();

$storageBuilder->build();

$parserBuilder->setStorageUpfront(
    $storageBuilder->andGetStorageAfterTheBuild();
);
$parserBuilder->build();

//  and now, do something with the result
var_dump(
    $parserBuilder->andGetListOfDetailOrNullAfterwards()
);
var_dump(
    $parserBuilder->andGetInformationOrNullAfterwards()
);
var_dump(
    $parserBuilder->andGetScoreboardOrNullAfterwards()
);
var_dump(
    $parserBuilder->andGetStatisticOrNullAfterwards()
);
//end of business logic

示例

示例位于路径 /example。由于实现了两种内容获取器,它们被分为两个类别 "本地" 和 "远程"。

使用本地文件示例

cd <project root>/example/local

#if no file path is provided, the shipped with example file will be used
#parse all
php parse_all.php [<string: path to the apache status file to parse>]
#parse detail only
php parse_detail_only.php [<string: path to the apache status file to parse>]
#check if a request is still running
php check_if_a_request_is_still_running <int: pid> [<string: uri path> [<string: path to the example file>]]

使用远程文件示例

cd <project root>/example/remote

#if no file path is provided, the build in example url will be used
#parse all
php remote/parse_all.php [<string: url to the apache status page>]
#parse detail only
php parse_detail_only.php [<string: url to the apache status page>]

示例输出

解析详情

只有一个细节。

http_method: GET
ip_address: 198.76.54.42
pid: 22754
status: Ready
uri_authority: example.host.org:80
uri_path_with_query: /

解析信息

date_of_built: Oct 06 1983 20:44:43
identifier: first.example.host.org (via 123.45.67.89)
mode_of_mpm: prefork
version: Apache/2.4.10 (Debian)

解析分数板

process: _WWW_WWWWKW_....._.W..................................................................................................................................
legend
    0: "_" Waiting for Connection,
    1: "S" Starting up,
    2: "R" Reading Request,
    3: "W" Sending Reply,
    4: "K" Keepalive (read),
    5: "D" DNS Lookup,
    6: "C" Closing connection,
    7: "L" Logging,
    8: "G" Gracefully finishing,
    9: "I" Idle cleanup of worker,
    10: "." Open slot with no current process

解析统计

b_per_request: 1667
cpu_load: 584
cpu_usage: u959.08 s127.38 cu1.72 cs.95
current_timestamp: 1485804167
idle_workers: 4
kb_per_request: 57
parent_server_configuration_generation: 1
parent_server_mpm_generation: 1
requests_currently_being_processed: 10
requests_per_second: 283
restart_timestamp: 1485785532
server_load: 1.22 1.05 0.83
server_up_time: 5 hours 10 minutes 35 seconds
total_accesses: 5279
total_traffic: 29.6 MB

安装

手动

mkdir -p vendor/net_bazzline/php_component_apache_server_status_parser
cd vendor/net_bazzline/php_component_apache_server_status_parser
git clone https://github.com/bazzline/php_component_apache_server_status_parser .

使用 Packagist

composer require net_bazzline/php_component_apache_server_status_parser:dev-master

工作流程

  • 获取内容
  • 将内容拆分为专用部分
    • 详情
    • 信息
    • 分数板
    • 统计
  • 将每个部分解析成合适的域对象

域模型列表

  • DomainModel\Detail
    • 每个工作进程的动态详细信息
  • DomainModel\Information
    • 关于环境的通用静态信息
  • DomainModel\Scoreboard
    • 动态和通用的工作信息
  • DomainModel\Statistic
    • 动态服务器统计

服务列表

  • Service\Builder
    • 包含用于启动此组件使用的构建器类
  • Service\Content\Fetcher
    • 包含从某处获取Apache状态内容的类
  • Service\Content\Parser
    • 包含从内容创建域对象的类
  • Service\Content\Processor
    • 包含用于将内容拆分为逻辑部分的类(做大量工作)
  • Service\Content\Storage
    • 包含用于共享逻辑内容部分的类
  • Service\StateMachine
    • 包含一个简化将内容拆分为逻辑部分的类

注意

感谢

结语

如果喜欢,请给它点个赞 :-). 如有需要,请提交问题。如果喜欢,请拉取补丁。如果使用了,请写一篇博客。 捐赠一些东西 如果你真的喜欢 :-]。