Skip to content

Commit

Permalink
Monitor memory usage of shards
Browse files Browse the repository at this point in the history
Commit adds mem checks for the individual shards and adds the info to
the shards stats db. Will be used later
  • Loading branch information
Humblemonk committed Jul 3, 2024
1 parent a563a84 commit c124275
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
8 changes: 5 additions & 3 deletions dice_maiden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'discordrb'
require 'dicebag'
require 'dotenv'
require 'get_process_mem'

Dotenv.load
@total_shards = ENV['SHARD'].to_i
Expand Down Expand Up @@ -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!
Expand Down

0 comments on commit c124275

Please sign in to comment.