Ejemplo n.º 1
0
def get_stats():

    for log_type in get_log_types():

        db = connect_db(log_type)
        log_stats = db.command("dbstats")

        stats_coll = connect_collection('tools', 'db_stats')
        stats_object = stats_coll.update({'db':log_type}, log_stats, upsert=True)
Ejemplo n.º 2
0
 def tests(self):
     for case in self.test_list:
         case["dumper"].dump(test=True)
         names = connect_db(case["logtype"], local=True).collection_names()
         coll = None
         names.remove("system.indexes")
         try:
             coll = connect_collection(case["logtype"], names[0], local=True)
             self.assertEqual(coll.count() % 5, 0)
             for test in self.test_keys:
                 assert coll.distinct(test) is not 0
         except Exception as e:
             print case["logtype"] + " had an error"
             print str(e)
             pass
Ejemplo n.º 3
0
def print_last_inserts():
    """ return time of last insert for each logtype """

    for log_type in get_log_types():

        newest_coll_name = connect_db(log_type, local=False).collection_names()[-1]
        coll = connect_collection(log_type, newest_coll_name, local=False)

        for document in coll.find().sort([('time', DESCENDING)]).limit(1):
            line = document['line'].split(' ')
            try:
                line.remove('')
            except:
                pass
            print log_type + '\t\t' + str(line[0:3])
Ejemplo n.º 4
0
def compact(test=False):
    """
    Compact (defrag/free) every collection
    """

    for log_type in get_log_types():
        try:
            db = connect_db(log_type, local=test, master=True)

            for coll_name in db.collection_names():
                coll = connect_collection(log_type, coll_name)
                try:
                    print "compacting " + coll_name
                    db.eval("db.runCommand({ compact : '%s'})" % (coll_name))
                except Exception as e:
                    print str(e)
                    continue

        except Exception as e:
            print str(e)
            continue
Ejemplo n.º 5
0
#    for log_type in get_log_types():
>>>>>>> Stashed changes
    for log_type in ['aruba']:

        # find all collections in the database
        database = connect_db(log_type, local=True)
        collnames = database.collection_names()
        try:
            collnames.remove('system.indexes')
            collnames.remove('system.users')
        except:
            pass

        # loop over collections names
        for collname in collnames:
            collection = connect_collection(log_type, collname, local=True)
<<<<<<< Updated upstream
>>>>>>> Stashed changes
=======
>>>>>>> Stashed changes

    # use map/reduce to count the frequency of each field
    result = collection.map_reduce(map_fn, reduce_fn, "key_frequency")

<<<<<<< Updated upstream
    # print out the summary data
    print coll_name.center(60, '=')
    for item in result.find():
        key = item['_id']
        count = int(item['value'])
        freq = (count / float(total)) * 100.0