PHP code example of babymarkt / influxdb2-bundle
1. Go to this page and download the library: Download babymarkt/influxdb2-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/ */
babymarkt / influxdb2-bundle example snippets
// config/bundles.php
return [
// ...
Babymarkt\Symfony\Influxdb2Bundle\BabymarktInfluxdb2Bundle::class => ['all' => true],
];
namespace App;
class GenericMetricsWriter {
public function __construct(protected \InfluxDB2\Client $client) {
// ...
}
}
namespace App;
use Babymarkt\Symfony\Influxdb2Bundle\Registry\ClientRegistry;
class GenericMetricsWriter {
public function __construct(protected ClientRegistry $registry) {
/** @var \InfluxDB2\Client $client */
$client = $this->registry->getClient('your_client_name');
// ...
}
}
namespace App;
class GenericMetricsWriter {
// Injects the default Write- and Query-API.
public function __construct(
protected \InfluxDB2\WriteApi $writeApi,
protected \InfluxDB2\QueryApi $queryApi) {
// ...
}
}
namespace App;
use Babymarkt\Symfony\Influxdb2Bundle\Registry\ApiRegistry;
class GenericMetricsWriter {
public function __construct(protected ApiRegistry $registry) {
/** @var \InfluxDB2\WriteApi $writeAPi */
$writeAPi = $this->registry->getWriteApi('your_name');
/** @var \InfluxDB2\QueryApi $queryApi */
$queryApi = $this->registry->getQueryApi('your_name');
// ...
}
}
namespace App;
use InfluxDB2\Service\ReadyService;
class GenericMetricsWriter {
public function __construct(protected \InfluxDB2\Client $client) {
/** @var ReadyService $readyService */
$readyService = $this->client->createService(ReadyService::class);
$ready = $readyService->getReady();
echo $ready->getStatus(); // => "ready"
}
}