From 12fa195a2101922f58ef5db9f4a3df18cd1fc2ca Mon Sep 17 00:00:00 2001 From: Shen Yang Date: Wed, 11 Feb 2026 19:27:44 -0600 Subject: [PATCH] create resource monitoring script --- lib/tasks/post_gc_stat_to_discord.rake | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/tasks/post_gc_stat_to_discord.rake diff --git a/lib/tasks/post_gc_stat_to_discord.rake b/lib/tasks/post_gc_stat_to_discord.rake new file mode 100644 index 0000000000..373c69898a --- /dev/null +++ b/lib/tasks/post_gc_stat_to_discord.rake @@ -0,0 +1,25 @@ +desc "Post gc stats to discord channel" + +task post_gc_stat_to_discord: :environment do + stats = GC.stat + + unless ENV["DISCORD_WEBHOOK_URL"].nil? + formatted_stats = JSON.pretty_generate(stats) + discord_message = <<~MULTILINE + ```json + #{formatted_stats} + ``` + MULTILINE + + payload = {content: discord_message}.to_json + + uri = URI.parse(ENV["DISCORD_WEBHOOK_URL"]) + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = (uri.scheme == "https") # Use SSL for HTTPS + + request = Net::HTTP::Post.new(uri.path, {"Content-Type" => "application/json"}) + request.body = payload + + http.request(request) + end +end