<html><head><title> POO lib: usage meter </title></head><body><center> <h3>POO Library</h3> <h1>Usage Meter</h1> </center> This object checks the number of users logged in every six minutes, and keeps an hourly tally over the last week. The resulting counts are displayed in a tabular format. <p>This object does <i>not</i> require wiz privs to build. It does, however, require <a href="periodic.standard.html">$pub.periodic.standard</a>. <hr> <pre>@create $pub.periodic.standard as usage meter @set usage meter.aliases = meter @newfunc reset(self) on usage meter for day in ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']: setattr(self,day,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) self.since = ctime(time()) .x @cmd usage meter.reset <this> calls reset() @newfunc check(self) on usage meter timeparts = string.split(ctime(time())) day = timeparts[0] hour = string.atoi(string.split(timeparts[3],':')[0]) usercount = len(users()) rec = getattr(self,day) if not rec: setattr(self,day, range(0,24)) rec = getattr(self,day) rec[hour] = rec[hour] + usercount # while we're at it, also reset the next hour's count timeparts = string.split(ctime(time() + 3600)) day = timeparts[0] hour = string.atoi(string.split(timeparts[3],':')[0]) rec = getattr(self,day) if rec: rec[hour] = 0 .x @newfunc buildTable(self) on usage meter out = " 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n" for day in ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']: out = out + day for hour in range(0,24): try: count = getattr(self,day)[hour] except: count = 0 out = out + ("%3d" % count) out = out + "\n" return out .x @newfunc description(self,looker) on usage meter return super(looker) + "\n" + self.buildTable() \ + "\n(Running since " + self.since + "; " \ + "last update " + ctime(self.lastTime) + ".)" .x @set meter.interval = 360 @newfunc meter.periodicTask(self) self.check() .x </pre> <hr> <h3>Usage</h3> First, reset the usage meter by typing <b>reset meter</b>. This sets all initial counts to zero. Then, as with any object derived from <a href="periodic.standard.html">$pub.periodic.standard</a>, you'll need to start it by typing <b>start meter</b>. <p>That's it -- just let it run, and when you look at it, you'll see the tallies displayed (after any description you've set as on any object). Remember that the counts shown are the number of people counted every six minutes within an hour. So one person logged in for an hour registers as 10, as do two people connected for half an hour. <p><hr> <address> http://www.strout.net/python/poo/lib/usage.html <br>Last Updated: 10/15/97 . . . . . . <a href="http://www.strout.net/">Joe Strout</a> </address> </body></html>