RPCRequestStats

Documentation for eth_defi.provider.rpcdb.RPCRequestStats Python class.

class RPCRequestStats

Bases: object

Thread-safe, pickle-safe physical JSON-RPC request counters.

calls is keyed by (rpc_provider_domain, api_call) and errors by (rpc_provider_domain, error_code, error_message). The lock is excluded from pickle state and recreated in subprocesses.

Attributes summary

calls

Provider-domain and JSON-RPC method counts.

errors

Provider-domain, error-code and error-message counts.

Methods summary

__init__([calls, errors])

export()

Take a detached copy of both counter mappings.

merge(other)

Merge another worker or phase aggregate exactly once.

record_call(rpc_provider_domain, api_call[, ...])

Record physical JSON-RPC request attempts.

record_error(rpc_provider_domain, ...[, count])

Record JSON-RPC request failures.

calls: collections.Counter[tuple[str, str]]

Provider-domain and JSON-RPC method counts.

errors: collections.Counter[tuple[str, str, str]]

Provider-domain, error-code and error-message counts.

record_call(rpc_provider_domain, api_call, count=1)

Record physical JSON-RPC request attempts.

Parameters
  • rpc_provider_domain (str) – Provider hostname, optionally including a non-default port.

  • api_call (str) – JSON-RPC method name such as eth_call.

  • count (int) – Positive number of attempts to add.

Return type

None

record_error(rpc_provider_domain, error_code, error_message, count=1)

Record JSON-RPC request failures.

Parameters
  • rpc_provider_domain (str) – Provider hostname, optionally including a non-default port.

  • error_code (str) – Stable JSON-RPC, HTTP, or exception-class error code.

  • error_message (str) – Provider error message.

  • count (int) – Positive number of matching failures to add.

Return type

None

merge(other)

Merge another worker or phase aggregate exactly once.

Parameters

other (eth_defi.provider.rpcdb.RPCRequestStats) – Detached task statistics to add to this accumulator.

Return type

None

export()

Take a detached copy of both counter mappings.

Returns

Copied call and error counters safe to iterate without holding the accumulator lock.

Return type

tuple[collections.Counter[tuple[str, str]], collections.Counter[tuple[str, str, str]]]

__init__(calls=<factory>, errors=<factory>)
Parameters
Return type

None