Statistics <StateExtension, PersistedStateExtension>
Implements
- IStatistics<StateExtension>
Index
Constructors
constructor
Construct a statistics instance to pass to a crawler via its
statisticsoption, e.g. to preconfigure persistence or error snapshots, share it across sequential runs, or track extra fields viastate.Parameters
options: StatisticsOptions<StateExtension, PersistedStateExtension> = {}
Returns Statistics<StateExtension, PersistedStateExtension>
Properties
readonlyerrorTracker
An error tracker for final retry errors.
readonlyerrorTrackerRetry
An error tracker for retry errors prior to the final retry.
readonlyid
Statistic instance id.
Accessors
requestRetryHistogram
Contains the current retries histogram. Index 0 means 0 retries, index 2, 2 retries, and so on
Returns number[]
state
Current statistic state used for doing calculations on Statistics.calculate calls
Returns StatisticState & StateExtension
Methods
calculate
Calculate the current statistics
Returns CalculatedStatistics
persistState
Persist internal state to the key value store.
Statistics are bookkeeping - a store that refuses the write is worth a warning, not a failed crawl. The crawler calls this from its migration handler, where a rejection would go unhandled.
Returns Promise<void>
registerStatusCode
Increments the status code counter.
Parameters
code: number
Returns void
reset
Set the current statistic instance to pristine values.
The persisted record is left alone - use Statistics.resetStore to clear that as well.
Returns void
resetStore
Clear the persisted statistics record, leaving the in-memory state alone.
Throws while capturing - the next PERSIST_STATE event would write the record straight back.
Returns Promise<void>
startCapturing
Initializes the key value store for persisting the statistics, displaying the current state in predefined intervals
Returns Promise<void>
stopCapturing
Stops logging and remove event listeners, then persist
Returns Promise<void>
toJSON
Make this class serializable when called with
JSON.stringify(statsInstance)directly or throughkeyValueStore.setValue('KEY', statsInstance)Returns StatisticPersistedState & PersistedStateExtension
The statistics class provides an interface to collecting and logging run statistics for requests.
All statistic information is saved on key value store under the key
CRAWLEE_CRAWLER_STATISTICS_*, persists between migrations and abort/resurrectCustom fields are tracked by passing
stateExtension- the extra fields are then part ofstate, persisted and restored along with the built-in ones.