(conn)
return rows
Return metrics about replicas.
Return metrics about replicas.
Return metrics about replicas .
def get_replica_metrics(conn):
    # type: (rethinkdb.net.Connection) -> List[tuple]
    """
    Return metrics about replicas.
    """
    table_status = SYSTEM.table(
        'table_status',
        # Required so that we can join on 'server_config' below without having to look up UUIDs from names.
        # See: https://rethinkdb.com/api/python/table/#description
        identifier_format='uuid',
    )

    results = (
        # Grab table statuses with shards and replica info.
        table_status.pluck('id', {'shards': ['replicas']})
        # table_status -> [shard1, shard2, ...]
        .concat_map(lambda row: row['shards'].map(lambda shard: row.merge(shard.pluck('replicas'))))
        .without('shards')
        # [shard1, shard2,...] -> [replica1_1, replica1_2, ..., replica2_1, replica2_2, ...]
        .concat_map(
            lambda row: (row['replicas'].map(lambda replica: row.merge({'replica': replica.pluck('server', 'state')})))
        )
        .without('replicas')
        # Attach table info to each replica.
        .merge({'table': TABLE_CONFIG.get(r.row['id']).pluck('id', 'db', 'name')})
        # Attach server info to each replica.
        .merge({'server': SERVER_CONFIG.get(r.row['replica']['server'])})
        .filter(r.row['server'])  # Skip replicas stored on disconnected servers.
        .merge({'server': r.row['server'].pluck('id', 'name', 'tags')})
        # Attach statistics to each replica.
        # See: https://rethinkdb.com/docs/system-stats/#replica-tableserver-pair
        .merge(
            {
                'stats': STATS.get(['table_server', r.row['table']['id'], r.row['server']['id']]).pluck(
                    'query_engine', 'storage_engine'
                ),
            }
        )
    ).run(conn)

    rows = []  # type: List[tuple]

    for document in results:
        row = (
            document['table']['name'],
            document['table']['db'],
            document['server']['name'],
            document['server']['tags'],
            document['replica']['state'],
            document['stats']['query_engine']['read_docs_per_sec'],
            document['stats']['query_engine']['read_docs_total'],
            document['stats']['query_engine']['written_docs_per_sec'],
            document['stats']['query_engine']['written_docs_total'],
            document['stats']['storage_engine']['cache']['in_use_bytes'],
            document['stats']['storage_engine']['disk']['read_bytes_per_sec'],
            document['stats']['storage_engine']['disk']['read_bytes_total'],
            document['stats']['storage_engine']['disk']['written_bytes_per_sec'],
            document['stats']['storage_engine']['disk']['written_bytes_total'],
            document['stats']['storage_engine']['disk']['space_usage']['metadata_bytes'],
            document['stats']['storage_engine']['disk']['space_usage']['data_bytes'],
            document['stats']['storage_engine']['disk']['space_usage']['garbage_bytes'],
            document['stats']['storage_engine']['disk']['space_usage']['preallocated_bytes'],
        )
        rows.append(row)

    return rows
def get_replica_metrics ( conn ) : # type: (rethinkdb.net.Connection) -> List[tuple] table_status = SYSTEM . table ( 'table_status' , # Required so that we can join on 'server_config' below without having to look up UUIDs from names. # See: https://rethinkdb.com/api/python/table/#description identifier_format = 'uuid' , ) results = ( # Grab table statuses with shards and replica info. table_status . pluck ( 'id' , { 'shards' : [ 'replicas' ] } ) # table_status -> [shard1, shard2, ...] . concat_map ( lambda row : row [ 'shards' ] . map ( lambda shard : row . merge ( shard . pluck ( 'replicas' ) ) ) ) . without ( 'shards' ) # [shard1, shard2,...] -> [replica1_1, replica1_2, ..., replica2_1, replica2_2, ...] . concat_map ( lambda row : ( row [ 'replicas' ] . map ( lambda replica : row . merge ( { 'replica' : replica . pluck ( 'server' , 'state' ) } ) ) ) ) . without ( 'replicas' ) # Attach table info to each replica. . merge ( { 'table' : TABLE_CONFIG . get ( r . row [ 'id' ] ) . pluck ( 'id' , 'db' , 'name' ) } ) # Attach server info to each replica. . merge ( { 'server' : SERVER_CONFIG . get ( r . row [ 'replica' ] [ 'server' ] ) } ) . filter ( r . row [ 'server' ] ) # Skip replicas stored on disconnected servers. . merge ( { 'server' : r . row [ 'server' ] . pluck ( 'id' , 'name' , 'tags' ) } ) # Attach statistics to each replica. # See: https://rethinkdb.com/docs/system-stats/#replica-tableserver-pair . merge ( { 'stats' : STATS . get ( [ 'table_server' , r . row [ 'table' ] [ 'id' ] , r . row [ 'server' ] [ 'id' ] ] ) . pluck ( 'query_engine' , 'storage_engine' ) , } ) ) . run ( conn ) rows = [ ] # type: List[tuple] for document in results : row = ( document [ 'table' ] [ 'name' ] , document [ 'table' ] [ 'db' ] , document [ 'server' ] [ 'name' ] , document [ 'server' ] [ 'tags' ] , document [ 'replica' ] [ 'state' ] , document [ 'stats' ] [ 'query_engine' ] [ 'read_docs_per_sec' ] , document [ 'stats' ] [ 'query_engine' ] [ 'read_docs_total' ] , document [ 'stats' ] [ 'query_engine' ] [ 'written_docs_per_sec' ] , document [ 'stats' ] [ 'query_engine' ] [ 'written_docs_total' ] , document [ 'stats' ] [ 'storage_engine' ] [ 'cache' ] [ 'in_use_bytes' ] , document [ 'stats' ] [ 'storage_engine' ] [ 'disk' ] [ 'read_bytes_per_sec' ] , document [ 'stats' ] [ 'storage_engine' ] [ 'disk' ] [ 'read_bytes_total' ] , document [ 'stats' ] [ 'storage_engine' ] [ 'disk' ] [ 'written_bytes_per_sec' ] , document [ 'stats' ] [ 'storage_engine' ] [ 'disk' ] [ 'written_bytes_total' ] , document [ 'stats' ] [ 'storage_engine' ] [ 'disk' ] [ 'space_usage' ] [ 'metadata_bytes' ] , document [ 'stats' ] [ 'storage_engine' ] [ 'disk' ] [ 'space_usage' ] [ 'data_bytes' ] , document [ 'stats' ] [ 'storage_engine' ] [ 'disk' ] [ 'space_usage' ] [ 'garbage_bytes' ] , document [ 'stats' ] [ 'storage_engine' ] [ 'disk' ] [ 'space_usage' ] [ 'preallocated_bytes' ] , ) rows . append ( row ) return rows