1
0
Fork 0
mirror of synced 2024-06-14 16:54:52 +12:00

Revert "fix: influx db client"

This reverts commit 5ddcdf1779.
This commit is contained in:
Torsten Dittmann 2021-04-27 15:51:35 +02:00
parent 5ddcdf1779
commit 4689d0b69f
5 changed files with 63 additions and 45 deletions

View file

@ -193,7 +193,6 @@ App::get('/v1/functions/:functionId/usage')
],
];
/** @var InfluxDB2\Client */
$client = $register->get('influxdb');
$executions = [];
@ -203,12 +202,13 @@ App::get('/v1/functions/:functionId/usage')
if ($client) {
$start = $period[$range]['start']->format(DateTime::RFC3339);
$end = $period[$range]['end']->format(DateTime::RFC3339);
$database = $client->createQueryApi();
$database = $client->selectDB('telegraf');
// 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)');
foreach ($result as $point) {
$points = $result->getPoints();
foreach ($points as $point) {
$executions[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),
@ -217,8 +217,9 @@ 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)');
foreach ($result as $point) {
$points = $result->getPoints();
foreach ($points as $point) {
$failures[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),
@ -227,8 +228,9 @@ 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)');
foreach ($result as $point) {
$points = $result->getPoints();
foreach ($points as $point) {
$compute[] = [
'value' => round((!empty($point['value'])) ? $point['value'] / 1000 : 0, 2), // minutes
'date' => \strtotime($point['time']),

View file

@ -206,7 +206,6 @@ App::get('/v1/projects/:projectId/usage')
],
];
/** @var InfluxDB2\Client */
$client = $register->get('influxdb');
$requests = [];
@ -216,12 +215,13 @@ App::get('/v1/projects/:projectId/usage')
if ($client) {
$start = $period[$range]['start']->format(DateTime::RFC3339);
$end = $period[$range]['end']->format(DateTime::RFC3339);
$database = $client->createQueryApi();
$database = $client->selectDB('telegraf');
// 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)');
foreach ($result as $point) {
$points = $result->getPoints();
foreach ($points as $point) {
$requests[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),
@ -230,8 +230,9 @@ 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)');
foreach ($result as $point) {
$points = $result->getPoints();
foreach ($points as $point) {
$network[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),
@ -240,8 +241,9 @@ 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)');
foreach ($result as $point) {
$points = $result->getPoints();
foreach ($points as $point) {
$functions[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),

View file

@ -170,13 +170,7 @@ $register->set('influxdb', function () { // Register DB connection
return;
}
$client = new InfluxDB2\Client([
'url' => "http://{$host}". $port ? ':' . $port : '',
'token' => '',
'bucket' => 'telegraf/autogen',
'org' => '',
'precision' => InfluxDB2\Model\WritePrecision::S
]);
$client = new InfluxDB\Client($host, $port, '', '', false, false, 5);
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",
"influxdata/influxdb-client-php": "1.12.0",
"influxdb/influxdb-php": "1.15.2",
"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": "c9d5c1577bc385cc6ec9c7b989709224",
"content-hash": "32ceddda707fb8f625f84eec08dc3871",
"packages": [
{
"name": "adhocore/jwt",
@ -648,50 +648,70 @@
"time": "2021-04-26T09:17:50+00:00"
},
{
"name": "influxdata/influxdb-client-php",
"version": "1.12.0",
"name": "influxdb/influxdb-php",
"version": "1.15.2",
"source": {
"type": "git",
"url": "https://github.com/influxdata/influxdb-client-php.git",
"reference": "e04f802a4d9c52b5b497077673269e8463fdb6ea"
"url": "https://github.com/influxdata/influxdb-php.git",
"reference": "d6e59f4f04ab9107574fda69c2cbe36671253d03"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/influxdata/influxdb-client-php/zipball/e04f802a4d9c52b5b497077673269e8463fdb6ea",
"reference": "e04f802a4d9c52b5b497077673269e8463fdb6ea",
"url": "https://api.github.com/repos/influxdata/influxdb-php/zipball/d6e59f4f04ab9107574fda69c2cbe36671253d03",
"reference": "d6e59f4f04ab9107574fda69c2cbe36671253d03",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^6.2|^7.0.1",
"php": ">=7.1"
"guzzlehttp/guzzle": "^6.0|^7.0",
"php": "^5.5 || ^7.0 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^7.4|^9.1",
"squizlabs/php_codesniffer": "~2.6"
"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."
},
"type": "library",
"autoload": {
"psr-4": {
"InfluxDB2\\": "src/InfluxDB2"
"InfluxDB\\": "src/InfluxDB"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "InfluxDB (v2+) Client Library for PHP",
"homepage": "https://www.github.com/influxdata/influxdb-client-php",
"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",
"keywords": [
"influxdb"
"client",
"influxdata",
"influxdb",
"influxdb class",
"influxdb client",
"influxdb library",
"time series"
],
"support": {
"issues": "https://github.com/influxdata/influxdb-client-php/issues",
"source": "https://github.com/influxdata/influxdb-client-php/tree/1.12.0"
"issues": "https://github.com/influxdata/influxdb-php/issues",
"source": "https://github.com/influxdata/influxdb-php/tree/1.15.2"
},
"time": "2021-04-01T06:28:57+00:00"
"time": "2020-12-26T17:45:17+00:00"
},
{
"name": "matomo/device-detector",