Merge pull request #2874 from uxen-ab/bugs-in-the-average-metrics-graph
Bugs in the average metrics graph
This commit is contained in:
@@ -60,7 +60,7 @@ class MetricRepository
|
||||
public function listPointsLastHour(Metric $metric)
|
||||
{
|
||||
$dateTime = $this->dates->make();
|
||||
$pointKey = $dateTime->format('H:i');
|
||||
$pointKey = $dateTime->format('Y-m-d H:i');
|
||||
$points = $this->repository->getPointsSinceMinutes($metric, 60)->pluck('value', 'key')->take(60);
|
||||
|
||||
for ($i = 0; $i <= 60; $i++) {
|
||||
@@ -68,7 +68,7 @@ class MetricRepository
|
||||
$points->put($pointKey, $metric->default_value);
|
||||
}
|
||||
|
||||
$pointKey = $dateTime->sub(new DateInterval('PT1M'))->format('H:i');
|
||||
$pointKey = $dateTime->sub(new DateInterval('PT1M'))->format('Y-m-d H:i');
|
||||
}
|
||||
|
||||
return $points->sortBy(function ($point, $key) {
|
||||
@@ -87,7 +87,7 @@ class MetricRepository
|
||||
public function listPointsToday(Metric $metric, $hours = 12)
|
||||
{
|
||||
$dateTime = $this->dates->make();
|
||||
$pointKey = $dateTime->format('H:00');
|
||||
$pointKey = $dateTime->format('Y-m-d H:00');
|
||||
$points = $this->repository->getPointsSinceHour($metric, $hours)->pluck('value', 'key');
|
||||
|
||||
for ($i = 0; $i <= $hours; $i++) {
|
||||
@@ -95,9 +95,9 @@ class MetricRepository
|
||||
$points->put($pointKey, $metric->default_value);
|
||||
}
|
||||
|
||||
$pointKey = $dateTime->sub(new DateInterval('PT1H'))->format('H:00');
|
||||
}
|
||||
$pointKey = $dateTime->sub(new DateInterval('PT1H'))->format('Y-m-d H:00');
|
||||
|
||||
}
|
||||
return $points->sortBy(function ($point, $key) {
|
||||
return $key;
|
||||
});
|
||||
|
||||
@@ -32,7 +32,13 @@ class MySqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceMinutes(Metric $metric, $minutes)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%H:%i') AS `key`, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.`created_at` >= DATE_SUB(NOW(), INTERVAL :minutes MINUTE) GROUP BY HOUR({$this->getMetricPointsTable()}.`created_at`), MINUTE({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%Y-%m-%d %H:%i') AS `key`, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` >= DATE_SUB(NOW(), INTERVAL :minutes MINUTE) " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= NOW() " .
|
||||
"GROUP BY HOUR({$this->getMetricPointsTable()}.`created_at`), MINUTE({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
'minutes' => $minutes,
|
||||
]);
|
||||
@@ -51,7 +57,13 @@ class MySqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceHour(Metric $metric, $hour)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%H:00') AS `key`, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.`created_at` >= DATE_SUB(NOW(), INTERVAL :hour HOUR) GROUP BY HOUR({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%Y-%m-%d %H:00') AS `key`, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` >= DATE_SUB(NOW(), INTERVAL :hour HOUR) " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= NOW() " .
|
||||
"GROUP BY HOUR({$this->getMetricPointsTable()}.`created_at`) " .
|
||||
"ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
'hour' => $hour,
|
||||
]);
|
||||
@@ -70,7 +82,12 @@ class MySqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceDay(Metric $metric, $day)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%Y-%m-%d') AS `key`, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.`created_at` >= DATE_SUB(NOW(), INTERVAL :day DAY) GROUP BY DATE({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
$points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%Y-%m-%d') AS `key`, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` >= DATE_SUB(NOW(), INTERVAL :day DAY) " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= NOW() " .
|
||||
"GROUP BY DATE({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
'day' => $day,
|
||||
]);
|
||||
|
||||
@@ -33,7 +33,13 @@ class PgSqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceMinutes(Metric $metric, $minutes)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI') AS key, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.created_at >= (NOW() - INTERVAL '{$minutes}' MINUTE) GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI') ORDER BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI')", [
|
||||
$points = DB::select("SELECT to_char({$this->getMetricPointsTable()}.created_at, 'YYYY-MM-DD HH24:MI') AS key, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.created_at >= (NOW() - INTERVAL '{$minutes}' MINUTE) " .
|
||||
"AND {$this->getMetricPointsTable()}.created_at <= NOW() " .
|
||||
"GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI') " .
|
||||
"ORDER BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI')", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
@@ -51,7 +57,13 @@ class PgSqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceHour(Metric $metric, $hour)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00') AS key, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.created_at >= (NOW() - INTERVAL '{$hour}' HOUR) GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00') ORDER BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00')", [
|
||||
$points = DB::select("SELECT to_char({$this->getMetricPointsTable()}.created_at, 'YYYY-MM-DD HH24:00') AS key, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.created_at >= (NOW() - INTERVAL '{$hour}' HOUR) " .
|
||||
"AND {$this->getMetricPointsTable()}.created_at <= NOW() " .
|
||||
"GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00') " .
|
||||
"ORDER BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00')", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
@@ -69,7 +81,13 @@ class PgSqlRepository extends AbstractMetricRepository implements MetricInterfac
|
||||
public function getPointsSinceDay(Metric $metric, $day)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT DATE({$this->getMetricPointsTable()}.created_at) AS key, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.created_at >= (DATE(NOW()) - INTERVAL '{$day}' DAY) GROUP BY DATE({$this->getMetricPointsTable()}.created_at) ORDER BY DATE({$this->getMetricPointsTable()}.created_at)", [
|
||||
$points = DB::select("SELECT DATE({$this->getMetricPointsTable()}.created_at) AS key, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.created_at >= (DATE(NOW()) - INTERVAL '{$day}' DAY) " .
|
||||
"AND {$this->getMetricPointsTable()}.created_at <= DATE(NOW()) " .
|
||||
"GROUP BY DATE({$this->getMetricPointsTable()}.created_at) " .
|
||||
"ORDER BY DATE({$this->getMetricPointsTable()}.created_at)", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
|
||||
@@ -33,7 +33,14 @@ class SqliteRepository extends AbstractMetricRepository implements MetricInterfa
|
||||
public function getPointsSinceMinutes(Metric $metric, $minutes)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT strftime('%H:%M', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$minutes} minutes') GROUP BY strftime('%H', {$this->getMetricPointsTable()}.`created_at`), strftime('%M', {$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
$points = DB::select("SELECT strftime('%Y-%m-%d %H:%M', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} " .
|
||||
"INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$minutes} minutes') " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now') " .
|
||||
"GROUP BY strftime('%H', {$this->getMetricPointsTable()}.`created_at`), strftime('%M', {$this->getMetricPointsTable()}.`created_at`) " .
|
||||
"ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
@@ -51,7 +58,12 @@ class SqliteRepository extends AbstractMetricRepository implements MetricInterfa
|
||||
public function getPointsSinceHour(Metric $metric, $hour)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT strftime('%H:00', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$hour} hours') GROUP BY strftime('%H', {$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
$points = DB::select("SELECT strftime('%Y-%m-%d %H:00', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$hour} hours') " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now') " .
|
||||
"GROUP BY strftime('%H', {$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
@@ -69,7 +81,13 @@ class SqliteRepository extends AbstractMetricRepository implements MetricInterfa
|
||||
public function getPointsSinceDay(Metric $metric, $day)
|
||||
{
|
||||
$queryType = $this->getQueryType($metric);
|
||||
$points = DB::select("SELECT strftime('%Y-%m-%d', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id WHERE {$this->getMetricsTable()}.id = :metricId AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$day} days') GROUP BY DATE({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
$points = DB::select("SELECT strftime('%Y-%m-%d', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} " .
|
||||
"FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id " .
|
||||
"WHERE {$this->getMetricsTable()}.id = :metricId " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$day} days') " .
|
||||
"AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now') " .
|
||||
"GROUP BY DATE({$this->getMetricPointsTable()}.`created_at`) " .
|
||||
"ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
|
||||
'metricId' => $metric->id,
|
||||
]);
|
||||
|
||||
|
||||
36
public/dist/js/all.js
vendored
36
public/dist/js/all.js
vendored
File diff suppressed because one or more lines are too long
2
public/dist/js/app.js
vendored
2
public/dist/js/app.js
vendored
File diff suppressed because one or more lines are too long
@@ -116,11 +116,25 @@ module.exports = {
|
||||
if (this.chart !== null) {
|
||||
this.chart.destroy()
|
||||
}
|
||||
|
||||
//Used in tooltip callback where this.metric is not the same.
|
||||
var metric = this.metric;
|
||||
/*
|
||||
* Datetimes are used as keys instead of just time in order to
|
||||
* improve ordering of labels in "Last 12 hours", so we cut the
|
||||
* labels.
|
||||
* This cutting is done only if there is an hour in the string, so
|
||||
* if the view by day is set it doesn't fail.
|
||||
*/
|
||||
var data_keys = _.keys(this.data);
|
||||
if (0 < data_keys.length && data_keys[0].length > 10) {
|
||||
for (var i = 0; i < data_keys.length; i++) {
|
||||
data_keys[i] = data_keys[i].substr(11);
|
||||
}
|
||||
}
|
||||
this.chart = new Chart(this.context, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: _.keys(this.data),
|
||||
labels: data_keys,
|
||||
datasets: [{
|
||||
data: _.values(this.data),
|
||||
// backgroundColor: "{{ $theme_metrics }}",
|
||||
@@ -164,15 +178,14 @@ module.exports = {
|
||||
}
|
||||
}]
|
||||
},
|
||||
},
|
||||
tooltips: {
|
||||
callbacks: {
|
||||
label: function(tooltipItem, data) {
|
||||
return tooltipItem.yLabel + ' ' + result.data.metric.suffix
|
||||
tooltips: {
|
||||
callbacks: {
|
||||
label: function(tooltipItem, data) {
|
||||
return tooltipItem.yLabel + ' ' + metric.suffix;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user