Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Rough Memory Usage Estimate for Hangoutsbot
import logging, os, sys, resource
import psutil # pip3 install psutil
import plugins
logger = logging.getLogger(__name__)
def _initialise(bot):
plugins.register_admin_command(["resourcememory", "psutilmemory"])
def resourcememory(bot, event, *args):
"""print basic information about memory usage with resource library"""
rusage_denom = 1024.
if sys.platform == 'darwin':
# ... it seems that in OSX the output is different units ...
rusage_denom = rusage_denom * rusage_denom
mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom
message = "memory (resource): {} MB".format(mem)
bot.send_message_parsed(event.conv, "<b>" + message + "</b>")
def psutilmemory(bot, event, *args):
"""print basic information about memory usage with psutil library"""
# return the memory usage in MB
process = psutil.Process(os.getpid())
mem = process.memory_info()[0] / float(2 ** 20)
message = "memory (psutil): {} MB".format(mem)
bot.send_message_parsed(event.conv, "<b>" + message + "</b>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.