triadev/laravel-prometheus-exporter
Composer 安装命令:
composer require triadev/laravel-prometheus-exporter
包简介
A laravel and lumen service provider to export metrics for prometheus.
关键字:
README 文档
README
A laravel and lumen service provider to export metrics for prometheus.
Supported laravel versions
Supported lumen versions
Main features
- Metrics with APC
- Metrics with Redis
- Metrics with InMemory
- Metrics with the push gateway
- Request per route middleware (total and duration metrics)
Installation
Composer
composer require triadev/laravel-prometheus-exporter
Application
The package is registered through the package discovery of laravel and Composer.
Once installed you can now publish your config file and set your correct configuration for using the package.
php artisan vendor:publish --provider="Triadev\PrometheusExporter\Provider\PrometheusExporterServiceProvider" --tag="config"
This will create a file config/prometheus-exporter.php.
Configuration
| Key | Env | Value | Description | Default |
|---|---|---|---|---|
| adapter | PROMETHEUS_ADAPTER | STRING | apc, redis, inmemory or push | apc |
| namespace | --- | STRING | default: app | app |
| namespace_http | --- | STRING | namespace for "RequestPerRoute-Middleware metrics" | http |
| redis.host | PROMETHEUS_REDIS_HOST, REDIS_HOST | STRING | redis host | 127.0.0.1 |
| redis.port | PROMETHEUS_REDIS_PORT, REDIS_PORT | INTEGER | redis port | 6379 |
| redis.password | PROMETHEUS_REDIS_PASSWORD, REDIS_PASSWORD | STRING | redis password | null |
| redis.timeout | --- | FLOAT | redis timeout | 0.1 |
| redis.read_timeout | --- | INTEGER | redis read timeout | 10 |
| push_gateway.address | PROMETHEUS_PUSH_GATEWAY_ADDRESS | STRING | push gateway address | localhost:9091 |
| buckets_per_route | --- | STRING | histogram buckets for "RequestPerRoute-Middleware" | --- |
buckets_per_route
'buckets_per_route' => [
ROUTE-NAME => [10,20,50,100,200],
...
]
Usage
Get metrics
Laravel
When you are using laravel you can use the default http endpoint:
triadev/pe/metrics
Of course you can also register your own route. Here is an example:
Route::get(
ROUTE,
\Triadev\PrometheusExporter\Controller\LaravelController::class . '@metrics'
);
Lumen
When you are using lumen you must register the route on your own. Here is an example:
Route::get(
ROUTE,
\Triadev\PrometheusExporter\Controller\LumenController::class . '@metrics'
);
Middleware
RequestPerRoute
A middleware to build metrics for "request_total" and "requests_latency_milliseconds" per route.
Alias
lpe.requestPerRoute
Metrics
- requests_total (inc)
- requests_latency_milliseconds (histogram)
Example
$router->get('/test/route', function () { return 'valid'; })->middleware('lpe.requestPerRoute');
app_requests_latency_milliseconds_bucket{route="/test/route",method="GET",status_code="200",le="0.005"} 0 ... app_requests_latency_milliseconds_count{route="/test/route",method="GET",status_code="200"} 1 app_requests_latency_milliseconds_sum{route="/test/route",method="GET",status_code="200"} 6 app_requests_total{route="/test/route",method="GET",status_code="200"} 1
Roadmap
- histogram buckets per route (RequestPerRoute)
Reporting Issues
If you do find an issue, please feel free to report it with GitHub's bug tracker for this project.
Alternatively, fork the project and make a pull request. :)
Testing
- docker-compose up
- docker exec fpm ./vendor/phpunit/phpunit/phpunit
Contributing
Please see CONTRIBUTING for details.
Credits
Other
Project related links
Author
License
The code for LaravelPrometheusExporter is distributed under the terms of the MIT license (see LICENSE).
triadev/laravel-prometheus-exporter 适用场景与选型建议
triadev/laravel-prometheus-exporter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28.69k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2017 年 07 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Metrics」 「laravel」 「prometheus」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 triadev/laravel-prometheus-exporter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 triadev/laravel-prometheus-exporter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 triadev/laravel-prometheus-exporter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Metrics endpoint for Laravel applications
A Prometheus exporter for Laravel and Lumen
A abstraction for generating metrics in Laravel.
Laravel SDK for working with prometheus metrics
Production-ready Laravel Prometheus metrics package with built-in collectors for HTTP, database, cache, queue, events, errors, filesystem, and mail monitoring
Tool to show code coverage metrics, measured by PHP Unit in Cobertura format, in console and CI/CD pipeline
统计信息
- 总下载量: 28.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-28