温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

cronmon 定时任务执行状态监控

发布时间:2020-04-08 22:14:25 来源:网络 阅读:937 作者:bruceye777 栏目:编程语言

       cronmon是一个计划任务(定时任务)监控系统,可以对循环执行的程序和脚本进行监控告警,当其未按照预期执行时,发送邮件到对应邮箱进行通知。同时可以将监控任务划分到不同业务下面,每个业务可以分配不同的通知人,建立业务、通知人和监控任务的多层级关系。
 
       通过以一定的间隔发送HTTPS请求到特定的URL实现监控。如果URL未按时接受到请求,对应的业务通知人则会收到告警。
 
       也就是说,你可以在你的计划任务或者程序脚本中,根据执行结果进行条件判断,如果成功则发送请求到cronmon,这样的任务可以包括数据库备份、安全扫描、数据同步等任何你认为重要的,需要保证其在指定时间间隔完成的任务。
   
   
主要功能介绍

   

  • 登录;

cronmon 定时任务执行状态监控

  • 登录之后,看到的是首页:包括业务、通知人、任务和日志相关汇总信息,以及图表展示一段时间API请求数据;

cronmon 定时任务执行状态监控

  • 任务管理相关操作:这里是系统最核心的功能,监控任务管理,包括新建,编辑,删除,监控日志查看。;

cronmon 定时任务执行状态监控

cronmon 定时任务执行状态监控

cronmon 定时任务执行状态监控

  • 系统管理相关操作:系统用户角色分为二种,拥有所有权限的系统管理员和绑定若干业务的业务管理员。在这里,你可以新建、编辑、删除用户以及业务权限分配;

cronmon 定时任务执行状态监控

cronmon 定时任务执行状态监控

cronmon 定时任务执行状态监控

cronmon 定时任务执行状态监控
  
API调用

  
目前API仅针对监控任务,包括获取所有监控任务和基于关键字进行的任务过滤,json格式返回。

  • 获取所有监控任务

cronmon 定时任务执行状态监控

  • 按指定关键字获取任务(业务名、任务名和任务URL)

cronmon 定时任务执行状态监控

cronmon 定时任务执行状态监控

cronmon 定时任务执行状态监控

公共参数包括page(显示第几页)和length(每页显示多少记录)
  
如何使用监控链接

  
在不同情况下调用任务监控URL的写法

  • crontab写法
# system status check
20 * * * * cd /path/to/systemStatusCheck && ./systemStatusCheck.sh > systemStatusCheck.sh.cron.log 2>&1 && curl -kfsS --retry 3 --connect-timeout 10 --ipv4 https://cronmon.yoursite.io/api/monlink/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx >> systemStatusCheck.sh.cron.log 2>&1
  • bash写法
curl -kfsS --retry 3 --connect-timeout 10 --ipv4 https://cronmon.yoursite.io/api/monlink/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  • python写法
import requests
requests.get('https://cronmon.yoursite.io/api/monlink/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')

  
生产环境

  
本部分是针对生产环境一些额外的配置优化,包括日志表自动分区脚本、程序管理服务化(linux)、nginx配置和日志轮转配置。

  • 服务启停

以CentOS为例,首先编辑相关变量

cronmon 定时任务执行状态监控

然后将启动脚本(production/init.d/cronmon)放入/etc/init.d目录

$ service cronmon help
Usage: cronmon {start|stop|restart|reload|status|help}
$ chkconfig --level 35 cronmon on  # 加入开机启动
  • 日志分区

针对日志表数据,为了方便管理和提高效率,使用mysql分区,首先导入存储过程创建sql文件(production/cronmonPartition.sql),
脚本首先修改表结构,添加了复合主键(id+create_datetime),然后创建了所需的5个存储过程,脚本基于zabbix分区创建脚本进行修改,执行脚本后结果如下:

cronmon 定时任务执行状态监控

cronmon 定时任务执行状态监控

对应的shell脚本

cronmon 定时任务执行状态监控

对应的crontab配置

# cronmon mysql partition
15 0 * * * cd /path/to/cronmonMysqlPartition && ./cronmonMysqlPartition.sh > cronmonMysqlPartition.sh.cron.log 2>&1 && curl -kfsS --retry 3 --connect-timeout 10 --ipv4 https://cronmon.yoursite.io/api/monlink/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx >> cronmonMysqlPartition.sh.cron.log 2>&1
  • WebService配置

以nginx为例

cronmon 定时任务执行状态监控

  • 日志轮转

以logrotate为例

cronmon 定时任务执行状态监控
  
压力测试

  
本系统主要的压力是客户端对监控URL的请求,而网站本身操作的压力以及API请求的压力相对较小,有鉴于此,针对此部分进行了压力测试。

  • 配置调整

uwsgi相关配置

[uwsgi]
listen=10240
processes=8
gevent=100

系统相关配置

# echo 'net.core.somaxconn=4096' >> /etc/sysctl.conf
  • 压测表现

使用ab对监控链接进行压力测试,10000并发无错误(目前只测试到10000并发,未测试更高并发),客户端和服务端网络延迟在11ms左右:

$ ab -n 50000 -c 10000 https://cronmon.yoursite.com/api/monlink/ba60afc4-f162-11e8-a56a-001b7872e686

cronmon 定时任务执行状态监控

获取帮助

如果想进一步了解安装配置,数据库变更和系统网站的功能可以点击github

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI