javihgil / status-page-bundle
该软件包已被弃用,不再维护。没有推荐替代软件包。
在Redis中存储一些指标并为Symfony项目提供状态页面
v0.1.4
2017-12-05 10:54 UTC
Requires
- predis/predis: ^1.0.0
Suggests
- guzzlehttp/guzzle: If you use guzzlehttp to call external services, StatusPageBundle can store request stats
- snc/redis-bundle: Provices easy way to configure redis clients, and more useful related features
README
此软件包正在开发中,尚未稳定
状态页面软件包允许将一些指标存储在Redis服务器中,以提供状态页面。
配置
# app/config/config.yml
jhg_status_page:
predis_client_id: predis_service_id
metrics:
requests_per_minute:
type: request_count
period: minute
expire: "+24 hours"
condition: "not (request.getPathInfo() matches '/^\\\\/_status/i')"
response_count_404:
type: response_count
period: minute
expire: "next day"
condition: "response.getStatusCode() == 404"
response_time:
type: response_time
period: minute
expire: "+24 hours"
condition: "not (request.getPathInfo() matches '/^\\\\/_status/i')"
exception:
type: exception
period: minute
expire: "tomorrow"
requests_per_hour:
type: request_count
period: hour
expire: "next month"
api_requests_per_minute:
type: request_count
period: minute
expire: "+24 hours"
condition: "request.getPathInfo() matches '/^\\\\/api/i'"
# routing.yml
_status_page:
resource: "@JhgStatusPageBundle/Resources/config/routing.yml"
prefix: /status
自定义状态事件
例如,如果您想存储每个FOSUserBundle的成功注册,您可以实现此状态监听器
AppBundle/EventListener/LoginStatusListener.php
<?php
namespace AppBundle\EventListener;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\FOSUserEvents;
use Jhg\StatusPageBundle\Status\StatusCount;
use Jhg\StatusPageBundle\StatusListener\AbstractStatusListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class RegistrationStatusListener extends AbstractStatusListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
FOSUserEvents::REGISTRATION_SUCCESS => ['onUserRegister' => 1024],
];
}
public function onUserLogin(FormEvent $event)
{
$this->statusStack->registerStatus(new StatusCount($this->eventKey, $this->eventPeriod, $this->eventExpire));
}
}
app/config/config.yml
jhg_status_page:
predis_client_id: predis_service_id
metrics:
registration_success_count:
type: custom
class: AppBundle\StatusListener\RegistrationStatusListener
period: minute
expire: "+24 hours"