Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- graphs = [["h", "hour"], ["d", "day"], ["w", "week"]]
- viperaddr = "99.198.97.162", 27105
- vipereuroaddr = "188.138.113.30", 27015
- epicaddr = "epic-empires.co.uk", 27020
- outdir = "/var/www/html/players/emp/"
- dbs = "db/emp/viper.rrd", "db/emp/vipereuro.rrd", "db/emp/epic.rrd"
- ##############################################################
- import sys
- import time
- import rrdtool
- try:
- from lib.SourceLib import SourceQuery
- except Exception, e:
- msg("Import error: %s" % str(e))
- sys.exit()
- def msg(msg):
- print "(%s) %s" % (time.strftime("%d %b %Y %H:%M:%S"), msg)
- def get(addr):
- try:
- srv = SourceQuery.SourceQuery(addr[0], addr[1])
- srv.connect()
- return str(srv.info()["numplayers"])
- except Exception, e:
- msg("Error retrieving server data: %s" % str(e))
- return False
- try:
- #N = time = now
- plys = []
- plys.append(get(viperaddr))
- plys.append(get(vipereuroaddr))
- plys.append(get(epicaddr))
- if plys[0] != False: rrdtool.update(dbs[0], "N:" + plys[0])
- if plys[1] != False: rrdtool.update(dbs[1], "N:" + plys[1])
- if plys[2] != False: rrdtool.update(dbs[2], "N:" + plys[2])
- msg("Updated databases")
- except Exception, e:
- msg("Error updating DBs: %s" % str(e))
- for graph in graphs:
- try:
- #--start -1d = start the graph from 1 day ago
- #DEF:<GPRAH variable name>=<rrd file>:<RRD variable name>:RRA
- #%1.1lf would give you a single precision floating point number, like 5.2 or 0.6,
- #and %2.4lf would be a number like 23.1412. Whole number can be rounded with %2.0lf
- rrdtool.graph(outdir + graph[0] + ".png", "--start", "-1" + graph[0],
- "--title=Clients (last " + graph[1] + ")", "--vertical-label=Number of clients",
- "--watermark=ukgamer.dyndns.org",
- "DEF:viperply=" + dbs[0] + ":players:AVERAGE",
- "DEF:vipereuroply=" + dbs[1] + ":players:AVERAGE",
- "DEF:epicply=" + dbs[2] + ":players:AVERAGE",
- "LINE2:viperply#FF0000:VIPER",
- "LINE2:vipereuroply#00FF00:VIPER Euro",
- "LINE2:epicply#0000FF:EPIC",
- "COMMENT:\\n",
- "GPRINT:viperply:MIN:VIPER Min\: %2.0lf",
- "GPRINT:viperply:LAST:Cur\: %2.0lf",
- "GPRINT:viperply:MAX:Max\: %2.0lf",
- "GPRINT:viperply:AVERAGE:Avg\: %2.1lf\\r",
- #########################################
- "GPRINT:vipereuroply:MIN:VIPER Euro Min\: %2.0lf",
- "GPRINT:vipereuroply:LAST:Cur\: %2.0lf",
- "GPRINT:vipereuroply:MAX:Max\: %2.0lf",
- "GPRINT:vipereuroply:AVERAGE:Avg\: %2.1lf\\r",
- #########################################
- "GPRINT:epicply:MIN:EPIC Min\: %2.0lf",
- "GPRINT:epicply:LAST:Cur\: %2.0lf",
- "GPRINT:epicply:MAX:Max\: %2.0lf",
- "GPRINT:epicply:AVERAGE:Avg\: %2.1lf\\r",
- "COMMENT:Last update\: " + time.strftime("%d %b %Y %H\:%M\:%S %Z"))
- #strftime because i have no idea how to do it the rrdtool way
- msg("Updated graph (" + graph[0] + ")")
- except Exception, e:
- msg("Error updating graph: %s" % str(e))
Add Comment
Please, Sign In to add comment