From cee74a63e663c04dc70e86e9044aa0a63029fd7f Mon Sep 17 00:00:00 2001 From: Bert Date: Fri, 13 Mar 2020 14:55:49 +0100 Subject: [PATCH 1/4] add metrics options and dark mode config --- config/horizon.php | 32 +++++++++++++++++++++ resources/js/components/LineChart.vue | 2 +- resources/js/screens/metrics/preview.vue | 11 +++---- src/Horizon.php | 10 +++++-- src/Repositories/RedisMetricsRepository.php | 4 +-- 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/config/horizon.php b/config/horizon.php index ee5ae3a1..06a24e36 100644 --- a/config/horizon.php +++ b/config/horizon.php @@ -101,6 +101,38 @@ 'monitored' => 10080, ], + /* + |-------------------------------------------------------------------------- + | Metrics + |-------------------------------------------------------------------------- + | + | Here you can configure how many snapshots should be kept to display in + | the metrics graph. You should use this in conjunction with the + | `horizon:snapshot` schedule to define how long of a timespan + | you want to see in the metrics. + | + */ + + 'metrics' => [ + 'trim_snapshots' => [ + 'job' => 24, + 'queue' => 24, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Theme + |-------------------------------------------------------------------------- + | + | Here you can define which theme Horizon should load. + | + | Supported: "light", "dark" + | + */ + + 'theme' => 'light', + /* |-------------------------------------------------------------------------- | Fast Termination diff --git a/resources/js/components/LineChart.vue b/resources/js/components/LineChart.vue index 281c4f88..53721ca0 100644 --- a/resources/js/components/LineChart.vue +++ b/resources/js/components/LineChart.vue @@ -62,6 +62,6 @@ diff --git a/resources/js/screens/metrics/preview.vue b/resources/js/screens/metrics/preview.vue index e7c78cf6..17cb0c06 100644 --- a/resources/js/screens/metrics/preview.vue +++ b/resources/js/screens/metrics/preview.vue @@ -57,7 +57,7 @@ prepareData(data) { return _.chain(data) .map(value => { - value.time = this.formatDate(value.time).format("hh:mmA"); + value.time = this.formatDate(value.time).format("MMM-D hh:mmA"); return value; }) @@ -86,10 +86,11 @@ label: label, data: _.map(data, attribute), lineTension: 0, - backgroundColor: 'rgba(235, 243, 249, 0.4)', - pointBackgroundColor: '#3981B4', - borderColor: '#3981B4', - borderWidth: 4, + backgroundColor: 'transparent', + pointBackgroundColor: '#fff', + pointBorderColor: '#7746ec', + borderColor: '#7746ec', + borderWidth: 2, }, ], }; diff --git a/src/Horizon.php b/src/Horizon.php index da2f87c8..92797b40 100644 --- a/src/Horizon.php +++ b/src/Horizon.php @@ -59,6 +59,11 @@ class Horizon 'Metrics', 'Locks', 'Processes', ]; + public function __construct() + { + static::$useDarkTheme = config('horizon.theme') === 'dark'; + } + /** * Determine if the given request can access the Horizon dashboard. * @@ -108,11 +113,12 @@ public static function use($connection) /** * Specifies that Horizon should use the dark theme. * + * @param boolean $on * @return static */ - public static function night() + public static function night($on = true) { - static::$useDarkTheme = true; + static::$useDarkTheme = $on; return new static; } diff --git a/src/Repositories/RedisMetricsRepository.php b/src/Repositories/RedisMetricsRepository.php index 08a5c815..4a01ec60 100644 --- a/src/Repositories/RedisMetricsRepository.php +++ b/src/Repositories/RedisMetricsRepository.php @@ -274,7 +274,7 @@ protected function storeSnapshotForJob($job) ); $this->connection()->zremrangebyrank( - 'snapshot:'.$key, 0, -25 + 'snapshot:'.$key, 0, -abs(1 + config('horizon.metrics.trim_snapshots.job', 24)) ); } @@ -298,7 +298,7 @@ protected function storeSnapshotForQueue($queue) ); $this->connection()->zremrangebyrank( - 'snapshot:'.$key, 0, -25 + 'snapshot:'.$key, 0, -abs(1 + config('horizon.metrics.trim_snapshots.queue', 24)) ); } From ae3ed43469f39fa2d50c1d68935cfd48e69d5c5d Mon Sep 17 00:00:00 2001 From: Bert Date: Fri, 13 Mar 2020 16:23:46 +0100 Subject: [PATCH 2/4] code format --- src/Horizon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Horizon.php b/src/Horizon.php index 92797b40..04599da9 100644 --- a/src/Horizon.php +++ b/src/Horizon.php @@ -113,7 +113,7 @@ public static function use($connection) /** * Specifies that Horizon should use the dark theme. * - * @param boolean $on + * @param bool $on * @return static */ public static function night($on = true) From 968d8db6e1e5b73ca956aeb1d587de63bc33f498 Mon Sep 17 00:00:00 2001 From: Bert Date: Fri, 13 Mar 2020 14:55:49 +0100 Subject: [PATCH 3/4] add metrics options and dark mode config --- config/horizon.php | 32 +++++++++++++++++++++ resources/js/components/LineChart.vue | 2 +- resources/js/screens/metrics/preview.vue | 11 +++---- src/Horizon.php | 10 +++++-- src/Repositories/RedisMetricsRepository.php | 4 +-- 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/config/horizon.php b/config/horizon.php index 1f95f70c..ca100eed 100644 --- a/config/horizon.php +++ b/config/horizon.php @@ -107,6 +107,38 @@ 'monitored' => 10080, ], + /* + |-------------------------------------------------------------------------- + | Metrics + |-------------------------------------------------------------------------- + | + | Here you can configure how many snapshots should be kept to display in + | the metrics graph. You should use this in conjunction with the + | `horizon:snapshot` schedule to define how long of a timespan + | you want to see in the metrics. + | + */ + + 'metrics' => [ + 'trim_snapshots' => [ + 'job' => 24, + 'queue' => 24, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Theme + |-------------------------------------------------------------------------- + | + | Here you can define which theme Horizon should load. + | + | Supported: "light", "dark" + | + */ + + 'theme' => 'light', + /* |-------------------------------------------------------------------------- | Fast Termination diff --git a/resources/js/components/LineChart.vue b/resources/js/components/LineChart.vue index 281c4f88..53721ca0 100644 --- a/resources/js/components/LineChart.vue +++ b/resources/js/components/LineChart.vue @@ -62,6 +62,6 @@ diff --git a/resources/js/screens/metrics/preview.vue b/resources/js/screens/metrics/preview.vue index e7c78cf6..17cb0c06 100644 --- a/resources/js/screens/metrics/preview.vue +++ b/resources/js/screens/metrics/preview.vue @@ -57,7 +57,7 @@ prepareData(data) { return _.chain(data) .map(value => { - value.time = this.formatDate(value.time).format("hh:mmA"); + value.time = this.formatDate(value.time).format("MMM-D hh:mmA"); return value; }) @@ -86,10 +86,11 @@ label: label, data: _.map(data, attribute), lineTension: 0, - backgroundColor: 'rgba(235, 243, 249, 0.4)', - pointBackgroundColor: '#3981B4', - borderColor: '#3981B4', - borderWidth: 4, + backgroundColor: 'transparent', + pointBackgroundColor: '#fff', + pointBorderColor: '#7746ec', + borderColor: '#7746ec', + borderWidth: 2, }, ], }; diff --git a/src/Horizon.php b/src/Horizon.php index f20911fc..79277f3e 100644 --- a/src/Horizon.php +++ b/src/Horizon.php @@ -61,6 +61,11 @@ class Horizon 'Metrics', 'Locks', 'Processes', ]; + public function __construct() + { + static::$useDarkTheme = config('horizon.theme') === 'dark'; + } + /** * Determine if the given request can access the Horizon dashboard. * @@ -110,11 +115,12 @@ public static function use($connection) /** * Specifies that Horizon should use the dark theme. * + * @param boolean $on * @return static */ - public static function night() + public static function night($on = true) { - static::$useDarkTheme = true; + static::$useDarkTheme = $on; return new static; } diff --git a/src/Repositories/RedisMetricsRepository.php b/src/Repositories/RedisMetricsRepository.php index 08a5c815..4a01ec60 100644 --- a/src/Repositories/RedisMetricsRepository.php +++ b/src/Repositories/RedisMetricsRepository.php @@ -274,7 +274,7 @@ protected function storeSnapshotForJob($job) ); $this->connection()->zremrangebyrank( - 'snapshot:'.$key, 0, -25 + 'snapshot:'.$key, 0, -abs(1 + config('horizon.metrics.trim_snapshots.job', 24)) ); } @@ -298,7 +298,7 @@ protected function storeSnapshotForQueue($queue) ); $this->connection()->zremrangebyrank( - 'snapshot:'.$key, 0, -25 + 'snapshot:'.$key, 0, -abs(1 + config('horizon.metrics.trim_snapshots.queue', 24)) ); } From a7c106b1a8d74985de9a296bd7e8a43e6da08270 Mon Sep 17 00:00:00 2001 From: Bert Date: Fri, 13 Mar 2020 16:23:46 +0100 Subject: [PATCH 4/4] code format --- src/Horizon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Horizon.php b/src/Horizon.php index 79277f3e..c6f1e16f 100644 --- a/src/Horizon.php +++ b/src/Horizon.php @@ -115,7 +115,7 @@ public static function use($connection) /** * Specifies that Horizon should use the dark theme. * - * @param boolean $on + * @param bool $on * @return static */ public static function night($on = true)