From c621fd04df4d72c0e8999e3785966192cf972548 Mon Sep 17 00:00:00 2001
From: mooleshacat <43627985+mooleshacat@users.noreply.github.com>
Date: Mon, 21 Oct 2024 23:29:11 -0400
Subject: [PATCH 1/6] loadavg initial commit
---
README.md | 5 +++--
config/config.example.yml | 8 ++++++++
src/invidious/config.cr | 1 +
src/invidious/views/template.ecr | 4 ++++
4 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index eff5a9f1..efe52990 100644
--- a/README.md
+++ b/README.md
@@ -78,6 +78,7 @@
- add proxy patch
- sig helper reconnect patch
- uptime status patch (mooleshacat)
+- loadavg status patch (mooleshacat)
- token monitor patch (mooleshacat)
**User features**
@@ -169,9 +170,9 @@ This branch has the token monitor patch from myself (mooleshacat) which will che
This patch is a temporary workaround until inv_sig_helper itself can get the tokens for us. unixfox (invidious dev) raised this idea to techmetx11 (inv_sig_helper dev) and they are working on an implementation that will eventually make this patch useless. This is OK, as it is only a patch and that setup would be better performance wise than my current implementations. You can read about it here https://github.com/iv-org/inv_sig_helper/issues/10
-## uptime status patch notes
+## uptime & loadavg status patch notes
-This branch has the uptime patch from myself (mooleshacat) which if enabled in the config, will show the uptime on the page. Please note, if everyone can see your uptime, so could a theoretical attacker. This may or may not be a good idea, you be the judge.
+This branch has the uptime & loadavg patch from myself (mooleshacat) which if enabled in the config, will show the uptime and/or loadavg on the page. Please note, if everyone can see your uptime or loadavg, so could a theoretical attacker. This may or may not be a good idea, you be the judge.
## Documentation
diff --git a/config/config.example.yml b/config/config.example.yml
index a9ef777a..eef2e222 100644
--- a/config/config.example.yml
+++ b/config/config.example.yml
@@ -246,6 +246,14 @@ http_proxy:
##
#uptime_enabled: true
+##
+## Enable/Disable showing the load avg on the main page.
+##
+## Accepted values: true, false
+## Default: false
+##
+#loadavg_enabled: true
+
##
## Enable/Disable the "Popular" tab on the main page.
##
diff --git a/src/invidious/config.cr b/src/invidious/config.cr
index a5fc0aca..1bafca78 100644
--- a/src/invidious/config.cr
+++ b/src/invidious/config.cr
@@ -103,6 +103,7 @@ class Config
property use_pubsub_feeds : Bool | Int32 = false
property popular_enabled : Bool = true
property uptime_enabled : Bool = false
+ property loadavg_enabled : Bool = false
property captcha_enabled : Bool = true
property login_enabled : Bool = true
property registration_enabled : Bool = true
diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr
index a0e5165b..c2d83d0a 100644
--- a/src/invidious/views/template.ecr
+++ b/src/invidious/views/template.ecr
@@ -2,6 +2,7 @@
locale = env.get("preferences").as(Preferences).locale
dark_mode = env.get("preferences").as(Preferences).dark_mode
uptime_enabled = CONFIG.uptime_enabled
+ loadavg_enabled = CONFIG.loadavg_enabled
%>
@@ -38,6 +39,9 @@
<% if uptime_enabled %>
server <%= Invidious::Uptime.get_uptime %> |
<% end %>
+ <% if loadavg_enabled %>
+ server <%= Invidious::Loadavg.get_loadavg %> |
+ <% end %>
From 1619e78d6c9216b60914d3b7abf2b093f398b0ce Mon Sep 17 00:00:00 2001
From: mooleshacat <43627985+mooleshacat@users.noreply.github.com>
Date: Mon, 21 Oct 2024 23:31:35 -0400
Subject: [PATCH 2/6] escaped quotes, fixed template
---
src/invidious/views/template.ecr | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr
index c2d83d0a..bcd586b7 100644
--- a/src/invidious/views/template.ecr
+++ b/src/invidious/views/template.ecr
@@ -40,7 +40,7 @@
server <%= Invidious::Uptime.get_uptime %> |
<% end %>
<% if loadavg_enabled %>
- server <%= Invidious::Loadavg.get_loadavg %> |
+ server load <%= Invidious::Loadavg.get_loadavg %> |
<% end %>
From d9b9cc0d7c44627654f426adc520efded40774f0 Mon Sep 17 00:00:00 2001
From: mooleshacat <43627985+mooleshacat@users.noreply.github.com>
Date: Mon, 21 Oct 2024 23:33:37 -0400
Subject: [PATCH 3/6] forgot a file
---
src/invidious/helpers/loadavg.cr | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 src/invidious/helpers/loadavg.cr
diff --git a/src/invidious/helpers/loadavg.cr b/src/invidious/helpers/loadavg.cr
new file mode 100644
index 00000000..7b342ecb
--- /dev/null
+++ b/src/invidious/helpers/loadavg.cr
@@ -0,0 +1,23 @@
+class Invidious::Loadavg
+
+ def self.get_loadavg
+
+ str_loadavg = "error"
+
+ if CONFIG.loadavg_enabled
+
+ # get the uptime
+ loadavg_cmd = "/usr/bin/cat /proc/loadavg | awk -F'[ ]' '{print $1\" \"$2\" \"$3}'"
+ loadavg_args = ""
+ process = Process.new(loadavg_cmd, [loadavg_args], output: Process::Redirect::Pipe)
+ str_loadavg = process.output.gets_to_end
+
+ else
+ str_loadavg = ""
+ end
+
+ return str_loadavg
+
+ end
+
+end
\ No newline at end of file
From 6b426c28861799c6a3d5d9f5e32818139a368a57 Mon Sep 17 00:00:00 2001
From: mooleshacat <43627985+mooleshacat@users.noreply.github.com>
Date: Mon, 21 Oct 2024 23:48:52 -0400
Subject: [PATCH 4/6] test
---
src/invidious/helpers/loadavg.cr | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/invidious/helpers/loadavg.cr b/src/invidious/helpers/loadavg.cr
index 7b342ecb..9a9496f7 100644
--- a/src/invidious/helpers/loadavg.cr
+++ b/src/invidious/helpers/loadavg.cr
@@ -7,10 +7,12 @@ class Invidious::Loadavg
if CONFIG.loadavg_enabled
# get the uptime
- loadavg_cmd = "/usr/bin/cat /proc/loadavg | awk -F'[ ]' '{print $1\" \"$2\" \"$3}'"
- loadavg_args = ""
- process = Process.new(loadavg_cmd, [loadavg_args], output: Process::Redirect::Pipe)
- str_loadavg = process.output.gets_to_end
+ #loadavg_cmd = "/usr/bin/cat /proc/loadavg | awk -F'[ ]' '{print $1\" \"$2\" \"$3}'"
+ #loadavg_args = ""
+ #process = Process.new(loadavg_cmd, [loadavg_args], output: Process::Redirect::Pipe)
+ #str_loadavg = process.output.gets_to_end
+
+ str_loadavg = "test"
else
str_loadavg = ""
From 5632e313358d4b2f61d9ec9653f40311c7b71080 Mon Sep 17 00:00:00 2001
From: mooleshacat <43627985+mooleshacat@users.noreply.github.com>
Date: Mon, 21 Oct 2024 23:56:29 -0400
Subject: [PATCH 5/6] oneliner test
---
src/invidious/helpers/loadavg.cr | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/invidious/helpers/loadavg.cr b/src/invidious/helpers/loadavg.cr
index 9a9496f7..9595f831 100644
--- a/src/invidious/helpers/loadavg.cr
+++ b/src/invidious/helpers/loadavg.cr
@@ -12,7 +12,7 @@ class Invidious::Loadavg
#process = Process.new(loadavg_cmd, [loadavg_args], output: Process::Redirect::Pipe)
#str_loadavg = process.output.gets_to_end
- str_loadavg = "test"
+ str_loadavg = `/usr/bin/cat /proc/loadavg | awk -F'[ ]' '{print $1" "$2" "$3}'`
else
str_loadavg = ""
From 0a033b3dea1407ec3091ea3f514ecab4094319dc Mon Sep 17 00:00:00 2001
From: mooleshacat <43627985+mooleshacat@users.noreply.github.com>
Date: Mon, 21 Oct 2024 23:59:51 -0400
Subject: [PATCH 6/6] removed commented code
---
src/invidious/helpers/loadavg.cr | 6 ------
1 file changed, 6 deletions(-)
diff --git a/src/invidious/helpers/loadavg.cr b/src/invidious/helpers/loadavg.cr
index 9595f831..dffab823 100644
--- a/src/invidious/helpers/loadavg.cr
+++ b/src/invidious/helpers/loadavg.cr
@@ -5,12 +5,6 @@ class Invidious::Loadavg
str_loadavg = "error"
if CONFIG.loadavg_enabled
-
- # get the uptime
- #loadavg_cmd = "/usr/bin/cat /proc/loadavg | awk -F'[ ]' '{print $1\" \"$2\" \"$3}'"
- #loadavg_args = ""
- #process = Process.new(loadavg_cmd, [loadavg_args], output: Process::Redirect::Pipe)
- #str_loadavg = process.output.gets_to_end
str_loadavg = `/usr/bin/cat /proc/loadavg | awk -F'[ ]' '{print $1" "$2" "$3}'`