通过crontab监控SparkStreaming任务运行状态

1.问题

最近发现SparkStreaming提交的job经常在半夜挂掉,于是写了个定时任务监控SparkStreaming的运行状态,保证其不挂掉

2.shell脚本

touch /opt/module/jobs/monitorlog.txt
vim /opt/module/jobs/monitor.sh
#!/bin/bash

#在linux中查找你所运行的spark任务中  任务名称为WBStreamingClusterDriver的任务有没有,如果有则返回值是1
job_status=$(yarn application -list| awk '{print $2}'  | grep -w KeyBehaviorsQl  | wc -l)

if [ $job_status = 0 ];then

    echo $(date "+%Y-%m-%d %H:%M:%S")  'SparkStreamingTestis stop'  >> /opt/module/jobs/monitorlog.txt

    nohup spark2-submit --master yarn --deploy-mode cluster --driver-memory 3g --num-executors 70 \
--executor-cores 2 --executor-memory 3g  \
--class com.eighteen.sparkstreaming.SparkStreamingTest\
/opt/module/jobs/SparkStreaming-1.0-SNAPSHOT-jar-with-dependencies.jar

    echo $(date "+%Y-%m-%d %H:%M:%S")  "restart SparkStreamingTest success !!!"  >> /opt/module/jobs/monitorlog.txt

else

    echo $(date "+%Y-%m-%d %H:%M:%S")  'SparkStreamingTest is running !!' >> /opt/module/jobs/monitorlog.txt

fi

3.编写定时任务

*/3 * * * * /opt/module/jobs/monitor.sh

4.查看 monitorlog.txt

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值