building5 / apache-exporter
用于导出Apache状态到Prometheus的库
v1.0.0
2018-03-02 15:08 UTC
Requires
- php: >=7.1
- jimdo/prometheus_client_php: ^0.9.1
Requires (Dev)
- ext-apc: *
- phpunit/phpunit: ^6.5
- squizlabs/php_codesniffer: ^3.2
This package is not auto-updated.
Last update: 2024-09-29 06:06:19 UTC
README
PHP版本的apache_exporter。对于PHP应用来说,使用更方便,因为它不需要运行额外的导出进程。
安装
$ composer require building5/apache-exporter
使用方法
请确保Apache服务器状态页面已启用并配置。
使用 a2enmod status
命令启用状态模块。它可能在 /etc/apache2/mods-enabled
中已经有了一个配置好的 status.conf
文件,如果没有,你也需要创建它
<IfModule mod_status.c>
<Location /server-status>
SetHandler server-status
Require local
</Location>
ExtendedStatus On
<IfModule mod_proxy.c>
# Show Proxy LoadBalancer status in mod_status
ProxyStatus On
</IfModule>
</IfModule>
你可以在Web服务器上运行 curl https:///server-status?auto
来测试状态页面是否正常服务。
简单使用
在你的PHP应用程序中,或在你选择的任何webroot中,创建一个名为 metrics.php
的脚本,该脚本调用 ApacheExporter\Exporter::simple()
。关于使用 .htaccess
来限制访问、添加密码等,请作为练习完成。
<?php ApacheExporter\Exporter::simple();
非简单使用
如果你有其他想要报告的统计信息,你可以使用 ApacheExporter\Exporter::export()
方法将统计信息导出到你选择的注册表中。
不推荐使用APC或Redis存储。如果你这样做,计数器字段如访问次数、千字节和运行时间将会无限制地累积。
<?php use ApacheExporter\Exporter; use Prometheus\CollectorRegistry; use Prometheus\RenderTextFormat; use Prometheus\Storage\InMemory; $registry = new CollectorRegistry(new InMemory()); $renderer = new RenderTextFormat(); Exporter::export($registry); // register other stats you want here header('Content-type: ' . RenderTextFormat::MIME_TYPE); echo $renderer->render($registry->getMetricFamilySamples());
许可协议
apache-exporter-php
采用MIT许可协议。