1. Go to this page and download the library: Download prismamedia/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/ */
# src/Metrics/ArticleCountMetric.php
namespace App\Metrics;
use Doctrine\DBAL\Connection;
use PrismaMedia\Metrics\Metric;
use PrismaMedia\Metrics\MetricGenerator;
class ArticleCountMetric implements MetricGenerator
{
private $connection;
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
/**
* @return Metric[]
*/
public function getMetrics(): \Traversable
{
// SELECT a.status, COUNT(*) as total FROM article GROUP BY a.status
$qbd = $this->connection->createQueryBuilder();
$qbd->select('a.status, COUNT(*) as total')
->from('article', 'a')
->groupBy('a.status');
foreach ($qbd->execute()->fetchAll() as $row) {
// app_article_total{status=<status>} <total>
yield new Metric('app_article_total', (int) $row['total'], [
'status' => $row['status'],
]);
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.