From: Michael Tremer Date: Thu, 6 Feb 2025 20:22:56 +0000 (+0000) Subject: builders: Move stats JS into the main file X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a55c5c4d4985e65c7322e80aaaf0aaa112c0c905;p=pbs.git builders: Move stats JS into the main file We currently cannot easily add more files in the right place, so since there is only so little code, we just ship it all together. Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 8a44eb96..61500ec9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -343,7 +343,6 @@ CLEANFILES += \ src/static/css/site.css static_js_DATA = \ - src/static/js/builders-stats.min.js \ src/static/js/jquery.min.js \ src/static/js/job-log-stream.min.js \ src/static/js/notification-worker.min.js \ @@ -352,7 +351,6 @@ static_js_DATA = \ static_jsdir = $(staticdir)/js EXTRA_DIST += \ - src/static/js/builders-stats.js \ src/static/js/job-log-stream.js \ src/static/js/notification-worker.js \ src/static/js/pbs.js diff --git a/src/static/js/builders-stats.js b/src/static/js/builders-stats.js deleted file mode 100644 index b65bd70f..00000000 --- a/src/static/js/builders-stats.js +++ /dev/null @@ -1,52 +0,0 @@ -$(".builders-stats").each(function() { - // Fetch the name of the builder - const name = $(this).data("name"); - - const cpu_usage = $(this).find("#cpu-usage"); - const mem_usage = $(this).find("#mem-usage"); - const swap_usage = $(this).find("#swap-usage"); - - // Make the URL - const url = "wss://" + window.location.host + "/builders/" + name + "/stats"; - - // Try to connect to the stream - const stream = new WebSocket(url); - - // Updates the progressbar and sets a colour - updateProgressBar = function(e, percentage) { - // Set the value - e.val(percentage * 100); - - // Remove all classes - e.removeClass("is-dark is-light is-danger is-warning is-success"); - - if (percentage >= 0.9) { - e.addClass("is-danger"); - - } else if (percentage >= 0.75) { - e.addClass("is-warning"); - - } else { - e.addClass("is-success"); - } - } - - stream.addEventListener("message", (event) => { - // Parse message as JSON - const data = JSON.parse(event.data); - - console.debug("Message from server: ", data); - - // Set CPU usage - if (cpu_usage) - updateProgressBar(cpu_usage, data.cpu_usage); - - // Set memory usage - if (mem_usage) - updateProgressBar(mem_usage, data.mem_usage); - - // Set swap usage - if (swap_usage) - updateProgressBar(swap_usage, data.swap_usage); - }); -}); diff --git a/src/static/js/pbs.js b/src/static/js/pbs.js index 772d1cb2..e4603c81 100644 --- a/src/static/js/pbs.js +++ b/src/static/js/pbs.js @@ -134,3 +134,60 @@ $("#push-subscribe-button").on("click", function() { return subscription; }); }); + +/* + * Builder Stats + */ + +$(".builders-stats").each(function() { + // Fetch the name of the builder + const name = $(this).data("name"); + + const cpu_usage = $(this).find("#cpu-usage"); + const mem_usage = $(this).find("#mem-usage"); + const swap_usage = $(this).find("#swap-usage"); + + // Make the URL + const url = "wss://" + window.location.host + "/builders/" + name + "/stats"; + + // Try to connect to the stream + const stream = new WebSocket(url); + + // Updates the progressbar and sets a colour + updateProgressBar = function(e, percentage) { + // Set the value + e.val(percentage * 100); + + // Remove all classes + e.removeClass("is-dark is-light is-danger is-warning is-success"); + + if (percentage >= 0.9) { + e.addClass("is-danger"); + + } else if (percentage >= 0.75) { + e.addClass("is-warning"); + + } else { + e.addClass("is-success"); + } + } + + stream.addEventListener("message", (event) => { + // Parse message as JSON + const data = JSON.parse(event.data); + + console.debug("Message from server: ", data); + + // Set CPU usage + if (cpu_usage) + updateProgressBar(cpu_usage, data.cpu_usage); + + // Set memory usage + if (mem_usage) + updateProgressBar(mem_usage, data.mem_usage); + + // Set swap usage + if (swap_usage) + updateProgressBar(swap_usage, data.swap_usage); + }); +}); diff --git a/src/templates/builders/macros.html b/src/templates/builders/macros.html index b1f23551..68d14f7c 100644 --- a/src/templates/builders/macros.html +++ b/src/templates/builders/macros.html @@ -19,9 +19,6 @@ ##############################################################################} {% macro BuilderStats(builder) %} - {# XXX Not sure if this is a good place to load the JS #} - -