1. Go to this page and download the library: Download javer/influxdb-admin-bundle 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/ */
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
class CpuLoadAdmin extends AbstractAdmin
{
protected function generateBaseRouteName(bool $isChildAdmin = false): string
{
return 'cpu_load';
}
protected function generateBaseRoutePattern(bool $isChildAdmin = false): string
{
return 'cpu_load';
}
protected function configureListFields(ListMapper $list): void
{
// ...
}
protected function configureDatagridFilters(DatagridMapper $filter): void
{
// ...
}
protected function configureShowFields(ShowMapper $show): void
{
// ...
}
protected function configureFormFields(FormMapper $form): void
{
// ...
}
}
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface;
class CpuLoadAdmin extends AbstractAdmin
{
protected function configureListFields(ListMapper $list): void
{
$list
->addIdentifier('time', FieldDescriptionInterface::TYPE_DATETIME, [
'format' => 'Y-m-d H:i:s.u',
])
->add('serverId')
->add('load')
->add(ListMapper::NAME_ACTIONS, ListMapper::TYPE_ACTIONS, [
'actions' => [
'show' => [],
'edit' => [],
'delete' => [],
],
]);
}
}
namespace App\Admin;
use Javer\InfluxDB\AdminBundle\Filter\DateTimeRangeFilter;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
class CpuLoadAdmin extends AbstractAdmin
{
protected function configureDatagridFilters(DatagridMapper $filter): void
{
$filter
->add('time', DateTimeRangeFilter::class)
->add('serverId');
}
}
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
class CpuLoadAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $form): void
{
$form
->add('serverId')
->add('load');
}
}
use Javer\InfluxDB\AdminBundle\Datagrid\ProxyQuery;
$query = $this->measurementManager->createQuery();
$proxyQuery = new ProxyQuery($query);
$proxyQuery->setSortBy('time');
$proxyQuery->setMaxResults(10);
$results = $proxyQuery->execute();