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.5.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.5-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spider_task_monitor-0.0.5.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.5.tar.gz
Algorithm Hash digest
SHA256 643e901f13e9bf859fddad8c2fd89ad426bc926d5eddc7fb3470488b620cf98c
MD5 9c15623124af24c87262c4fde9b32bc4
BLAKE2b-256 d4540e1ddd4e0d0d20490bd3ddb8e85faf562f2e97f16f63446843fea7c6c602

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spider_task_monitor-0.0.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 341f9175c5c82017e99df8bf5e224d3c0048b4b0fd511e0d4c4279ee7d82405f
MD5 47952e9e13ca66ea88ef3a7838c5993e
BLAKE2b-256 2d13592daca57b14a8285c3311d9330748f4db9df6c4daf49d45180c8381840f

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