def get_stats(host, metric):
    only_latest = False
    cf = request.args.get('cf', 'AVERAGE')
    step = request.args.get('step', 15)
    start = request.args.get('start')
    if start is None:
        only_latest = True
        start = '-%s' % step
        end = -1
    else:
        end = request.args.get('end', -1)
    ret = cache.read(str(host), str(metric), str(cf).upper(), 
                     int(step), int(start), int(end))
    if only_latest:
        return encode([ret[0]] + [[i for i in ret[1] if i[1] is not None][-1]])
    else:
        return encode(ret)
def get_metric_list(host):
    rc, metric_list = mon_server.metricList(host)
    if rc == 0:
        abort(404)
    #metric = request.args.get('metric')
    #if metric is not None:
        #if '-' in metric: prefix, metric = metric.split('-')
        #for mg in metric_list:
            #for mc in mg['metrics']:
                #if mc['name'] == metric:
                    #return encode(mc)
        #abort(404)
    return encode(metric_list)
def get_host_list():
    rc, host_list = mon_server.hostList()
    if rc == 0:
        abort(404)
    return encode(host_list)