1
0
Fork 0
mirror of synced 2024-06-02 10:54:44 +12:00

Removed request and bandwidth when no time series db is available

This commit is contained in:
eldadfux 2019-07-29 20:37:25 +03:00
parent 08368133a9
commit 9635c1581b
7 changed files with 68 additions and 54 deletions

View file

@ -444,7 +444,7 @@ $utopia->post('/v1/database/:collectionId')
throw new Exception('Bad structure. ' . $exception->getMessage(), 400);
}
catch (\Exception $exception) {
throw new Exception('Failed saving document to DB', 500);
throw new Exception('Failed saving document to DB' . $exception->getMessage(), 500);
}
$data = $data->getArrayCopy();

View file

@ -119,39 +119,42 @@ $utopia->get('/v1/projects/:projectId/usage')
throw new Exception('Project not found', 404);
}
/*$client = new InfluxDB\Client('influxdb', '8086');
$start = DateTime::createFromFormat('U', strtotime('first day of this month'));
$start = $start->format(DateTime::RFC3339);
$end = DateTime::createFromFormat('U', strtotime('last day of this month'));
$end = $end->format(DateTime::RFC3339);
$database = $client->selectDB('telegraf');
$client = $register->get('influxdb');
// Requests
if($client) {
$start = DateTime::createFromFormat('U', strtotime('first day of this month'));
$start = $start->format(DateTime::RFC3339);
$end = DateTime::createFromFormat('U', strtotime('last day of this month'));
$end = $end->format(DateTime::RFC3339);
$database = $client->selectDB('telegraf');
$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->getUid() . '\' GROUP BY time(1d) FILL(null)');
$points = $result->getPoints();
$requests = [];
// Requests
foreach ($points as $point) {
$requests[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => strtotime($point['time']),
];
$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->getUid() . '\' GROUP BY time(1d) FILL(null)');
$points = $result->getPoints();
$requests = [];
foreach ($points as $point) {
$requests[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => strtotime($point['time']),
];
}
// 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->getUid() . '\' GROUP BY time(1d) FILL(null)');
$points = $result->getPoints();
$network = [];
foreach ($points as $point) {
$network[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => strtotime($point['time']),
];
}
}
// 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->getUid() . '\' GROUP BY time(1d) FILL(null)');
$points = $result->getPoints();
$network = [];
foreach ($points as $point) {
$network[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => strtotime($point['time']),
];
}
*/
// Users
$projectDB->getCollection([

View file

@ -84,8 +84,12 @@ $register->set('db', function() use ($request) { // Register DB connection
return $pdo;
});
$register->set('influxdb', function() use ($request) { // Register DB connection
$host = $request->getServer('_APP_INFLUXDB_HOST', 'influxdb');
$port = $request->getServer('_APP_INFLUXDB_PORT', 8086);
$host = $request->getServer('_APP_INFLUXDB_HOST', '');
$port = $request->getServer('_APP_INFLUXDB_PORT', '');
if(empty($host) || empty($port)) {
return null;
}
$client = new InfluxDB\Client($host, $port, '', '', false, false, 5);

View file

@ -1,3 +1,7 @@
<?php
$graph = $this->getParam('graph', false);
?>
<div class="cover margin-bottom-small">
<div class="zone xl margin-bottom-large margin-top-small">
<h1 class="margin-bottom-small">
@ -23,29 +27,32 @@
data-success="render,trigger"
data-error="render"
data-success-triggers="usage.load">
<div class="row responsive">
<div class="col span-9">
<div class="pull-start margin-end">
<div class="value margin-bottom-small"><span class="sum" data-ls-bind="{{usage.requests.total|statsTotal}}">N/A</span></div>
<div class="metric margin-bottom-small">Requests <span class="tooltip" data-tooltip="Total number of API requests this month"><i class="icon-info-circled"></i></span></div>
<?php if($graph): ?>
<div class="row responsive">
<div class="col span-9">
<div class="pull-start margin-end">
<div class="value margin-bottom-small"><span class="sum" data-ls-bind="{{usage.requests.total|statsTotal}}">N/A</span></div>
<div class="metric margin-bottom-small">Requests <span class="tooltip" data-tooltip="Total number of API requests this month"><i class="icon-info-circled"></i></span></div>
<div class="range">Current Month</div>
</div>
<div class="chart">
<div class="content" data-ls-ui-chart></div>
</div>
</div>
<div class="col span-3">
<div class="value margin-bottom-small"><span class="sum" data-ls-bind="{{usage.network.total|humanFileSize}}" data-default="0">0</span></div>
<div class="metric margin-bottom-small">Bandwidth</div>
<div class="range">Current Month</div>
</div>
<div class="chart">
<div class="content" data-ls-ui-chart></div>
<div class="margin-top dev-feature">
<a href="">Full Usage Report <i class="icon-right-open"></i></a>
</div>
</div>
</div>
<div class="col span-3">
<div class="value margin-bottom-small"><span class="sum" data-ls-bind="{{usage.network.total|humanFileSize}}" data-default="0">0</span></div>
<div class="metric margin-bottom-small">Bandwidth</div>
<div class="range">Current Month</div>
<div class="margin-top dev-feature">
<a href="">Full Usage Report <i class="icon-right-open"></i></a>
</div>
</div>
</div>
<hr />
<hr />
<?php endif; ?>
<div>

View file

@ -21,8 +21,8 @@ services:
- _APP_DB_SCHEMA=appwrite
- _APP_DB_USER=root
- _APP_DB_PASS=password
- _APP_INFLUXDB_HOST=influxdb
- _APP_INFLUXDB_PORT=8086
# - _APP_INFLUXDB_HOST=influxdb
# - _APP_INFLUXDB_PORT=8086
- _APP_NEWRELIC_KEY=
- _APP_MAILGUN_KEY=
- _APP_MAILGUN_DOMAIN=

File diff suppressed because one or more lines are too long

View file

@ -368,7 +368,7 @@
.dashboard {
padding: 20px;
min-height: 115px;
min-height: 95px;
overflow: hidden;
position: relative;
z-index: 1;