#!/usr/bin/python

import pymongo
import datetime
import time

from pymongo import MongoClient
from datetime import timedelta

mongodb = MongoClient('mongodb://logwriter:sinqsics@mpc1965:27017/?authSource=admin')

dblist = ['amor', 'boa', 'dmc', 'eiger', 'focus', 'hrpt', 'morpheus', 
       'narziss', 'orion', 'poldi', 'rita2', 'sans', 'sans2', 'tasp', 'zebra'] 

totime = datetime.datetime.today()
totime = datetime.datetime(totime.year,totime.month,totime.day)
fromtime = totime - timedelta(1)

print('Message counts between ' + str(fromtime) + ' to ' + str(totime) )
for inst in dblist:
    db = mongodb[inst]
    ct = db.log.find({"timestamp" : {"$gt": time.mktime(fromtime.timetuple()), 
			 "$lt" : time.mktime(totime.timetuple())} }).count()
    print(inst + ',' + str(ct))			 
