<s> import socket <EOL> import time <EOL> import redis <EOL> import shared <EOL> r = redis . StrictRedis ( host = '<STR_LIT:localhost>' , port = <NUM_LIT> , db = <NUM_LIT:0> ) <EOL> b = shared . BatchCounter ( <NUM_LIT:5> , <NUM_LIT> ) <EOL> agg = shared . AggregatorConnector ( ) <EOL> metric = { } <EOL> granularity = <NUM_LIT> <EOL> def process_data ( data ) : <EOL> global metric <EOL> if data [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> time = ( ( data [ '<STR_LIT:time>' ] / <NUM_LIT:1000> ) / granularity ) * granularity <EOL> TIME_LENGTH = <NUM_LIT:10> <EOL> try : <EOL> metric [ "<STR_LIT>" % ( time , data [ '<STR_LIT:host>' ] ) ] += <NUM_LIT:1> <EOL> except : <EOL> metric [ "<STR_LIT>" % ( time , data [ '<STR_LIT:host>' ] ) ] = <NUM_LIT:1> <EOL> if b . check ( ) : <EOL> for k , v in metric . items ( ) : <EOL> time , host = k [ <NUM_LIT:0> : <NUM_LIT:10> ] , k [ <NUM_LIT:11> : ] <EOL> r . zincrby ( time + "<STR_LIT>" , host , v ) <EOL> metric . clear ( ) <EOL> while True : <EOL> for d in agg . json_read ( ) : <EOL> process_data ( d ) </s>
