@app.route('/stats', defaults={'clusterid': None})
@app.route('/stats/<clusterid>')
@login_required
def stalker_stats(clusterid):
    """Obtain stats for this cluster or one with a given clusterid"""
    default = {'qsize': None, 'failing': None, 'flapping': None,
               'suspended': None, 'checks': None, 'pending': None}
    if not clusterid:
        q = _get_local_metrics()
        if q:
            return jsonify({app.config['LOCAL_CID']: q})
        else:
            return jsonify({app.config['LOCAL_CID']: default})
    else:
        if clusterid in app.config['GLOBAL_CLUSTERS']:
            ckey = '%s:%s' % (clusterid, 'stats')
            cached = cache.get(ckey)
            if cached:
                return jsonify({clusterid: cached})
            else:
                q = _get_remote_stats(clusterid)
                if q:
                    cache.set(ckey, q)
                    return jsonify({clusterid: q})
                else:
                    return jsonify({clusterid: default})
        elif clusterid == 'all':
            q = {}
            q[app.config['LOCAL_CID']] = _get_local_metrics()
            for cid in app.config['GLOBAL_CLUSTERS'].keys():
                ckey = '%s:%s' % (cid, 'stats')
                cached = cache.get(ckey)
                if cached:
                    q[cid] = cached
                else:
                    q[cid] = _get_remote_stats(cid)
                    if not q[cid]:
                        q[cid] = default
                    cache.set(ckey, q[cid])
            return jsonify({'all': q})
        else:
            abort(404)
dataset/ETHPy150Open pandemicsyn/stalker/stalkerweb/stalkerweb/views.py/stalker_stats/original