def get_raw_data(args):
    # find raw points in database
    client = InfluxDBClient.from_DSN(args.influx_dsn)
    
    # get series to query
    check_series = {}
    for list_spec in data_spec:
        series = InfluxResult08.query(client, "list series %s" % list_spec)
        check_series[list_spec] = []
        for s in series:
            check_series[list_spec].extend(s.fields.values())

    # query the series and record the results according to the data spec 
    # and command line arguments
    data_points = {}

    for list_spec in check_series:
        for series in check_series[list_spec]:
            query = """SELECT 
                        mean("%s") AS "used", 
                        mean("%s") AS "capacity"
                       FROM %s 
                       WHERE time > now() - %sd
                       GROUP BY time(%sd) ORDER ASC""" % \
                       (data_spec[list_spec]['used'], 
                        data_spec[list_spec]['capacity'],
                        series, args.range, args.interval)

            res = InfluxResult08.query(client, query)
            for ts in res:
                ts.tags['bytes_factor'] = data_spec[list_spec]['bytes_factor']
            data_points[series] = res

    return data_points
Пример #2
0
def find_first_point(dsn, search, interval=None):
    """Connect to an InfluxDB instance and find the first point in each series
       optionally within the given intervala
            Arguments:
                dsn: an InflxDBClient DSN, for example:
                    influxdb://username:password@localhost:8086/database
                search: series name or regex to search against
                interval: length of history to search
            Return: A list of InfluxResult objects representing the points
    """
    client = InfluxDBClient.from_DSN(dsn)

    if interval is not None:
        where = "WHERE time > now() - %s" % (interval)
    else:
        where = ""
    query = "SELECT * FROM %s %s LIMIT 1 ORDER ASC" % \
            (search, where)
    query_res = client.query(query)
    result_objs = InfluxResult08.from_query(query_res)

    return result_objs