Skip to main content

对于爬虫任务调度的监控

Project description

爬虫任务的监控

- 针对爬虫调度任务的监控,为每个任务的不同批次设置唯一的标识,作为redis的key,并记录相应信息(队列长度)
- 当每个种子爬取完毕时,需向监控系统发送此次爬取的状态(成功/失败/重试,及爬取时间),监控系统会作记录
- 在次日的早晨,报表调度器会将前一天的监控信息汇总入库,并给相关人员发送监控报表

代码结构:
<pre>
spider_task_monitor
|--- common 通用库
||---- config.py 一些配置信息
||---- constants.py 一些常量
||---- util.py 一些通用函数
|--- core 核心库
||---- dao.py 持久层的操作
||---- mail.py 邮件系统
||---- task_dao.py 任务监控的持久层细节
|--- monitor 监控库
||---- monitor.py 监控类
||---- report.py 报表类
</pre>

具体使用:
- 由于这里使用redis临时存储监控信息,所以需配置好 `redis_config`
<pre>
redis_config = {
'host': host,
'port': port,
'password': pwd,
'db': db (可不设置,监控会强制设置为db14)
}

mail_config = {
'host': host,
'port': port,
'user': user,
'password': pwd
}
</pre>
- 当启动一个批次的任务时,创建监控队列
<pre>
from spider_task_monitor.monitor import monitor
m = monitor.Monitor(bis_name, task_name, redis_config, mail_config)
# 初始化当前任务的配置信息,如失败率上限,种子的平均爬取时长上限,报警邮件的收件人
m.init_config(failure_rate_up=.05, avg_time_up=5.0, warn_addresses=['example@domain.com'])
# 版本号遵循一个默认规则,`%Y/%m/%d %H:%M`,即 `年/月/日 时:分`
version = m.cons_version()
# 创建监控队列
m.create(version, queue_length) # 版本号,队列长度
</pre>
- 一个种子爬取完成时,发送当前种子的完成状态
<pre>
# 版本号,爬取结果(成功/失败/重试),爬取时长
m.send(version, crawl_time=1.68) # 默认成功
m.send(version, data_result=monitor.DataResult.FAILED, crawl_time=1.5)
m.send(version, data_result=monitor.DataResult.RETRY, crawl_time=2.3)
</pre>


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spider_task_monitor-0.0.7.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spider_task_monitor-0.0.7-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file spider_task_monitor-0.0.7.tar.gz.

File metadata

  • Download URL: spider_task_monitor-0.0.7.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for spider_task_monitor-0.0.7.tar.gz
Algorithm Hash digest
SHA256 bfb9f3717d70822e0d3f0bbe6a8bc0c4c84d42adbb7d5b00cb6dc71b3996305a
MD5 f7e01b33a074708489c4727c122cc70d
BLAKE2b-256 06e09ef7da2330d06b56fb3219832cd45747b2e0fd123aa022e2bb4293f1dc83

See more details on using hashes here.

File details

Details for the file spider_task_monitor-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: spider_task_monitor-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for spider_task_monitor-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 888e7f062e70e6b44486523100a3fd2d649fbc36c043f670cb97cc3e8cbc8481
MD5 c924acd21764aa03dcc355b8d1f6a9e9
BLAKE2b-256 d3cd5ad97164791ac195b350864e32cb8c9f29cc222c053864f681e54f682391

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page