Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spidermon. #23

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Scrapy==2.11.2
scrapy-zyte-api[provider]>=0.17.3
zyte-spider-templates==0.8.0
duplicate-url-discarder[rules]>=0.2.0
spidermon>=1.19.0
wRAR marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions zyte_spider_templates_project/monitors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from spidermon.contrib.scrapy.monitors import (
ErrorCountMonitor,
FieldCoverageMonitor,
FinishReasonMonitor,
SpiderCloseMonitorSuite,
UnwantedHTTPCodesMonitor,
)


class CustomSpiderCloseMonitorSuite(SpiderCloseMonitorSuite):
monitors = [
ErrorCountMonitor,
FinishReasonMonitor,
UnwantedHTTPCodesMonitor,
FieldCoverageMonitor,
]
24 changes: 24 additions & 0 deletions zyte_spider_templates_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"zyte_spider_templates.middlewares.AllowOffsiteMiddleware": 500,
"zyte_spider_templates.middlewares.CrawlingLogsMiddleware": 1000,
}
EXTENSIONS = {
'spidermon.contrib.scrapy.extensions.Spidermon': 500,
}

# scrapy-poet
SCRAPY_POET_DISCOVER = [
Expand All @@ -46,3 +49,24 @@
"style"
],
}

# spidermon
SPIDERMON_ENABLED = True
SPIDERMON_SPIDER_CLOSE_MONITORS = (
"zyte_spider_templates_project.monitors.CustomSpiderCloseMonitorSuite",
)
SPIDERMON_MAX_ERRORS = 0
SPIDERMON_ADD_FIELD_COVERAGE = True
SPIDERMON_FIELD_COVERAGE_RULES = {
"Product/url": 1.0,
"Product/name": 1.0,
"Product/metadata": 1.0,
}
SPIDERMON_ITEM_COUNT_INCREASE = 1 # At least 1 item every 5 minutes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels redundant with the recommended CLOSESPIDER_TIMEOUT_NO_ITEM value of 600 in the setup instructions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VMRuiz what do you think?

SPIDERMON_PERIODIC_MONITORS = {
'spidermon.contrib.scrapy.monitors.PeriodicItemCountMonitorSuite': 500,
}
SPIDERMON_UNWANTED_HTTP_CODES = {
400: {"max_percentage": 0.3},
500: {"max_percentage": 0.2},
}