<s> """<STR_LIT>""" <EOL> from diamond . collector import Collector <EOL> import diamond . convertor <EOL> import os <EOL> class MemoryLxcCollector ( Collector ) : <EOL> def get_default_config_help ( self ) : <EOL> """<STR_LIT>""" <EOL> config_help = super ( MemoryLxcCollector , self ) . get_default_config_help ( ) <EOL> config_help . update ( { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> return config_help <EOL> def get_default_config ( self ) : <EOL> """<STR_LIT>""" <EOL> config = super ( MemoryLxcCollector , self ) . get_default_config ( ) <EOL> config . update ( { <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> return config <EOL> def collect ( self ) : <EOL> """<STR_LIT>""" <EOL> lxc_metrics = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> if os . path . isdir ( self . config [ "<STR_LIT>" ] ) is False : <EOL> self . log . debug ( "<STR_LIT>" , <EOL> self . config [ "<STR_LIT>" ] ) <EOL> return { } <EOL> collected = { } <EOL> for item in os . listdir ( self . config [ "<STR_LIT>" ] ) : <EOL> fpath = "<STR_LIT>" % ( self . config [ "<STR_LIT>" ] , item ) <EOL> if os . path . isdir ( fpath ) is False : <EOL> continue <EOL> for lxc_metric in lxc_metrics : <EOL> filename = "<STR_LIT>" % ( fpath , lxc_metric ) <EOL> metric_name = "<STR_LIT>" % ( <EOL> item . replace ( "<STR_LIT:.>" , "<STR_LIT:_>" ) , <EOL> lxc_metric . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . log . debug ( "<STR_LIT>" , filename ) <EOL> collected [ metric_name ] = self . _read_file ( filename ) <EOL> for key in collected . keys ( ) : <EOL> if collected [ key ] is None : <EOL> continue <EOL> for unit in self . config [ "<STR_LIT>" ] : <EOL> value = diamond . convertor . binary . convert ( <EOL> collected [ key ] , <EOL> oldUnit = "<STR_LIT:B>" , <EOL> newUnit = unit ) <EOL> new_key = "<STR_LIT>" % ( key , unit ) <EOL> self . log . debug ( "<STR_LIT>" , new_key , value ) <EOL> self . publish ( new_key , value , metric_type = "<STR_LIT>" ) <EOL> def _read_file ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> with open ( filename , "<STR_LIT:r>" ) as fhandle : <EOL> stats = float ( fhandle . readline ( ) . rstrip ( "<STR_LIT:\n>" ) ) <EOL> except Exception as exception : <EOL> stats = None <EOL> return stats </s>
