Created
October 10, 2011 21:51
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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