资源简介
yarn任务邮件监控及linux进程邮件监控,定时检查 ,本人在生产环境使用的,可以监控yarn任务,各种进程 如namenode ,java jar进程,如果不明白可以留言或者联系我(文档里面有联系方式)
代码片段和文件信息
#!/usr/bin/python
# -*- coding: utf-8 -*-
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.image import MIMEImage
from email.Header import Header
from email.utils import formataddr parseaddr
from email import encoders
import traceback
import os
import sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)
def _format_addr(s):
name addr = parseaddr(s)
print name addr
return formataddr((Header(name ‘utf-8‘).encode()
addr.encode(‘utf-8‘) if isinstance(addr unicode) else addr))
def send_mail(subject content sender=‘改成你的发件邮箱.cn‘ receiver=‘改成你的收件邮箱‘ cc=[] partname=None
priority=‘0‘):
if type(receiver) == str:
receiver = [receiver]
receiver1 = list(receiver)
msgRoot = MIMEMultipart(‘related‘)
msgRoot[‘From‘] = _format_addr(u‘mail监控通知<%s>‘ % sender)
msgRoot[‘To‘] = ‘ ‘.join(receiver1)
msgRoot[‘X-Priority‘] = priority
if cc:
if type(cc) == str:
cc = [cc]
receiver1.extend(cc)
msgRoot[‘Cc‘] = ‘ ‘.join(cc)
msgRoot[‘Subject‘] = subject
msgText = MIMEText(content ‘html‘ ‘utf-8‘)
msgRoot.attach(msgText)
if partname:
print partname
part = MIMEApplication(open(partname ‘rb‘).read())
part.add_header(‘Content-Disposition‘ ‘attachment‘ filename=partname)
msgRoot.attach(part)
smtp = None
try:
# 一般都是企业邮箱 个人邮箱我没有试过 可能会限制什么的
smtp = smtplib.SMTP_SSL()
smtp.connect(‘smtp.exmail.qq.com‘ port=465)
smtp.login(‘改成你的发件邮箱登录名称‘ ‘改成你的登录密码‘)
smtp.sendmail(sender receiver1 msgRoot.as_string())
except:
print “sendmail“
finally:
try:
if smtp: smtp.quit()
except:
print “sendmail“
def isRunning(process_name):
try:
process = len(os.popen(‘ps aux | grep “‘ + process_name + ‘“ | grep -v grep‘).readlines())
if process >= 1:
return True
else:
return False
except:
print(“Check process ERROR!!!“)
return False
def yarn_mon(result):
#该处应该写绝对路径
jps = ‘/data/module/hadoop-2.7.6/bin/yarn application -list‘
try:
yarn_appname=[]
yarn_list = os.popen(jps).readlines()[2:]
for yarn in yarn_list:
ys = yarn.split(“\t“)[1]
yarn_appname.append(ys)
for job in result:
if job not in yarn_appname:
print “send_mail“
send_mail(“每半小时yarn spark job 和 kafka to gp 监控“ “每半小时yarn spark job监控,该{}任务监控不到,\n“
“检查hadoop:8088界面详情正在运行的job任务为{}:\n“.format(jobyarn_appname))
except baseException e:
print e.message
send_mail(“每半小时yarn spark job 和 kafka to gp 监控“ “30分钟yarn spark job监控,监控邮件Except 未能成功运行 {}“ .format(e.message))
if __name__ == ‘__main__‘:
# 监控进
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4206 2019-01-29 14:48 mon.py
目录 0 2019-01-29 14:56 __MACOSX\
文件 266 2019-01-29 14:48 __MACOSX\._mon.py
文件 74 2019-01-29 14:48 mon_yarn_job.txt
文件 210 2019-01-29 14:48 __MACOSX\._mon_yarn_job.txt
文件 294 2019-01-29 14:53 閮ㄧ讲鏂规硶.py
文件 210 2019-01-29 14:53 __MACOSX\._閮ㄧ讲鏂规硶.py
- 上一篇:java实现敏感词过滤280838
- 下一篇:个人信息管理系统
相关资源
- 大数据hadoop,spark,hive等等面试汇总
- 《Hadoop with Python》 pdf
- 绝对可用hadoop-eclipse-plugin-1.1.2.jar
- hadoop-common-2.7.1-bin
- hadoop2.5.0 snappy编译jar包
- Hadoop 2.7.4 Windows 64位 编译bin包含win
- hadoop-hdfs-2.7.7.jar
- 修复版 hadoop-0.21.0-eclipse-plugin.jar
- hadoop-eclipse-plugin-1.2.1.jar
- Native Hadoop3.2.1 Library 64位编译
- hadoop-common-2.7.3.jar
- avro-1.8.1
- Hadoop2.7.7配合使用的winutil
- hadoop 32位lib包
- hadoop电商网站分析系统毕业设计项目
- hadoop-eclipse-plugin-2.7.5.jar275778
- Hadoop-Eclipse插件2.7.6
- JavaWeb操作hadoop2.6 HDFS从页面上传,,
- hadoop-eclipse-plugin-2.7.3.jar 插件
- hadoop-eclipse-plugin-2.7.2完美兼容版
- hadoop-eclipse-plugin-2.6.4.jar
- hadoop-eclipse-plugin-2.8.5.jar
- hadoop-eclipse-plugin-3.1.2.jar
- Hadoop的jar包
- hadoop-eclipse-plugin-2.9.2.jar 插件
- hadoop-eclipse-plugin-2.7.7.jar 插件
- hadoop-3.1.3.tar.gz
- hadoop-eclipse-plugin-2.7.3.jar
- hadoop-eclipse-plugin-2.6.0.jar
- hadoop-eclipse-plugin-2.9.0套装
评论
共有 条评论