Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[monitoring][influxdb] Do not attempt to create database / Allow TCP socket / custom Client #803

Closed
Steveb-p opened this issue Mar 18, 2019 · 0 comments

Comments

@Steveb-p
Copy link
Contributor

Steveb-p commented Mar 18, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant