1
0
Fork 0
mirror of synced 2024-06-02 19:04:49 +12:00

fix: influx db client

This commit is contained in:
Torsten Dittmann 2021-04-27 15:39:40 +02:00
parent acbf643ff3
commit 5ddcdf1779
5 changed files with 45 additions and 63 deletions

View file

@ -193,6 +193,7 @@ App::get('/v1/functions/:functionId/usage')
],
];
/** @var InfluxDB2\Client */
$client = $register->get('influxdb');
$executions = [];
@ -202,13 +203,12 @@ App::get('/v1/functions/:functionId/usage')
if ($client) {
$start = $period[$range]['start']->format(DateTime::RFC3339);
$end = $period[$range]['end']->format(DateTime::RFC3339);
$database = $client->selectDB('telegraf');
$database = $client->createQueryApi();
// Executions
$result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_executions_all" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' AND "functionId"=\''.$function->getId().'\' GROUP BY time('.$period[$range]['group'].') FILL(null)');
$points = $result->getPoints();
foreach ($points as $point) {
foreach ($result as $point) {
$executions[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),
@ -217,9 +217,8 @@ App::get('/v1/functions/:functionId/usage')
// Failures
$result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_executions_all" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' AND "functionId"=\''.$function->getId().'\' AND "functionStatus"=\'failed\' GROUP BY time('.$period[$range]['group'].') FILL(null)');
$points = $result->getPoints();
foreach ($points as $point) {
foreach ($result as $point) {
$failures[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),
@ -228,9 +227,8 @@ App::get('/v1/functions/:functionId/usage')
// Compute
$result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_executions_time" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' AND "functionId"=\''.$function->getId().'\' GROUP BY time('.$period[$range]['group'].') FILL(null)');
$points = $result->getPoints();
foreach ($points as $point) {
foreach ($result as $point) {
$compute[] = [
'value' => round((!empty($point['value'])) ? $point['value'] / 1000 : 0, 2), // minutes
'date' => \strtotime($point['time']),

View file

@ -206,6 +206,7 @@ App::get('/v1/projects/:projectId/usage')
],
];
/** @var InfluxDB2\Client */
$client = $register->get('influxdb');
$requests = [];
@ -215,13 +216,12 @@ App::get('/v1/projects/:projectId/usage')
if ($client) {
$start = $period[$range]['start']->format(DateTime::RFC3339);
$end = $period[$range]['end']->format(DateTime::RFC3339);
$database = $client->selectDB('telegraf');
$database = $client->createQueryApi();
// Requests
$result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_requests_all" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' GROUP BY time('.$period[$range]['group'].') FILL(null)');
$points = $result->getPoints();
foreach ($points as $point) {
foreach ($result as $point) {
$requests[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),
@ -230,9 +230,8 @@ App::get('/v1/projects/:projectId/usage')
// Network
$result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_network_all" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' GROUP BY time('.$period[$range]['group'].') FILL(null)');
$points = $result->getPoints();
foreach ($points as $point) {
foreach ($result as $point) {
$network[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),
@ -241,9 +240,8 @@ App::get('/v1/projects/:projectId/usage')
// Functions
$result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_executions_all" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' GROUP BY time('.$period[$range]['group'].') FILL(null)');
$points = $result->getPoints();
foreach ($points as $point) {
foreach ($result as $point) {
$functions[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),

View file

@ -170,7 +170,13 @@ $register->set('influxdb', function () { // Register DB connection
return;
}
$client = new InfluxDB\Client($host, $port, '', '', false, false, 5);
$client = new InfluxDB2\Client([
'url' => "http://{$host}". $port ? ':' . $port : '',
'token' => '',
'bucket' => 'telegraf/autogen',
'org' => '',
'precision' => InfluxDB2\Model\WritePrecision::S
]);
return $client;
});

View file

@ -55,7 +55,7 @@
"resque/php-resque": "1.3.6",
"matomo/device-detector": "4.2.2",
"dragonmantank/cron-expression": "3.1.0",
"influxdb/influxdb-php": "1.15.2",
"influxdata/influxdb-client-php": "1.12.0",
"phpmailer/phpmailer": "6.4.0",
"chillerlan/php-qrcode": "4.3.0",
"adhocore/jwt": "1.1.2",

62
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "32ceddda707fb8f625f84eec08dc3871",
"content-hash": "c9d5c1577bc385cc6ec9c7b989709224",
"packages": [
{
"name": "adhocore/jwt",
@ -648,70 +648,50 @@
"time": "2021-04-26T09:17:50+00:00"
},
{
"name": "influxdb/influxdb-php",
"version": "1.15.2",
"name": "influxdata/influxdb-client-php",
"version": "1.12.0",
"source": {
"type": "git",
"url": "https://github.com/influxdata/influxdb-php.git",
"reference": "d6e59f4f04ab9107574fda69c2cbe36671253d03"
"url": "https://github.com/influxdata/influxdb-client-php.git",
"reference": "e04f802a4d9c52b5b497077673269e8463fdb6ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/influxdata/influxdb-php/zipball/d6e59f4f04ab9107574fda69c2cbe36671253d03",
"reference": "d6e59f4f04ab9107574fda69c2cbe36671253d03",
"url": "https://api.github.com/repos/influxdata/influxdb-client-php/zipball/e04f802a4d9c52b5b497077673269e8463fdb6ea",
"reference": "e04f802a4d9c52b5b497077673269e8463fdb6ea",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "^6.0|^7.0",
"php": "^5.5 || ^7.0 || ^8.0"
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^6.2|^7.0.1",
"php": ">=7.1"
},
"require-dev": {
"dms/phpunit-arraysubset-asserts": "^0.2.1",
"phpunit/phpunit": "^9.5"
},
"suggest": {
"ext-curl": "Curl extension, needed for Curl driver",
"stefanotorresi/influxdb-php-async": "An asyncronous client for InfluxDB, implemented via ReactPHP."
"phpunit/phpunit": "^7.4|^9.1",
"squizlabs/php_codesniffer": "~2.6"
},
"type": "library",
"autoload": {
"psr-4": {
"InfluxDB\\": "src/InfluxDB"
"InfluxDB2\\": "src/InfluxDB2"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Stephen Hoogendijk",
"email": "stephen@tca0.nl"
},
{
"name": "Daniel Martinez",
"email": "danimartcas@hotmail.com"
},
{
"name": "Gianluca Arbezzano",
"email": "gianarb92@gmail.com"
}
],
"description": "InfluxDB client library for PHP",
"description": "InfluxDB (v2+) Client Library for PHP",
"homepage": "https://www.github.com/influxdata/influxdb-client-php",
"keywords": [
"client",
"influxdata",
"influxdb",
"influxdb class",
"influxdb client",
"influxdb library",
"time series"
"influxdb"
],
"support": {
"issues": "https://github.com/influxdata/influxdb-php/issues",
"source": "https://github.com/influxdata/influxdb-php/tree/1.15.2"
"issues": "https://github.com/influxdata/influxdb-client-php/issues",
"source": "https://github.com/influxdata/influxdb-client-php/tree/1.12.0"
},
"time": "2020-12-26T17:45:17+00:00"
"time": "2021-04-01T06:28:57+00:00"
},
{
"name": "matomo/device-detector",