]> jfr.im git - erebus.git/blame - modules/resources.py
fix croncheck to redirect stderr also
[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)
23def ram(bot, user, chan, realtarget, *args):
b79721ee 24 if chan is not None and realtarget == chan.name: replyto = chan
72137af7 25 else: replyto = user
26
27 try:
28 res = resource.getrusage(resource.RUSAGE_BOTH)
29 except:
30 res = resource.getrusage(resource.RUSAGE_SELF)
31
32 bot.msg(replyto, "Memory usage (MiB): %r" % (res.ru_maxrss/1024.0))
33
fb20be7c 34@lib.hook(needchan=False, glevel=lib.MANAGER)
35def resources(bot, user, chan, realtarget, *args):
b79721ee 36 if chan is not None and realtarget == chan.name: replyto = chan
72137af7 37 else: replyto = user
38
39 try:
40 res = resource.getrusage(resource.RUSAGE_BOTH)
41 except:
42 res = resource.getrusage(resource.RUSAGE_SELF)
43
44 bot.msg(replyto, "Resource usage:")
45 for i, v in [
46 ('utime (s)', res.ru_utime),
47 ('stime (s)', res.ru_stime),
48 ('memory (MiB)', (res.ru_maxrss/1024.0))
49 ('I/O (blocks)', res.ru_inblock+res.ru_oublock),
50 ('page faults', res.ru_majflt),
51 ('signals', res.ru_nsignals),
52 ('context switches (voluntary)', res.ru_nvcsw),
53 ('context switches (involuntary)', res.ru_nivcsw),
54 ]:
55 bot.msg(replyto, "- %s: %r" % (i, v))
56 bot.msg(replyto, "EOL.")