I am trying to implement spidermon to monitor scrapyd:
https://github.com/scrapinghub/spidermon/blob/master/spidermon/contrib/scrapy/monitors.py https://spidermon.readthedocs.io/en/latest/monitors.html#is-there-a-basic-scrapy-suite-ready-to-use
Currently it monitors minimum number of items and max amount of errors. In case of error it sends out a message via telegram. Somehow either the documentation must be wrong or my implementation as the amount of errors or items will not be included in the message:
from spidermon import Monitor, MonitorSuite, monitors
from spidermon.contrib.actions.telegram.notifiers import SendTelegramMessageSpiderFinished
from spidermon.contrib.monitors.mixins import StatsMonitorMixin
@monitors.name('Item count')
class ItemCountMonitor(Monitor):
@monitors.name('Minimum number of items')
def test_minimum_number_of_items(self):
item_extracted = getattr(
self.data.stats, 'item_scraped_count', 0)
minimum_threshold = 500
msg = 'Extracted less than {} items'.format(
minimum_threshold)
self.assertTrue(
item_extracted >= minimum_threshold, msg=msg
)
@monitors.name("Error Count Monitor")
class ErrorCountMonitor(Monitor):
"""Check for errors in the spider log.
You can configure the expected number of ERROR log messages using
``SPIDERMON_MAX_ERRORS``. The default is ``0``."""
@monitors.name("Should not have any errors")
def test_max_errors_in_log(self):
errors_threshold = self.crawler.settings.getint(SPIDERMON_MAX_ERRORS, 0)
no_of_errors = self.stats.get("log_count/ERROR", 0)
msg = "Found {} errors in log, maximum expected is " "{}".format(
no_of_errors, errors_threshold
)
self.assertTrue(no_of_errors <= errors_threshold, msg=msg)
class SpiderCloseMonitorSuite(MonitorSuite):
monitors = [
ItemCountMonitor,
# ItemValidationMonitor,
ErrorCountMonitor
]
monitors_failed_actions = [
SendTelegramMessageSpiderFinished,
]
How can the msg text be included within the telegram notification?