]> jfr.im git - erebus.git/blame - modules/resources.py
added help to each module
[erebus.git] / modules / resources.py
CommitLineData
72137af7 1# Erebus IRC bot - Author: Erebus Team
2# simple module example
3# This file is released into the public domain; see http://unlicense.org/
4
5# module info
6modinfo = {
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [1], # compatible module API versions
10 'depends': [], # other modules required to work properly?
11}
12
13# preamble
14import modlib
15lib = modlib.modlib(__name__)
16modstart = lib.modstart
17modstop = lib.modstop
18
19# module code
20import resource
21
fb20be7c 22@lib.hook(needchan=False, glevel=lib.MANAGER)
5f03d045 23@lib.help(None, "show RAM usage")
fb20be7c 24def ram(bot, user, chan, realtarget, *args):
b79721ee 25 if chan is not None and realtarget == chan.name: replyto = chan
72137af7 26 else: replyto = user
27
28 try:
29 res = resource.getrusage(resource.RUSAGE_BOTH)
30 except:
31 res = resource.getrusage(resource.RUSAGE_SELF)
32
a8657439 33 bot.fastmsg(replyto, "Memory usage (MiB): %r" % (res.ru_maxrss/1024.0))
72137af7 34
fb20be7c 35@lib.hook(needchan=False, glevel=lib.MANAGER)
5f03d045 36@lib.help(None, "show resource usage")
fb20be7c 37def resources(bot, user, chan, realtarget, *args):
b79721ee 38 if chan is not None and realtarget == chan.name: replyto = chan
72137af7 39 else: replyto = user
40
41 try:
42 res = resource.getrusage(resource.RUSAGE_BOTH)
43 except:
44 res = resource.getrusage(resource.RUSAGE_SELF)
45
a8657439 46 bot.slowmsg(replyto, "Resource usage:")
10e2a6b9 47 for i, v in (
72137af7 48 ('utime (s)', res.ru_utime),
49 ('stime (s)', res.ru_stime),
10e2a6b9 50 ('memory (MiB)', (res.ru_maxrss/1024.0)),
72137af7 51 ('I/O (blocks)', res.ru_inblock+res.ru_oublock),
52 ('page faults', res.ru_majflt),
53 ('signals', res.ru_nsignals),
54 ('context switches (voluntary)', res.ru_nvcsw),
55 ('context switches (involuntary)', res.ru_nivcsw),
10e2a6b9 56 ):
a8657439 57 bot.slowmsg(replyto, "- %s: %r" % (i, v))
58 bot.slowmsg(replyto, "EOL.")