Skip to main content
Version: 3.0

Statistics

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 SDK_CRAWLER_STATISTICS_*, persists between migrations and abort/resurrect

Index

Properties

readonlyid

id: number = ...

Statistic instance id.

readonlyrequestRetryHistogram

requestRetryHistogram: number[] = []

Contains the current retries histogram. Index 0 means 0 retries, index 2, 2 retries, and so on

state

state: StatisticState

Current statistic state used for doing calculations on Statistics.calculate calls

Methods

calculate

  • calculate(): { crawlerRuntimeMillis: number; requestAvgFailedDurationMillis: number; requestAvgFinishedDurationMillis: number; requestTotalDurationMillis: number; requestsFailedPerMinute: number; requestsFinishedPerMinute: number; requestsTotal: number }
  • Calculate the current statistics


    Returns { crawlerRuntimeMillis: number; requestAvgFailedDurationMillis: number; requestAvgFinishedDurationMillis: number; requestTotalDurationMillis: number; requestsFailedPerMinute: number; requestsFinishedPerMinute: number; requestsTotal: number }

    • crawlerRuntimeMillis: number
    • requestAvgFailedDurationMillis: number
    • requestAvgFinishedDurationMillis: number
    • requestTotalDurationMillis: number
    • requestsFailedPerMinute: number
    • requestsFinishedPerMinute: number
    • requestsTotal: number

persistState

  • persistState(): Promise<void>
  • Persist internal state to the key value store


    Returns Promise<void>

reset

  • reset(): void
  • Set the current statistic instance to pristine values


    Returns void

startCapturing

  • startCapturing(): Promise<void>
  • Initializes the key value store for persisting the statistics, displaying the current state in predefined intervals


    Returns Promise<void>

stopCapturing

  • stopCapturing(): Promise<void>
  • Stops logging and remove event listeners, then persist


    Returns Promise<void>

toJSON

  • toJSON(): StatisticPersistedState
  • Make this class serializable when called with JSON.stringify(statsInstance) directly or through keyValueStore.setValue('KEY', statsInstance)


    Returns StatisticPersistedState