1. Go to this page and download the library: Download javer/influxdb-odm 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/ */
use Doctrine\Common\Annotations\AnnotationReader;
use Javer\InfluxDB\ODM\Connection\ConnectionFactory;
use Javer\InfluxDB\ODM\Mapping\Driver\AnnotationDriver;
use Javer\InfluxDB\ODM\MeasurementManager;
use Javer\InfluxDB\ODM\Repository\RepositoryFactory;
$dsn = 'influxdb://localhost:8086/metrics';
$mappingDir = 'src/Measurements';
$mappingDriver = new AnnotationDriver(new AnnotationReader(), $mappingDir);
$connectionFactory = new ConnectionFactory();
$repositoryFactory = new RepositoryFactory();
$measurementManager = new MeasurementManager($mappingDriver, $connectionFactory, $repositoryFactory, $dsn);
use Javer\InfluxDB\ODM\Connection\ConnectionFactory;
use Javer\InfluxDB\ODM\Mapping\Driver\AttributeDriver;
use Javer\InfluxDB\ODM\MeasurementManager;
use Javer\InfluxDB\ODM\Repository\RepositoryFactory;
$dsn = 'influxdb://localhost:8086/metrics';
$mappingDir = 'src/Measurements';
$mappingDriver = new AttributeDriver($mappingDir);
$connectionFactory = new ConnectionFactory();
$repositoryFactory = new RepositoryFactory();
$measurementManager = new MeasurementManager($mappingDriver, $connectionFactory, $repositoryFactory, $dsn);
use App\Measurement\CpuLoad;
use Javer\InfluxDB\ODM\MeasurementManager;
$cpuLoad = new CpuLoad();
$cpuLoad->setTime(new DateTime());
$cpuLoad->setServerId(42);
$cpuLoad->setCoreNumber(0);
$cpuLoad->setLoad(3.14);
/** @var MeasurementManager $measurementManager */
$measurementManager->persist($cpuLoad);
// query by the time
$cpuLoad = $repository->find($time);
// find *all* CPU metrics
$cpuLoads = $repository->findAll();
// find a group of CPU metrics for the particular server
$cpuLoads = $repository->findBy(['serverId' => 42]);
// query for one cpuLoad matching by serverId and coreNumber
$cpuLoad = $repository->findOneBy(['serverId' => 42, 'coreNumber' => 3]);
// query for all cpuLoads matching the serverId, ordered by time desc
$cpuLoads = $repository->findBy(
['serverId' => 42],
['time' => 'DESC']
);