Exemplo n.º 1
0
#!/usr/bin/python
import os, sys, time
import commands, re
import glob

from pysqllib import MySqlAccess


if __name__ == '__main__':

    mySqlHdlr = MySqlAccess('10.6.3.5','root','','flowmon')
    fileList = glob.glob("/home/ryu/csvfiles/flow*.Pending")
    for file in fileList:
        print "loading file %s \n" % (file)
        mySqlHdlr.load_file(file,'flow_table')
        os.system('\\rm "%s"' % file)

    fileList = glob.glob("/home/ryu/csvfiles/total*.Pending")
    for file in fileList:
        print "loading file %s \n" % (file)
        mySqlHdlr.load_file(file,'total_stats_table', ignoreHeader=False)
        os.system('\\rm "%s"' % file)
Exemplo n.º 2
0
    sorted_dict_txbytes = sorted(dictTable.items(), key = lambda x: x[1]['tx_bytes'], reverse=True)

#        print "avg_tx_rate=%u bps, avg_rx_rate=%u bps\n" % (value['tx_bytes']*8/timeInterval, value['rx_bytes']*8/timeInterval)
#        print "avg_tx_pkt_rate=%u, avg_rx_pkt_rate=%u\n" % (value['tx_pkts']/timeInterval, value['rx_pkts']/timeInterval)

if __name__ == "__main__":
    
    # read the records of all subscribers in the last 300 secs
    # aggregate the records based on subscriber ( 2 dictionaries one for tx and another of rx
    # sort the subscriber list based on tx and rx bytes usage
    # take the last 10 top subs
    print "loading the users config"
    policy = PolicyUser('/home/mravi/dbloader/tf_users.csv')
    pollInterval = 300; # 120 secs
    print "connecting to database"
    mySqlHandler = MySqlAccess('10.6.3.5', 'root','','flowmon')
    print "connected to database"
    currTimeStamp = time.time()

    sqlFetch = "select * from flow_table where LastSeen > %s" 
    args = (currTimeStamp - pollInterval)


    print "fetch records from database"
    records = mySqlHandler.get_records(sqlFetch,args)
    
    print "Processing all records...., pl wait", len(records)
    time1 = time.time()
    currCnt = 0
    for record in records:
        Process_Sub_record(policy,record)