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临时存储监控信息,mysql作持久存储,所以需配置好 `redis_config` 及 `mysql_config`
<pre>
redis_config = {
'host': host,
'port': port,
'password': pwd,
'db': db (可不设置,监控会强制设置为db14)
}

mysql_config = {
'host': host,
'user': user,
'passwd': pwd,
'db': 'ins-spider', (db请设置为 ins-spider)
'charset': charset,
'port': port
}

mail_config = {
'host': host,
'port': port,
'user': user,
'password': pwd
}
</pre>
- 当启动一个批次的任务时,创建监控队列
<pre>
from spider_task_monitor.monitor import monitor
m = monitor.Monitor(redis_config, mysql_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.4.tar.gz (10.0 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.4-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spider_task_monitor-0.0.4.tar.gz
  • Upload date:
  • Size: 10.0 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.4.tar.gz
Algorithm Hash digest
SHA256 465e42516c4d9138a9f85a05cfae66a2aec984b9a8bed9c8663905559a5f751e
MD5 0031d18c2e3d83f9ac2807b83fcb58f9
BLAKE2b-256 b16d4b9378b376fc5a1f555131173ecc4c5ab1d512130a494aa6ae4b1be641c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spider_task_monitor-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.4 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fcfa45128627c03d8e013a7b3dead3f12d6f805ba40ad0750753751cc67e9b1c
MD5 57fd77611e0ec3f2b93b8fd7984ba96e
BLAKE2b-256 9e90f1f540c3b275b83e0672a1cbda796dd6d054c022ba539b3a69b5da1c0ede

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