<s> import sys <EOL> from munin . postgres import MuninPostgresPlugin <EOL> class MuninPgBouncerPlugin ( MuninPostgresPlugin ) : <EOL> dbname_in_args = False <EOL> default_table = "<STR_LIT>" <EOL> category = "<STR_LIT>" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( MuninPgBouncerPlugin , self ) . __init__ ( * args , ** kwargs ) <EOL> self . dbwatched = sys . argv [ <NUM_LIT:0> ] . rsplit ( '<STR_LIT:_>' , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] <EOL> def connection ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> import psycopg2 <EOL> self . _connection = psycopg2 . connect ( self . dsn ) <EOL> self . _connection . set_isolation_level ( <NUM_LIT:0> ) <EOL> return self . _connection <EOL> def execute ( self ) : <EOL> cursor = self . cursor ( ) <EOL> cursor . execute ( self . command ) <EOL> columns = [ column [ <NUM_LIT:0> ] for column in cursor . description ] <EOL> totals = dict . fromkeys ( ( field [ <NUM_LIT:0> ] for field in self . fields ) , <NUM_LIT:0> ) <EOL> for row in cursor : <EOL> row_dict = dict ( zip ( columns , row ) ) <EOL> if row_dict [ '<STR_LIT>' ] in ( self . dbwatched , self . dbwatched + '<STR_LIT:\x00>' ) : <EOL> for field in self . fields : <EOL> totals [ field [ <NUM_LIT:0> ] ] += row_dict [ field [ <NUM_LIT:0> ] ] <EOL> return dict ( ( field [ <NUM_LIT:0> ] , totals [ field [ <NUM_LIT:0> ] ] ) for field in self . fields ) </s>
