Exemplo n.º 1
0
def get_instance_recently_perf(instance_name, seconds):
    db = get_database()
    perf_recently = db.instance_perf_recently
    
    max_timestamp_cursor = perf_recently.find({'name' : instance_name}).\
                sort([('timestamp', pymongo.DESCENDING)]).limit(1)
    
    max_timestamp_list = [i for i in max_timestamp_cursor]
    if len(max_timestamp_list) == 0:
        return []
    
    max_timestamp = max_timestamp_list[0]['timestamp'] + 1
    min_timestamp = max_timestamp - seconds
    
    recently_perf_cursor = perf_recently.find({'name' : instance_name, 
            'timestamp' : {"$lt" : max_timestamp, "$gt" : min_timestamp}})
    recently_perf_list = [i for i in recently_perf_cursor]
    
    return recently_perf_list
Exemplo n.º 2
0
def get_instance_statistic(instance_name):
    db = get_database()
    return db.instance_statistic.find_one({'name' : instance_name})
Exemplo n.º 3
0
def update_instance_statistic_data(statistic_data, datetime):
    db = get_database()
    statistic_data['last_updated_at'] = datetime
    return db.instance_statistic.update({'host' : statistic_data['name']}, 
                                        {'$set' : statistic_data}, True)
Exemplo n.º 4
0
def save_instance_perf_data(perf_data):
    db = get_database()
    perf_recently = db.instance_perf_recently
    return perf_recently.insert(perf_data)
Exemplo n.º 5
0
def update_agent_status(host, datetime):
    db = get_database()
    return db.agent_status.update({'host' : host}, 
                                  {'$set' : {'last_updated_at' : datetime}}, True)