42 lines
882 B
PHP
42 lines
882 B
PHP
<?php
|
|
|
|
namespace App\EventListener;
|
|
|
|
use App\Api\InfluxDB;
|
|
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
|
use InfluxDB2\WriteType;
|
|
use InfluxDB2\Point;
|
|
|
|
/**
|
|
* class StatListener.
|
|
*
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
*/
|
|
class StatListener
|
|
{
|
|
public function __construct(protected InfluxDB $influxDB)
|
|
{
|
|
}
|
|
|
|
public function onKernelRequest(RequestEvent $event)
|
|
{
|
|
if (!$this->influxDB->isAvailable()) {
|
|
return;
|
|
}
|
|
|
|
$client = $this->influxDB->getClient();
|
|
|
|
$writeApi = $client->createWriteApi(['writeType' => WriteType::SYNCHRONOUS]);
|
|
$pageView = new Point('page_view');
|
|
$pageView
|
|
->addTag('request', 'view')
|
|
->addField('value', 1)
|
|
->time(time())
|
|
;
|
|
|
|
$writeApi->write($pageView);
|
|
$writeApi->close();
|
|
$client->close();
|
|
}
|
|
}
|