Statistics
Index
Methods
__aenter__
Subscribe to events and start collecting statistics.
Returns Self
__aexit__
Stop collecting statistics.
Parameters
optionalkeyword-onlyexc_type: type[BaseException] | None
optionalkeyword-onlyexc_value: BaseException | None
optionalkeyword-onlyexc_traceback: TracebackType | None
Returns None
__init__
Parameters
optionalkeyword-onlypersistence_enabled: bool = False
optionalkeyword-onlypersist_state_kvs_name: str = 'default'
optionalkeyword-onlypersist_state_key: str | None = None
optionalkeyword-onlykey_value_store: KeyValueStore | None = None
optionalkeyword-onlylog_message: str = 'Statistics'
optionalkeyword-onlyperiodic_message_logger: Logger | None = None
optionalkeyword-onlylog_interval: timedelta = timedelta(minutes=1)
optionalkeyword-onlystate_model: type[TStatisticsState] = cast(Any, StatisticsState)
Returns None
calculate
Calculate the current statistics.
Returns FinalStatistics
record_request_processing_failure
Mark a request as failed.
Parameters
optionalkeyword-onlyrequest_id_or_key: str
Returns None
record_request_processing_finish
Mark a request as finished.
Parameters
optionalkeyword-onlyrequest_id_or_key: str
Returns None
record_request_processing_start
Mark a request as started.
Parameters
optionalkeyword-onlyrequest_id_or_key: str
Returns None
register_status_code
Increment the number of times a status code has been received.
Parameters
optionalkeyword-onlycode: int
Returns None
reset
Reset the statistics to their defaults and remove any persistent state.
Returns None
Properties
active
Indicate whether the context is active.
A class for collecting, tracking, and logging runtime statistics for requests.
It is designed to record information such as request durations, retries, successes, and failures, enabling analysis of crawler performance. The collected statistics are persisted to a
KeyValueStore
, ensuring they remain available across crawler migrations, abortions, and restarts. This persistence allows for tracking and evaluation of crawler behavior over its lifecycle.