import logging from flask import render_template, abort, request from sqlalchemy.exc import IntegrityError import redistrib.command from redistrib.connection import Connection from redistrib.exceptions import RedisStatusError from app.bpbase import Blueprint from app.utils import json_response from models.base import db import models.cluster import models.node as nm import models.proxy as pr from models.proxy import TYPE_CORVUS bp = Blueprint('cluster', __name__, url_prefix='/cluster') @bp.before_request def access_control(): if not bp.app.access_ctl_user_valid(): abort(403) @bp.route('/create') def create_cluster(): return render_template('cluster/create.html') @bp.route_post_json('/delete') def delete_cluster():
from flask import request, render_template, abort from datetime import datetime, timedelta from app.bpbase import Blueprint from models.audit import NodeEvent from models.polling_stat import PollingStat from models.task import ClusterTask, TaskStep bp = Blueprint('prune', __name__, url_prefix='/prune') @bp.before_request def access_control(): if not bp.app.access_ctl_user_adv(): abort(403) def xdays_before(x): return datetime.now() - timedelta(days=x) def objects_before(table, column, dt, limit): return table.query.filter(getattr(table, column) < dt).order_by( table.id.desc()).limit(limit).all() def delete_before(table, column, id, dt): obj = table.query.get(id) if getattr(obj, column) < dt: table.query.filter(table.id <= obj.id).delete()
from flask import abort, request from app.bpbase import Blueprint from models.base import db import models.node import models.proxy bp = Blueprint('alarm', __name__, url_prefix='/set_alarm') @bp.before_request def access_control(): if not bp.app.access_ctl_user_valid(): abort(403) def _set_alarm_status(n): if n is None: raise ValueError('no such node') n.suppress_alert = int(request.form['suppress']) db.session.add(n) @bp.route_post_json('/redis', True) def set_redis_alarm(): _set_alarm_status( models.node.get_by_host_port(request.form['host'], int(request.form['port']))) @bp.route_post_json('/proxy', True)
import re import time from flask import render_template, request from app.bpbase import Blueprint from app.utils import json_response bp = Blueprint('stats', __name__, url_prefix='/stats') PAT_HOST = re.compile('^[-.a-zA-Z0-9]+$') REDIS_MAX_FIELDS = [ 'used_cpu_sys', 'used_cpu_user', 'connected_clients', 'total_commands_processed', 'evicted_keys', 'expired_keys', 'keyspace_misses', 'keyspace_hits', 'keys', ] REDIS_AVG_FIELDS = ['used_memory', 'used_memory_rss', 'response_time'] REDIS_FIELDS = {} for f in REDIS_MAX_FIELDS: REDIS_FIELDS[f] = 'MAX' for f in REDIS_AVG_FIELDS: REDIS_FIELDS[f] = 'AVERAGE' PROXY_MAX_FIELDS = ['connected_clients', 'mem_buffer_alloc', 'completed_commands', 'used_cpu_sys', 'used_cpu_user'] PROXY_AVG_FIELDS = ['command_elapse', 'remote_cost'] PROXY_FIELDS = {} for f in PROXY_MAX_FIELDS: PROXY_FIELDS[f] = 'MAX' for f in PROXY_AVG_FIELDS: PROXY_FIELDS[f] = 'AVERAGE'
import json from flask import request, abort from hiredis import ReplyError from redistrib.connection import Connection from redistrib.command import list_masters from app.utils import json_response from app.bpbase import Blueprint import models.audit bp = Blueprint('command', __name__, url_prefix='/cmd') @bp.before_request def access_control(): if not bp.app.access_ctl_user_valid(): abort(403) def _simple_cmd(host, port, *command): status = 200 try: with Connection(host, port) as t: try: r = t.talk(*command) except ReplyError as e: r = {'reason': e.message} status = 400 except IOError: status = 400 r = {'reason': 'not reachable'}
import os.path from flask import safe_join, send_file from app.bpbase import Blueprint from app.utils import json_response bp = Blueprint('translation', __name__) @bp.route('/trans/<path>') def translation(path): p = safe_join('static/trans', path) if os.path.exists(p): return send_file(p, mimetype='text/javascript', conditional=True) return json_response({})
from flask import render_template, g from app.bpbase import Blueprint import models.audit bp = Blueprint('audit', __name__, url_prefix='/audit') @bp.route('/nodes') def node_events(): return render_template('audit/nodes.html', page=g.page, events=models.audit.list_events(g.page * 50, 50))
import time import threading import logging from flask import request, render_template, g, abort from sqlalchemy.exc import IntegrityError from redistrib.connection import Connection from app.bpbase import Blueprint from app.utils import json_response import models.cluster import models.node import models.proxy import models.audit import models.cont_image bp = Blueprint('containerize', __name__, url_prefix='/containerize') @bp.before_request def access_control(): if not bp.app.access_ctl_user_valid(): abort(403) @bp.route('/') def manage_home(): pods = bp.app.container_client.list_pods() if len(pods) == 0: return render_template('containerize/deploy/no_pod.html'), 400 return render_template( 'containerize/deploy/manage.html', pods=pods,
from flask import render_template, abort, request from app.utils import json_response from app.bpbase import Blueprint import models.node import models.audit bp = Blueprint('redis', __name__, url_prefix='/redis') @bp.before_request def access_control(): if not bp.app.access_ctl_user_valid(): abort(403) @bp.route('/panel/<host>/<int:port>') def node_panel(host, port): node = models.node.get_by_host_port(host, port) if node is None: return render_template('redis/not_found.html', host=host, port=port), 404 return render_template( 'redis/panel.html', node=node, max_mem_limit=bp.app.config_node_max_mem) @bp.route('/register') def register_redis(): return render_template('redis/create.html')
from flask import render_template from app.bpbase import Blueprint from models.polling_stat import PollingStat bp = Blueprint('pollings', __name__) @bp.route('/stats/pollings') def pollings(): return render_template('pollings.html', pollings=PollingStat.query.order_by( PollingStat.id.desc()).limit(120))
import redistrib from flask import render_template, abort, request, g from app.bpbase import Blueprint from app.utils import json_response from app.render_utils import f_strftime from models.base import db import models.node import models.task bp = Blueprint('task', __name__, url_prefix='/task') @bp.before_request def access_control(): if not bp.app.access_ctl_user_valid(): abort(403) @bp.route('/list_all') def list_all_tasks(): return render_template('cluster/tasks_all.html', page=g.page, tasks=models.task.get_all_tasks(g.page * 50, 50)) @bp.route('/list_cluster/<int:cluster_id>') def list_cluster_tasks(cluster_id): c = models.cluster.get_by_id(cluster_id) if c is None: return abort(404)
from flask import render_template from app.bpbase import Blueprint import models.node as nm import models.cluster as cl bp = Blueprint('index', __name__) @bp.route('/') def index(): nodes = nm.list_all_nodes() clusters = cl.list_all() poll_result = bp.app.polling_result() node_details = poll_result['nodes'] proxy_details = poll_result['proxies'] proxies = [] for c in clusters: for p in c.proxies: p.detail = proxy_details.get('%s:%d' % (p.host, p.port), {}) p.stat = p.detail.get('stat', True) proxies.extend(c.proxies) for n in nodes: detail = node_details.get('%s:%d' % (n.host, n.port), {}) n.node_id = detail.get('node_id') n.detail = detail n.stat = detail.get('stat', True) return render_template('index.html',