Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 46 lines (38 sloc) 1.19 KB
#!/usr/bin/python
import sys, os
from pysqlite2 import dbapi2 as sqlite
from subprocess import Popen, PIPE
import glob
try:
db = os.environ["dbpath"]
except KeyError:
db = "/home/timo/stackless/lojbanquest/data/quest.db"
if sys.argv[1:]:
if sys.argv[1] == "config":
print "graph_title lojbanquest players"
print "graph_category lojbanquest"
print "graph_scale no"
print "graph_vlabel Count"
print "players.label Players"
print "online.label Playing"
sys.exit(0)
# first, see if lojbanquest is online
try:
ps_out = Popen(["ps", "a"], stdout=PIPE).communicate()[0]
except CalledProcessError, e:
print "could not call 'ps a':", e, repr(e)
sys.exit(1)
lq_online = all(map(ps_out.__contains__, ["nagare-admin", "serve", "quest"]))
c = sqlite.connect(db)
cur = c.cursor()
numplayers = c.execute("SELECT count() FROM Player").fetchone()[0]
numonline = c.execute("SELECT count() FROM Player WHERE status > 0").fetchone()[0]
cur.close()
c.close()
if lq_online:
print "players.value %i" % (numplayers,)
print "online.value %i" % (numonline,)
else:
# show a gap for downtime
print "players.value U"
print "online.value U"