Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 103 lines (85 sloc) 2.88 KB
# Developed by Roman Arkharov, 05.2013
This file is a update script for RRD monitoring tool for Quickpong server.
Script depends on psutils and rrdtools.
import urllib2
import psutil
import rrdtool
basepath = '/usr/home/pythonuser/projects/quickpong_122012/scripts/'
gamesdb = basepath + 'quickponggames.rrd'
cpudb = basepath + 'quickpongcpu.rrd'
memorydb = basepath + 'quickpongram.rrd'
gamespng = basepath + 'quickponggames.png'
cpupng = basepath + 'quickpongcpu.png'
memorypng = basepath + 'quickpongram.png'
#quickpong_stats_url = ''
quickpong_stats_url = 'http://localhost:10082/'
pidfile = '/usr/home/pythonuser/projects/github/quickpong/'
f = open(pidfile, 'r+')
pid =
data = urllib2.urlopen(quickpong_stats_url).read()
gamers, games = data.split(',')
print gamers, games
res = rrdtool.update(gamesdb, "N:" + gamers + ":" + games)
if res:
print rrdtool.error()
rrdtool.graph(gamespng, "--start", "-1d", "--vertical-label=gamers and games",
"DEF:gamers=" + gamesdb + ":gamers:AVERAGE:step=1",
"DEF:games=" + gamesdb + ":games:AVERAGE:step=1",
"GPRINT:gamers:AVERAGE:Avg gamers online\: %6.2lf",
"GPRINT:gamers:MAX:Max gamers online\: %6.2lf",
"GPRINT:gamers:LAST:Last gamers online\: %6.2lf",
"GPRINT:games:AVERAGE:Avg games\: %6.2lf",
"GPRINT:games:MAX:Max games\: %6.2lf",
"GPRINT:games:LAST:Last games\: %6.2lf")
p = psutil.Process(int(pid))
rss, vms = p.get_memory_info()
print rss, vms
res = rrdtool.update(memorydb, "N:" + str(rss) + ":" + str(vms))
if res:
print rrdtool.error()
rrdtool.graph(memorypng, "--start", "-1d", "--vertical-label=rss and vms in Mb",
"DEF:rss=" + memorydb + ":rss:AVERAGE:step=1",
"DEF:vms=" + memorydb + ":vms:AVERAGE:step=1",
"GPRINT:rssmb:AVERAGE:Avg RSS\: %6.2lf %SMb",
"GPRINT:rssmb:MAX:Max RSS\: %6.2lf %SMb",
"GPRINT:rssmb:LAST:Last RSS\: %6.2lf %SMb",
"GPRINT:vmsmb:AVERAGE:Avg VMS\: %6.2lf %SMb",
"GPRINT:vmsmb:MAX:Max VMS\: %6.2lf %SMb",
"GPRINT:vmsmb:LAST:Last VMS\: %6.2lf %SMb")
cpu_percent = p.get_cpu_percent()
print cpu_percent
res = rrdtool.update(cpudb, "N:" + str(cpu_percent))
if res:
print rrdtool.error()
rrdtool.graph(cpupng, "--start", "-1d", "--vertical-label=CPU",
"DEF:cpu=" + cpudb + ":cpu:AVERAGE:step=1",
"GPRINT:cpu:AVERAGE:Avg CPU usage\: %6.2lf",
"GPRINT:cpu:MIN:Min CPU usage\: %6.2lf",
"GPRINT:cpu:MAX:Max CPU usage\: %6.2lf",
"GPRINT:cpu:LAST:Last CPU usage\: %6.2lf")