From c1242757413b31d9de10de5010d206b533d70e0d Mon Sep 17 00:00:00 2001 From: Humblemonk Date: Wed, 3 Jul 2024 15:17:18 -0400 Subject: [PATCH] Monitor memory usage of shards Commit adds mem checks for the individual shards and adds the info to the shards stats db. Will be used later --- Gemfile | 1 + dice_maiden.rb | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index f62c9dd..3a7e469 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ gem 'base64' gem 'dicebag', git: 'https://github.com/Humblemonk/Dice-Bag.git', branch: 'pre-3.3' gem 'discordrb', github: 'shardlab/discordrb', branch: 'main' gem 'dotenv', '~> 2.5' +gem 'get_process_mem', '~>0.2.1' gem 'rest-client', '~>2.1' gem 'rubocop', require: false gem 'sqlite3', '~> 2.0', '>= 2.0.1' diff --git a/dice_maiden.rb b/dice_maiden.rb index edfe30c..5e1e45b 100755 --- a/dice_maiden.rb +++ b/dice_maiden.rb @@ -10,6 +10,7 @@ require 'discordrb' require 'dicebag' require 'dotenv' +require 'get_process_mem' Dotenv.load @total_shards = ENV['SHARD'].to_i @@ -211,10 +212,11 @@ time = Time.now.getutc if @bot.connected? == true server_parse = @bot.servers.count - $db.execute "update shard_stats set server_count = #{server_parse}, timestamp = CURRENT_TIMESTAMP where shard_id = #{@shard}" - File.open('dice_rolls.log', 'a') { |f| f.puts "#{time} Shard: #{@shard} Server Count: #{server_parse}" } + mem = GetProcessMem.new + $db.execute "update shard_stats set server_count= #{server_parse}, mem = #{mem.mb}, timestamp = CURRENT_TIMESTAMP where shard_id = #{@shard}" + File.open('dice_rolls.log', 'a') { |f| f.puts "#{time} Shard: #{@shard} Server Count: #{server_parse} Memory: #{mem.mb}" } else - $db.execute "update shard_stats set server_count = 0, timestamp = CURRENT_TIMESTAMP where shard_id = #{@shard}" + $db.execute "update shard_stats set server_count = 0, mem = 0, timestamp = CURRENT_TIMESTAMP where shard_id = #{@shard}" File.open('dice_rolls.log', 'a') { |f| f.puts "#{time} Shard: #{@shard} bot not ready!" } # Bot died and cant connect to Discord. Kill the bot and have eye restart it exit!