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

99封情书 提交于 2019-12-04 12:13:53

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 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!