From anonymous, 7 Years ago, written in Python.
Embed
  1.     def ram(self, irc, msg, args):
  2.         """tells you the ram of the current machine Supybot uses."""
  3.         p = subprocess.Popen(["free", "-o"], stdout=subprocess.PIPE)
  4.         out, err = p.communicate()
  5.         out = out.split()
  6.         total = float(out[7])/1024.0/1024.0
  7.         using = float(out[8])/1024.0/1024.0
  8.         free  = float(out[9])/1024.0/1024.0
  9.         msg = "[{0:4}] Total: {1:4.1f} GB | Used:04 {2:4.1f} GB ({3:>6.2%}) | Free:03 {4:4.1f} GB ({5:>6.2%})"
  10.         red_length = int(round((using/total) * 10.0))
  11.         green_length = 10 - red_length
  12.         bar = "[\0033%s%s\x0f]" % ("|" * red_length, " " * green_length)
  13.         irc.reply(msg.format(total, using, using/total, free, free/total), prefixNick=False)
  14.         irc.reply("Free: %s" % (bar), prefixNick=False)
  15.     ram = wrap(ram)
  16.        
  17.     def swap(self, irc, msg, args):
  18.         """tells you the swapped ram of the current machine Supybot uses."""
  19.         p = subprocess.Popen(["free", "-o"], stdout=subprocess.PIPE)
  20.         out, err = p.communicate()
  21.         out = out.split()
  22.         total = float(out[14])/1024.0/1024.0
  23.         using = float(out[15])/1024.0/1024.0
  24.         free = float(out[16])/1024.0/1024.0
  25.         msg = "[{0:4}] Total: {1:4.1f} GB | Used:04 {2:4.1f} GB ({3:>6.2%}) | Free:03 {4:4.1f} GB ({5:>6.2%})"
  26.         red_length = int(round((using/total) * 10.0))
  27.         green_length = 10 - red_length
  28.         bar = "[\0033%s%s\x0f]" % ("|" * red_length, " " * green_length)
  29.         irc.reply(msg.format(total, using, using/total, free, free/total), prefixNick=False)
  30.         irc.reply("Free: %s" % (bar), prefixNick=False)
  31.     ram = wrap(ram)