Added scripts to list total messagecounts and an analysis of messages
This commit is contained in:
24
utils/pymongo/messagecount
Executable file
24
utils/pymongo/messagecount
Executable file
@ -0,0 +1,24 @@
|
||||
#!/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']
|
||||
|
||||
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))
|
35
utils/pymongo/messagestatistics
Executable file
35
utils/pymongo/messagestatistics
Executable file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import pymongo
|
||||
import datetime
|
||||
import time
|
||||
import sys
|
||||
|
||||
from pymongo import MongoClient
|
||||
from datetime import timedelta
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print('Usage:\n\terrorstatistics instrument')
|
||||
sys.exit()
|
||||
|
||||
inst = sys.argv[1]
|
||||
|
||||
mongodb = MongoClient('mongodb://logwriter:sinqsics@mpc1965:27017/?authSource=admin')
|
||||
|
||||
totime = datetime.datetime.today()
|
||||
totime = datetime.datetime(totime.year,totime.month,totime.day)
|
||||
fromtime = totime - timedelta(1)
|
||||
|
||||
messagedict = {}
|
||||
db = mongodb[inst]
|
||||
for entry in db.log.find({"timestamp" : {"$gt": time.mktime(fromtime.timetuple()),
|
||||
"$lt" : time.mktime(totime.timetuple())} }):
|
||||
mes = entry['message']
|
||||
if messagedict.has_key(mes):
|
||||
messagedict[mes] = messagedict[mes] + 1
|
||||
else:
|
||||
messagedict[mes] = 1
|
||||
|
||||
|
||||
for mes in sorted(messagedict, key=messagedict.get):
|
||||
print('%8d %s' %(messagedict[mes], mes ))
|
Reference in New Issue
Block a user