<s> """<STR_LIT>""" <EOL> import struct <EOL> from graphite import GraphiteHandler <EOL> try : <EOL> import cPickle as pickle <EOL> except ImportError : <EOL> import pickle as pickle <EOL> class GraphitePickleHandler ( GraphiteHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , config = None ) : <EOL> """<STR_LIT>""" <EOL> GraphiteHandler . __init__ ( self , config ) <EOL> self . batch = [ ] <EOL> self . batch_size = int ( self . config [ '<STR_LIT>' ] ) <EOL> def get_default_config_help ( self ) : <EOL> """<STR_LIT>""" <EOL> config = super ( GraphitePickleHandler , self ) . get_default_config_help ( ) <EOL> config . update ( { <EOL> } ) <EOL> return config <EOL> def get_default_config ( self ) : <EOL> """<STR_LIT>""" <EOL> config = super ( GraphitePickleHandler , self ) . get_default_config ( ) <EOL> config . update ( { <EOL> '<STR_LIT:port>' : <NUM_LIT> , <EOL> } ) <EOL> return config <EOL> def process ( self , metric ) : <EOL> m = ( metric . path , ( metric . timestamp , metric . value ) ) <EOL> self . batch . append ( m ) <EOL> if len ( self . batch ) >= self . batch_size : <EOL> self . log . debug ( "<STR_LIT>" , <EOL> self . batch_size ) <EOL> self . metrics = [ self . _pickle_batch ( ) ] <EOL> self . _send ( ) <EOL> self . flush ( ) <EOL> self . batch = [ ] <EOL> def _pickle_batch ( self ) : <EOL> """<STR_LIT>""" <EOL> payload = pickle . dumps ( self . batch ) <EOL> header = struct . pack ( "<STR_LIT>" , len ( payload ) ) <EOL> message = header + payload <EOL> return message </s>
