Exemplo n.º 1
0
def magic_time(stuff):
    if type(stuff) == datetime:
        return time.mktime(stuff.timetuple())
    elif type(stuff) == str:
        return time.mktime(parseATTime(stuff).timetuple())
    elif type(stuff) == int:
        return stuff
    elif type(stuff) == float:
        return stuff
    raise Exception("Bad argument type")
Exemplo n.º 2
0
def magic_time(stuff):
    if type(stuff) == datetime:
        return time.mktime(stuff.timetuple())
    elif type(stuff) == str:
        return time.mktime(parseATTime(stuff).timetuple())
    elif type(stuff) == int:
        return stuff
    elif type(stuff) == float:
        return stuff
    raise Exception("Bad argument type")
Exemplo n.º 3
0
def render():
    if 'from' in request.query:
        fromTime = parseATTime(request.query['from'])
    else:
        fromTime = parseATTime('-1d')
    if 'until' in request.query:
        untilTime = parseATTime(request.query.until)
    else:
        untilTime = parseATTime('now')

    targets = request.query.getall('target')

    if 'format' in request.query:
        format_ = request.query.format
    else:
        format_ = 'json'

    store = app.config['store']

    requestContext = {
        'startTime': fromTime,
        'endTime': untilTime,
        'data': [],
        'localOnly': True
    }

    data = []
    for target in targets:
        if not target.strip():
            continue
        data.extend(evaluateTarget(store, requestContext, target))

    if format_ == 'json':
        series_data = []
        for series in data:
            timestamps = range(int(series.start), int(series.end),
                               int(series.step))
            datapoints = zip(series, timestamps)
            series_data.append(dict(target=series.name, datapoints=datapoints))
        response.content_type = "application/json"
        return json.dumps(series_data)
Exemplo n.º 4
0
def render():
    if 'from' in request.query:
        fromTime = parseATTime(request.query['from'])
    else:
        fromTime = parseATTime('-1d')
    if 'until' in request.query:
        untilTime = parseATTime(request.query.until)
    else:
        untilTime = parseATTime('now')

    targets = request.query.getall('target')

    if 'format' in request.query:
        format_ = request.query.format
    else:
        format_ = 'json'

    store = app.config['store']

    requestContext = {'startTime': fromTime,
                      'endTime': untilTime,
                      'data': [],
                      'localOnly': True
                      }

    data = []
    for target in targets:
        if not target.strip():
            continue
        data.extend(evaluateTarget(store, requestContext, target))

    if format_ == 'json':
        series_data = []
        for series in data:
            timestamps = range(int(series.start),
                               int(series.end), int(series.step))
            datapoints = zip(series, timestamps)
            series_data.append(dict(target=series.name, datapoints=datapoints))
        response.content_type = "application/json"
        return json.dumps(series_data)