Skip to content

Instantly share code, notes, and snippets.

@diegopacheco
Created October 10, 2011 21:51
Show Gist options
  • Save diegopacheco/1276666 to your computer and use it in GitHub Desktop.
Save diegopacheco/1276666 to your computer and use it in GitHub Desktop.
Python Redimon All interfaces sample: app.run(host='10.99.2.84', port=5000, debug=True)
from flask import Flask, render_template, jsonify
from lib.stats import RedisMonitor
from settings import SERVERS
try:
import json
except:
import simplejson as json
import datetime
redis_monitor = RedisMonitor(SERVERS)
# initialize flask application
app = Flask(__name__)
# main view
@app.route('/')
def index():
stats = redis_monitor.getStats()
return render_template('main.html', stats = stats)
# ajax view (json)
@app.route('/ajax')
def ajax():
stats = redis_monitor.getStats(True)
datetimeHandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else None
return json.dumps(stats, default = datetimeHandler)
# run the app.
if __name__ == '__main__':
app.debug = True
app.run(host='10.99.2.84', port=5000, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment