1. Go to this page and download the library: Download alexpon92/php2elk-metrics library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
/**
* Unique metric name
* @return string
*/
abstract public static function getName(): string;
/**
* Method to convert metric contents to array
*
* @return array
*/
abstract public function arraySerialize(): array;
namespace App\Metrics;
use Php2ElkMetrics\Metrics\BaseMetric;
use DateTime;
class SomeVisitDurationMetric extends BaseMetric
{
/**
* @var string
*/
private $userName;
/**
* @var float
*/
private $duration;
/**
* SomeVisitDurationMetric constructor.
*
* @param string $userName
* @param float $duration
* @param DateTime|null $time
*/
public function __construct(string $userName, float $duration, ?DateTime $time)
{
$this->userName = $userName;
$this->duration = $duration;
$this->time = $time; // time is protected field from BaseMetric class
}
public static function getName(): string
{
return 'some_duration_metric';
}
public function arraySerialize(): array
{
return [
'user_name' => $this->userName,
'duration' => $this->duration
];
}
}