I've created a PR for influxdb-php library introducing ability to write to TCP sockets, for example telegraf's ones - which allows me to write to a local socket instead of directly writing measurements to influxdb. (influxdata/influxdb-php#124)
I'm using a custom version of InfluxDBStorage class (monitoring) because the one from enqueue/monitoring always does try to create a database...
|
private function getDb(): Database |
|
{ |
|
if (null === $this->database) { |
|
if (null === $this->client) { |
|
$this->client = new Client( |
|
$this->config['host'], |
|
$this->config['port'], |
|
$this->config['user'], |
|
$this->config['password'] |
|
); |
|
} |
|
|
|
$this->database = $this->client->selectDB($this->config['db']); |
|
$this->database->create(); |
|
} |
|
|
|
return $this->database; |
|
} |
...which won't work in above case, because that socket is unable to handle database queries. I'm passing a custom client directly (as constructor
$config variable)...
|
public function __construct($config = 'influxdb:') |
|
{ |
|
if (false == class_exists(Client::class)) { |
|
throw new \LogicException('Seems client library is not installed. Please install "influxdb/influxdb-php"'); |
|
} |
|
|
|
if (empty($config)) { |
|
$config = []; |
|
} elseif (is_string($config)) { |
|
$config = $this->parseDsn($config); |
|
} elseif (is_array($config)) { |
|
$config = empty($config['dsn']) ? $config : $this->parseDsn($config['dsn']); |
|
} elseif ($config instanceof Client) { |
|
$this->client = $config; |
|
$config = []; |
|
} else { |
|
throw new \LogicException('The config must be either an array of options, a DSN string or null'); |
|
} |
|
|
|
$config = array_replace([ |
|
'host' => '127.0.0.1', |
|
'port' => '8086', |
|
'user' => '', |
|
'password' => '', |
|
'db' => 'enqueue', |
|
'measurementSentMessages' => 'sent-messages', |
|
'measurementConsumedMessages' => 'consumed-messages', |
|
'measurementConsumers' => 'consumers', |
|
], $config); |
|
|
|
$this->config = $config; |
|
} |
... but it appears that there is no way to pass configuration for measurements writing (since you can either pass a Client instance or config string/array).
I believe there should be a setter for configuration for this case? WDYT? Should using Client or Database instance be configurable as well / instead?
EDIT: For writing I'm replacing
|
$this->getDb()->writePoints($points, Database::PRECISION_MILLISECONDS); |
with
$this->client->write([], $points);
since the currently used in php-enqueue code will call Database's
https://github.com/influxdata/influxdb-php/blob/4a1efb43656a4f2b390201865cfe7051c895dff7/src/InfluxDB/Database.php#L162-L179
eventually anyway with passed Points as payload.
I've created a PR for influxdb-php library introducing ability to write to TCP sockets, for example telegraf's ones - which allows me to write to a local socket instead of directly writing measurements to influxdb. (influxdata/influxdb-php#124)
I'm using a custom version of InfluxDBStorage class (monitoring) because the one from enqueue/monitoring always does try to create a database...
enqueue-dev/pkg/monitoring/InfluxDbStorage.php
Lines 164 to 181 in 0652c5c
...which won't work in above case, because that socket is unable to handle database queries. I'm passing a custom client directly (as constructor
$configvariable)...enqueue-dev/pkg/monitoring/InfluxDbStorage.php
Lines 49 to 80 in 0652c5c
... but it appears that there is no way to pass configuration for measurements writing (since you can either pass a Client instance or config string/array).
I believe there should be a setter for configuration for this case? WDYT? Should using
ClientorDatabaseinstance be configurable as well / instead?EDIT: For writing I'm replacing
enqueue-dev/pkg/monitoring/InfluxDbStorage.php
Line 112 in 0652c5c
with
since the currently used in php-enqueue code will call
Database'shttps://github.com/influxdata/influxdb-php/blob/4a1efb43656a4f2b390201865cfe7051c895dff7/src/InfluxDB/Database.php#L162-L179
eventually anyway with passed
Pointsas payload.