@crawlee/core 4.0.0-beta.12 → 4.0.0-beta.121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -13
- package/autoscaling/autoscaled_pool.d.ts +67 -172
- package/autoscaling/autoscaled_pool.js +165 -320
- package/autoscaling/client_load_signal.d.ts +55 -0
- package/autoscaling/client_load_signal.js +73 -0
- package/autoscaling/concurrency_system.d.ts +268 -0
- package/autoscaling/concurrency_system.js +351 -0
- package/autoscaling/cpu_load_signal.d.ts +43 -0
- package/autoscaling/cpu_load_signal.js +47 -0
- package/autoscaling/event_loop_load_signal.d.ts +51 -0
- package/autoscaling/event_loop_load_signal.js +60 -0
- package/autoscaling/index.d.ts +6 -1
- package/autoscaling/index.js +6 -1
- package/autoscaling/load_signal.d.ts +99 -0
- package/autoscaling/load_signal.js +104 -0
- package/autoscaling/memory_load_signal.d.ts +47 -0
- package/autoscaling/memory_load_signal.js +106 -0
- package/autoscaling/snapshotter.d.ts +58 -163
- package/autoscaling/snapshotter.js +45 -263
- package/autoscaling/system_status.d.ts +62 -84
- package/autoscaling/system_status.js +92 -122
- package/autoscaling/weighted_avg.d.ts +5 -0
- package/autoscaling/weighted_avg.js +14 -0
- package/byte_utils.d.ts +17 -0
- package/byte_utils.js +42 -0
- package/configuration.d.ts +96 -223
- package/configuration.js +170 -222
- package/cookie_utils.d.ts +4 -3
- package/cookie_utils.js +22 -13
- package/crawlers/context_pipeline.d.ts +10 -1
- package/crawlers/context_pipeline.js +31 -8
- package/crawlers/crawler_commons.d.ts +90 -83
- package/crawlers/crawler_commons.js +1 -116
- package/crawlers/error_snapshotter.d.ts +2 -5
- package/crawlers/error_snapshotter.js +7 -8
- package/crawlers/error_tracker.d.ts +0 -1
- package/crawlers/error_tracker.js +0 -1
- package/crawlers/index.d.ts +1 -3
- package/crawlers/index.js +0 -3
- package/crawlers/internals/types.d.ts +0 -1
- package/crawlers/internals/types.js +0 -1
- package/crawlers/statistics.d.ts +143 -59
- package/crawlers/statistics.js +243 -153
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/enqueue_links/enqueue_links.d.ts +59 -68
- package/enqueue_links/enqueue_links.js +57 -62
- package/enqueue_links/index.d.ts +0 -1
- package/enqueue_links/index.js +0 -1
- package/enqueue_links/shared.d.ts +40 -27
- package/enqueue_links/shared.js +90 -68
- package/errors.d.ts +72 -4
- package/errors.js +89 -5
- package/events/event_manager.d.ts +35 -9
- package/events/event_manager.js +10 -12
- package/events/index.d.ts +0 -1
- package/events/index.js +0 -1
- package/events/local_event_manager.d.ts +15 -3
- package/events/local_event_manager.js +39 -13
- package/http.d.ts +9 -0
- package/http.js +28 -0
- package/index.d.ts +7 -4
- package/index.js +6 -3
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +82 -3
- package/log.js +106 -1
- package/memory-storage/consts.d.ts +4 -0
- package/memory-storage/consts.js +4 -0
- package/memory-storage/index.d.ts +1 -0
- package/memory-storage/index.js +1 -0
- package/memory-storage/memory-storage.d.ts +38 -0
- package/memory-storage/memory-storage.js +130 -0
- package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
- package/memory-storage/resource-clients/common/base-client.js +6 -0
- package/memory-storage/resource-clients/dataset.d.ts +40 -0
- package/memory-storage/resource-clients/dataset.js +114 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
- package/memory-storage/resource-clients/key-value-store.js +204 -0
- package/memory-storage/resource-clients/request-queue.d.ts +77 -0
- package/memory-storage/resource-clients/request-queue.js +422 -0
- package/memory-storage/utils.d.ts +16 -0
- package/memory-storage/utils.js +41 -0
- package/owned_or_injected.d.ts +58 -0
- package/owned_or_injected.js +98 -0
- package/package.json +13 -12
- package/proxy_configuration.d.ts +24 -132
- package/proxy_configuration.js +24 -143
- package/recoverable_state.d.ts +140 -0
- package/recoverable_state.js +212 -0
- package/request.d.ts +86 -17
- package/request.js +120 -41
- package/router.d.ts +193 -21
- package/router.js +188 -43
- package/serialization.d.ts +0 -1
- package/serialization.js +9 -11
- package/service_locator.d.ts +165 -0
- package/service_locator.js +253 -0
- package/session_pool/consts.d.ts +1 -2
- package/session_pool/consts.js +1 -2
- package/session_pool/errors.d.ts +0 -1
- package/session_pool/errors.js +0 -1
- package/session_pool/fingerprint.d.ts +9 -0
- package/session_pool/fingerprint.js +30 -0
- package/session_pool/index.d.ts +0 -2
- package/session_pool/index.js +0 -2
- package/session_pool/session.d.ts +35 -89
- package/session_pool/session.js +82 -142
- package/session_pool/session_pool.d.ts +69 -90
- package/session_pool/session_pool.js +151 -150
- package/storages/batched_adds.d.ts +37 -0
- package/storages/batched_adds.js +73 -0
- package/storages/dataset.d.ts +114 -54
- package/storages/dataset.js +285 -144
- package/storages/index.d.ts +10 -8
- package/storages/index.js +8 -8
- package/storages/key_value_store.d.ts +185 -42
- package/storages/key_value_store.js +424 -151
- package/storages/key_value_store_codec.d.ts +32 -0
- package/storages/key_value_store_codec.js +113 -0
- package/storages/request_dedup_cache.d.ts +22 -0
- package/storages/request_dedup_cache.js +48 -0
- package/storages/request_list.d.ts +52 -116
- package/storages/request_list.js +159 -133
- package/storages/request_loader.d.ts +101 -0
- package/storages/request_loader.js +1 -0
- package/storages/request_manager.d.ts +33 -0
- package/storages/request_manager.js +1 -0
- package/storages/request_manager_tandem.d.ts +97 -0
- package/storages/request_manager_tandem.js +197 -0
- package/storages/request_queue.d.ts +290 -47
- package/storages/request_queue.js +757 -216
- package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +37 -88
- package/storages/{sitemap_request_list.js → sitemap_request_loader.js} +137 -143
- package/storages/storage_instance_manager.d.ts +87 -0
- package/storages/storage_instance_manager.js +256 -0
- package/storages/storage_stats.d.ts +48 -0
- package/storages/storage_stats.js +29 -0
- package/storages/throttling_request_manager.d.ts +216 -0
- package/storages/throttling_request_manager.js +453 -0
- package/storages/transaction.d.ts +252 -0
- package/storages/transaction.js +251 -0
- package/storages/utils.d.ts +58 -11
- package/storages/utils.js +64 -13
- package/system-info/cpu-info.d.ts +67 -0
- package/system-info/cpu-info.js +216 -0
- package/system-info/memory-info.d.ts +31 -0
- package/system-info/memory-info.js +115 -0
- package/system-info/ps-tree.d.ts +17 -0
- package/system-info/ps-tree.js +144 -0
- package/system-info/runtime.d.ts +14 -0
- package/system-info/runtime.js +80 -0
- package/typedefs.d.ts +0 -6
- package/typedefs.js +0 -1
- package/url.d.ts +9 -0
- package/url.js +11 -0
- package/validators.d.ts +8 -1
- package/validators.js +10 -3
- package/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/autoscaling/autoscaled_pool.js.map +0 -1
- package/autoscaling/index.d.ts.map +0 -1
- package/autoscaling/index.js.map +0 -1
- package/autoscaling/snapshotter.d.ts.map +0 -1
- package/autoscaling/snapshotter.js.map +0 -1
- package/autoscaling/system_status.d.ts.map +0 -1
- package/autoscaling/system_status.js.map +0 -1
- package/configuration.d.ts.map +0 -1
- package/configuration.js.map +0 -1
- package/cookie_utils.d.ts.map +0 -1
- package/cookie_utils.js.map +0 -1
- package/crawlers/context_pipeline.d.ts.map +0 -1
- package/crawlers/context_pipeline.js.map +0 -1
- package/crawlers/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.js.map +0 -1
- package/crawlers/crawler_utils.d.ts +0 -10
- package/crawlers/crawler_utils.d.ts.map +0 -1
- package/crawlers/crawler_utils.js +0 -12
- package/crawlers/crawler_utils.js.map +0 -1
- package/crawlers/error_snapshotter.d.ts.map +0 -1
- package/crawlers/error_snapshotter.js.map +0 -1
- package/crawlers/error_tracker.d.ts.map +0 -1
- package/crawlers/error_tracker.js.map +0 -1
- package/crawlers/index.d.ts.map +0 -1
- package/crawlers/index.js.map +0 -1
- package/crawlers/internals/types.d.ts.map +0 -1
- package/crawlers/internals/types.js.map +0 -1
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js.map +0 -1
- package/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/enqueue_links/enqueue_links.js.map +0 -1
- package/enqueue_links/index.d.ts.map +0 -1
- package/enqueue_links/index.js.map +0 -1
- package/enqueue_links/shared.d.ts.map +0 -1
- package/enqueue_links/shared.js.map +0 -1
- package/errors.d.ts.map +0 -1
- package/errors.js.map +0 -1
- package/events/event_manager.d.ts.map +0 -1
- package/events/event_manager.js.map +0 -1
- package/events/index.d.ts.map +0 -1
- package/events/index.js.map +0 -1
- package/events/local_event_manager.d.ts.map +0 -1
- package/events/local_event_manager.js.map +0 -1
- package/http_clients/base-http-client.d.ts +0 -134
- package/http_clients/base-http-client.d.ts.map +0 -1
- package/http_clients/base-http-client.js +0 -33
- package/http_clients/base-http-client.js.map +0 -1
- package/http_clients/form-data-like.d.ts +0 -67
- package/http_clients/form-data-like.d.ts.map +0 -1
- package/http_clients/form-data-like.js +0 -5
- package/http_clients/form-data-like.js.map +0 -1
- package/http_clients/got-scraping-http-client.d.ts +0 -15
- package/http_clients/got-scraping-http-client.d.ts.map +0 -1
- package/http_clients/got-scraping-http-client.js +0 -69
- package/http_clients/got-scraping-http-client.js.map +0 -1
- package/http_clients/index.d.ts +0 -3
- package/http_clients/index.d.ts.map +0 -1
- package/http_clients/index.js +0 -3
- package/http_clients/index.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/log.d.ts.map +0 -1
- package/log.js.map +0 -1
- package/proxy_configuration.d.ts.map +0 -1
- package/proxy_configuration.js.map +0 -1
- package/request.d.ts.map +0 -1
- package/request.js.map +0 -1
- package/router.d.ts.map +0 -1
- package/router.js.map +0 -1
- package/serialization.d.ts.map +0 -1
- package/serialization.js.map +0 -1
- package/session_pool/consts.d.ts.map +0 -1
- package/session_pool/consts.js.map +0 -1
- package/session_pool/errors.d.ts.map +0 -1
- package/session_pool/errors.js.map +0 -1
- package/session_pool/events.d.ts +0 -3
- package/session_pool/events.d.ts.map +0 -1
- package/session_pool/events.js +0 -3
- package/session_pool/events.js.map +0 -1
- package/session_pool/index.d.ts.map +0 -1
- package/session_pool/index.js.map +0 -1
- package/session_pool/session.d.ts.map +0 -1
- package/session_pool/session.js.map +0 -1
- package/session_pool/session_pool.d.ts.map +0 -1
- package/session_pool/session_pool.js.map +0 -1
- package/storages/access_checking.d.ts +0 -13
- package/storages/access_checking.d.ts.map +0 -1
- package/storages/access_checking.js +0 -14
- package/storages/access_checking.js.map +0 -1
- package/storages/dataset.d.ts.map +0 -1
- package/storages/dataset.js.map +0 -1
- package/storages/index.d.ts.map +0 -1
- package/storages/index.js.map +0 -1
- package/storages/key_value_store.d.ts.map +0 -1
- package/storages/key_value_store.js.map +0 -1
- package/storages/request_list.d.ts.map +0 -1
- package/storages/request_list.js.map +0 -1
- package/storages/request_provider.d.ts +0 -308
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -555
- package/storages/request_provider.js.map +0 -1
- package/storages/request_queue.d.ts.map +0 -1
- package/storages/request_queue.js.map +0 -1
- package/storages/request_queue_v2.d.ts +0 -87
- package/storages/request_queue_v2.d.ts.map +0 -1
- package/storages/request_queue_v2.js +0 -438
- package/storages/request_queue_v2.js.map +0 -1
- package/storages/sitemap_request_list.d.ts.map +0 -1
- package/storages/sitemap_request_list.js.map +0 -1
- package/storages/storage_manager.d.ts +0 -58
- package/storages/storage_manager.d.ts.map +0 -1
- package/storages/storage_manager.js +0 -105
- package/storages/storage_manager.js.map +0 -1
- package/storages/utils.d.ts.map +0 -1
- package/storages/utils.js.map +0 -1
- package/tsconfig.build.tsbuildinfo +0 -1
- package/typedefs.d.ts.map +0 -1
- package/typedefs.js.map +0 -1
- package/validators.d.ts.map +0 -1
- package/validators.js.map +0 -1
package/crawlers/statistics.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import { KeyValueStore } from '../storages/key_value_store.js';
|
|
1
|
+
import type { CrawleeLogger } from '../log.js';
|
|
2
|
+
import type { KeyValueStore } from '../storages/key_value_store.js';
|
|
4
3
|
import { ErrorTracker } from './error_tracker.js';
|
|
5
4
|
/**
|
|
6
5
|
* Persistence-related options to control how and when crawler's data gets persisted.
|
|
@@ -12,65 +11,123 @@ export interface PersistenceOptions {
|
|
|
12
11
|
*/
|
|
13
12
|
enable?: boolean;
|
|
14
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* The statistics surface a crawler depends on: recording per-request outcomes, tracking errors, and driving the
|
|
16
|
+
* capture lifecycle for a run. Injected via the crawler's `statistics` option, so a custom implementation (or a
|
|
17
|
+
* {@link Statistics} subclass tracking extra fields) can be plugged in without subclassing the crawler.
|
|
18
|
+
*
|
|
19
|
+
* The owned-only mutators the crawler uses to *own* a default it built - `reset()`/`resetStore()` - are deliberately
|
|
20
|
+
* absent: an injected instance is borrowed, and the crawler never wipes it. Those live on the concrete
|
|
21
|
+
* {@link Statistics} only.
|
|
22
|
+
*
|
|
23
|
+
* @category Crawlers
|
|
24
|
+
*/
|
|
25
|
+
export interface IStatistics {
|
|
26
|
+
/** Tracker for errors on the final retry of a request. */
|
|
27
|
+
readonly errorTracker: ErrorTracker;
|
|
28
|
+
/** Tracker for errors on retries prior to the final one. */
|
|
29
|
+
readonly errorTrackerRetry: ErrorTracker;
|
|
30
|
+
/** The live statistics state the crawler reads for status messages and the final summary. */
|
|
31
|
+
readonly state: StatisticState;
|
|
32
|
+
/** Retries histogram - index `i` holds the number of requests that finished after `i` retries. */
|
|
33
|
+
readonly requestRetryHistogram: number[];
|
|
34
|
+
/** Marks a request as started, so its duration can be measured on finish/fail. */
|
|
35
|
+
startJob(id: number | string): void;
|
|
36
|
+
/** Marks a started request as finished, updating the finished counters and durations. */
|
|
37
|
+
finishJob(id: number | string, retryCount: number): void;
|
|
38
|
+
/** Marks a started request as failed, updating the failed counters and durations. */
|
|
39
|
+
failJob(id: number | string, retryCount: number): void;
|
|
40
|
+
/** Drops a started request without counting it as finished or failed (e.g. skipped by robots.txt). */
|
|
41
|
+
discardJob(id: number | string): void;
|
|
42
|
+
/** Increments the counter for the given HTTP status code. */
|
|
43
|
+
registerStatusCode(code: number): void;
|
|
44
|
+
/** Computes the derived aggregates (averages, per-minute rates, totals) from the current state. */
|
|
45
|
+
calculate(): CalculatedStatistics;
|
|
46
|
+
/** Begins a capture window: loads any persisted state, subscribes to persistence events, starts periodic logging. */
|
|
47
|
+
startCapturing(): Promise<void>;
|
|
48
|
+
/** Ends the capture window: stops logging, unsubscribes, and persists the final state. */
|
|
49
|
+
stopCapturing(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Persists the current state to the key-value store. Optional - the crawler calls it on migration, but a backend
|
|
52
|
+
* with no persistence of its own can omit it.
|
|
53
|
+
*/
|
|
54
|
+
persistState?(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
/** The derived aggregates computed by {@link IStatistics.calculate} from the current {@link StatisticState}. */
|
|
57
|
+
export interface CalculatedStatistics {
|
|
58
|
+
/** Mean duration of a failed request, in milliseconds; `Infinity` when nothing has failed. */
|
|
59
|
+
requestAvgFailedDurationMillis: number;
|
|
60
|
+
/** Mean duration of a finished request, in milliseconds; `Infinity` when nothing has finished. */
|
|
61
|
+
requestAvgFinishedDurationMillis: number;
|
|
62
|
+
/** Requests finished per minute over the run so far. */
|
|
63
|
+
requestsFinishedPerMinute: number;
|
|
64
|
+
/** Requests failed per minute over the run so far. */
|
|
65
|
+
requestsFailedPerMinute: number;
|
|
66
|
+
/** Combined duration of all finished and failed requests, in milliseconds. */
|
|
67
|
+
requestTotalDurationMillis: number;
|
|
68
|
+
/** Total number of settled requests (finished plus failed). */
|
|
69
|
+
requestsTotal: number;
|
|
70
|
+
/** Wall-clock runtime since capturing started, in milliseconds. */
|
|
71
|
+
crawlerRuntimeMillis: number;
|
|
72
|
+
}
|
|
15
73
|
/**
|
|
16
74
|
* The statistics class provides an interface to collecting and logging run
|
|
17
75
|
* statistics for requests.
|
|
18
76
|
*
|
|
19
77
|
* All statistic information is saved on key value store
|
|
20
|
-
* under the key `
|
|
78
|
+
* under the key `CRAWLEE_CRAWLER_STATISTICS_*`, persists between
|
|
21
79
|
* migrations and abort/resurrect
|
|
22
80
|
*
|
|
23
81
|
* @category Crawlers
|
|
24
82
|
*/
|
|
25
|
-
export declare class Statistics {
|
|
83
|
+
export declare class Statistics implements IStatistics {
|
|
84
|
+
#private;
|
|
26
85
|
private static id;
|
|
27
86
|
/**
|
|
28
87
|
* An error tracker for final retry errors.
|
|
29
88
|
*/
|
|
30
|
-
errorTracker: ErrorTracker;
|
|
89
|
+
readonly errorTracker: ErrorTracker;
|
|
31
90
|
/**
|
|
32
91
|
* An error tracker for retry errors prior to the final retry.
|
|
33
92
|
*/
|
|
34
|
-
errorTrackerRetry: ErrorTracker;
|
|
93
|
+
readonly errorTrackerRetry: ErrorTracker;
|
|
35
94
|
/**
|
|
36
95
|
* Statistic instance id.
|
|
37
96
|
*/
|
|
38
|
-
readonly id:
|
|
97
|
+
readonly id: string;
|
|
98
|
+
protected readonly persistStateKey: string;
|
|
99
|
+
private readonly log;
|
|
39
100
|
/**
|
|
40
101
|
* Current statistic state used for doing calculations on {@link Statistics.calculate} calls
|
|
41
102
|
*/
|
|
42
|
-
state: StatisticState;
|
|
103
|
+
get state(): StatisticState;
|
|
43
104
|
/**
|
|
44
105
|
* Contains the current retries histogram. Index 0 means 0 retries, index 2, 2 retries, and so on
|
|
45
106
|
*/
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Contains the associated Configuration instance
|
|
49
|
-
*/
|
|
50
|
-
private readonly config;
|
|
51
|
-
protected keyValueStore?: KeyValueStore;
|
|
52
|
-
protected persistStateKey: string;
|
|
53
|
-
private logIntervalMillis;
|
|
54
|
-
private logMessage;
|
|
55
|
-
private listener;
|
|
56
|
-
private requestsInProgress;
|
|
57
|
-
private readonly log;
|
|
58
|
-
private instanceStart;
|
|
59
|
-
private logInterval;
|
|
60
|
-
private events;
|
|
61
|
-
private persistenceOptions;
|
|
107
|
+
get requestRetryHistogram(): number[];
|
|
62
108
|
/**
|
|
63
|
-
*
|
|
109
|
+
* Construct a statistics instance to pass to a crawler via its `statistics` option, e.g. to preconfigure
|
|
110
|
+
* persistence or error snapshots, share it across sequential runs, or subclass it to track extra fields.
|
|
64
111
|
*/
|
|
65
112
|
constructor(options?: StatisticsOptions);
|
|
66
113
|
/**
|
|
67
|
-
* Set the current statistic instance to pristine values
|
|
114
|
+
* Set the current statistic instance to pristine values.
|
|
115
|
+
*
|
|
116
|
+
* The persisted record is left alone - use {@link Statistics.resetStore} to clear that as well.
|
|
68
117
|
*/
|
|
69
118
|
reset(): void;
|
|
70
119
|
/**
|
|
71
|
-
*
|
|
120
|
+
* The pristine state a new instance starts with and {@link Statistics.reset} restores.
|
|
121
|
+
*
|
|
122
|
+
* A subclass tracking extra fields declares their initial values here.
|
|
123
|
+
*/
|
|
124
|
+
protected defaultState(): StatisticState;
|
|
125
|
+
/**
|
|
126
|
+
* Clear the persisted statistics record, leaving the in-memory state alone.
|
|
127
|
+
*
|
|
128
|
+
* Throws while capturing - the next PERSIST_STATE event would write the record straight back.
|
|
72
129
|
*/
|
|
73
|
-
resetStore(
|
|
130
|
+
resetStore(): Promise<void>;
|
|
74
131
|
/**
|
|
75
132
|
* Increments the status code counter.
|
|
76
133
|
*/
|
|
@@ -90,18 +147,16 @@ export declare class Statistics {
|
|
|
90
147
|
* @ignore
|
|
91
148
|
*/
|
|
92
149
|
failJob(id: number | string, retryCount: number): void;
|
|
150
|
+
/**
|
|
151
|
+
* Discards a started job without affecting the finished/failed counters, e.g. when a request
|
|
152
|
+
* turns out to be skipped (robots.txt, enqueue strategy) after `startJob` was already called for it.
|
|
153
|
+
* @ignore
|
|
154
|
+
*/
|
|
155
|
+
discardJob(id: number | string): void;
|
|
93
156
|
/**
|
|
94
157
|
* Calculate the current statistics
|
|
95
158
|
*/
|
|
96
|
-
calculate():
|
|
97
|
-
requestAvgFailedDurationMillis: number;
|
|
98
|
-
requestAvgFinishedDurationMillis: number;
|
|
99
|
-
requestsFinishedPerMinute: number;
|
|
100
|
-
requestsFailedPerMinute: number;
|
|
101
|
-
requestTotalDurationMillis: number;
|
|
102
|
-
requestsTotal: number;
|
|
103
|
-
crawlerRuntimeMillis: number;
|
|
104
|
-
};
|
|
159
|
+
calculate(): CalculatedStatistics;
|
|
105
160
|
/**
|
|
106
161
|
* Initializes the key value store for persisting the statistics,
|
|
107
162
|
* displaying the current state in predefined intervals
|
|
@@ -111,17 +166,25 @@ export declare class Statistics {
|
|
|
111
166
|
* Stops logging and remove event listeners, then persist
|
|
112
167
|
*/
|
|
113
168
|
stopCapturing(): Promise<void>;
|
|
114
|
-
|
|
169
|
+
private saveRetryCountForJob;
|
|
115
170
|
/**
|
|
116
|
-
* Persist internal state to the key value store
|
|
117
|
-
*
|
|
171
|
+
* Persist internal state to the key value store.
|
|
172
|
+
*
|
|
173
|
+
* Statistics are bookkeeping - a store that refuses the write is worth a warning, not a failed crawl. The
|
|
174
|
+
* crawler calls this from its migration handler, where a rejection would go unhandled.
|
|
118
175
|
*/
|
|
119
|
-
persistState(
|
|
176
|
+
persistState(): Promise<void>;
|
|
120
177
|
/**
|
|
121
|
-
*
|
|
178
|
+
* Rebuilds the state from a persisted record.
|
|
179
|
+
*
|
|
180
|
+
* A subclass tracking extra fields restores them here, on top of the result of `super.deserializeState()`.
|
|
122
181
|
*/
|
|
123
|
-
protected
|
|
124
|
-
|
|
182
|
+
protected deserializeState(persistedState: StatisticPersistedState): StatisticState;
|
|
183
|
+
/**
|
|
184
|
+
* Builds the record written to the key value store, merging in the derived aggregates so that a consumer
|
|
185
|
+
* reading the record does not have to reconstruct them.
|
|
186
|
+
*/
|
|
187
|
+
protected serializeState(state: StatisticState): StatisticPersistedState;
|
|
125
188
|
/**
|
|
126
189
|
* Make this class serializable when called with `JSON.stringify(statsInstance)` directly
|
|
127
190
|
* or through `keyValueStore.setValue('KEY', statsInstance)`
|
|
@@ -146,17 +209,12 @@ export interface StatisticsOptions {
|
|
|
146
209
|
* Parent logger instance, the statistics will create a child logger from this.
|
|
147
210
|
* @default crawler.log
|
|
148
211
|
*/
|
|
149
|
-
log?:
|
|
212
|
+
log?: CrawleeLogger;
|
|
150
213
|
/**
|
|
151
214
|
* Key value store instance to persist the statistics.
|
|
152
215
|
* If not provided, the default one will be used when capturing starts
|
|
153
216
|
*/
|
|
154
217
|
keyValueStore?: KeyValueStore;
|
|
155
|
-
/**
|
|
156
|
-
* Configuration instance to use
|
|
157
|
-
* @default Configuration.getGlobalConfig()
|
|
158
|
-
*/
|
|
159
|
-
config?: Configuration;
|
|
160
218
|
/**
|
|
161
219
|
* Control how and when to persist the statistics.
|
|
162
220
|
*/
|
|
@@ -166,19 +224,39 @@ export interface StatisticsOptions {
|
|
|
166
224
|
* @default false
|
|
167
225
|
*/
|
|
168
226
|
saveErrorSnapshots?: boolean;
|
|
227
|
+
/**
|
|
228
|
+
* A unique identifier for this statistics instance. This ID is used for persistence
|
|
229
|
+
* to the key value store, ensuring the same statistics can be loaded after script restarts.
|
|
230
|
+
*
|
|
231
|
+
* If not provided, an auto-incremented ID will be used for backward compatibility.
|
|
232
|
+
* This means statistics may not persist correctly across script restarts
|
|
233
|
+
* if crawler creation order changes.
|
|
234
|
+
*/
|
|
235
|
+
id?: string;
|
|
169
236
|
}
|
|
170
237
|
/**
|
|
171
|
-
* Format of the persisted stats
|
|
238
|
+
* Format of the persisted stats.
|
|
239
|
+
*
|
|
240
|
+
* The `null`s are `Infinity` on the way out - JSON has no infinity, so a record written before anything
|
|
241
|
+
* finished or failed carries a `null` in its place.
|
|
172
242
|
*/
|
|
173
|
-
export interface StatisticPersistedState extends Omit<StatisticState, 'statsPersistedAt'> {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
243
|
+
export interface StatisticPersistedState extends Omit<StatisticState, 'statsPersistedAt' | 'crawlerStartedAt' | 'crawlerFinishedAt' | 'requestMinDurationMillis' | 'requestsFailedPerMinute' | 'requestsFinishedPerMinute' | 'requestRetryHistogram' | 'instanceStart'> {
|
|
244
|
+
statsId: string;
|
|
245
|
+
requestsFailedPerMinute: number | null;
|
|
246
|
+
requestsFinishedPerMinute: number | null;
|
|
247
|
+
/** ISO strings - the live state keeps these as `Date`s. */
|
|
248
|
+
crawlerStartedAt: string | null;
|
|
249
|
+
crawlerFinishedAt: string | null;
|
|
250
|
+
statsPersistedAt: string;
|
|
251
|
+
requestMinDurationMillis: number | null;
|
|
252
|
+
/** A retry count that no request ever reached leaves a `null` here. */
|
|
253
|
+
requestRetryHistogram: (number | null)[];
|
|
254
|
+
requestAvgFailedDurationMillis: number | null;
|
|
255
|
+
requestAvgFinishedDurationMillis: number | null;
|
|
178
256
|
requestTotalDurationMillis: number;
|
|
179
257
|
requestsTotal: number;
|
|
258
|
+
/** {@link StatisticState.instanceStart} of the run that wrote the record. */
|
|
180
259
|
crawlerLastStartTimestamp: number;
|
|
181
|
-
statsPersistedAt: string;
|
|
182
260
|
}
|
|
183
261
|
/**
|
|
184
262
|
* Contains the statistics state
|
|
@@ -200,5 +278,11 @@ export interface StatisticState {
|
|
|
200
278
|
errors: Record<string, unknown>;
|
|
201
279
|
retryErrors: Record<string, unknown>;
|
|
202
280
|
requestsWithStatusCode: Record<string, number>;
|
|
281
|
+
/** Retries histogram - index `i` holds the number of requests that finished after `i` retries. */
|
|
282
|
+
requestRetryHistogram: number[];
|
|
283
|
+
/**
|
|
284
|
+
* When the current capture window started, as a `Date.now()` timestamp. Rebased on load so that the runtime
|
|
285
|
+
* reported by {@link Statistics.calculate} spans a migration rather than restarting from zero.
|
|
286
|
+
*/
|
|
287
|
+
instanceStart: number;
|
|
203
288
|
}
|
|
204
|
-
//# sourceMappingURL=statistics.d.ts.map
|