博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tomcat监控脚本
阅读量:5134 次
发布时间:2019-06-13

本文共 1787 字,大约阅读时间需要 5 分钟。

监控tomcat程序是否正常运行的脚本#!/usr/local/bin/python3.5#coding:utf-8import urllib.requestimport subprocess, osfrom time import strftime, gmtime, sleep #tomcat_pid = (((subprocess.Popen("lsof -i :8080 |grep root |awk '{print $2}'", shell=True, stdout=subprocess.PIPE)).stdout.read()).decode()).strip()req = urllib.request.Request('http://123.57.79.138')try:    response = urllib.request.urlopen(req, timeout = 30)except Exception as e:    with open('/var/tomcat/logs/tomcat_down.txt', 'a') as f:        current_time = '#================<< Tomcat Down Time : ' + strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' >>==============\nMore information about tomcat...\n'        f.write(current_time)        f.write(e)        tomcat_status = (open('/proc/' + tomcat_pid + '/status')).read()        f.write(tomcat_status + '\n')            subprocess.Popen("/var/tomcat/bin/shutdown.sh > /dev/null 2>&1", shell=True, stdout=subprocess.PIPE)        if len(tomcat_pid) == 0:            pass        else:            subprocess.Popen("kill -9 " + tomcat_pid, shell=True, stdout=subprocess.PIPE)            subprocess.Popen("rm -rf /var/tomcat/temp/*", shell=True, stdout=subprocess.PIPE)            subprocess.Popen("rm -rf /var/tomcat/work/Catalina/localhost/*", shell=True, stdout=subprocess.PIPE)            sleep(3)            if len(os.listdir('/var/tomcat/temp')) == 0 and len(os.listdir('/var/tomcat/work/Catalina/localhost')) == 0:                subprocess.Popen("/var/tomcat/bin/startup.sh", shell=True, stdout=subprocess.PIPE)                send_mail.SendMail('/var/tomcat/logs/tomcat_lastdown.txt')            else:                with open('/var/tomcat/logs/tomcat_down.txt', 'a') as f:                    f.write('The cache file not clean yet!')END!

 

转载于:https://www.cnblogs.com/changbo/p/6496641.html

你可能感兴趣的文章
Java Servlet 过滤器与 springmvc 拦截器的区别?
查看>>
(tmp >> 8) & 0xff;
查看>>
linux命令之ifconfig详细解释
查看>>
NAT地址转换
查看>>
Nhibernate 过长的字符串报错 dehydration property
查看>>
Deque - leetcode 【双端队列】
查看>>
gulp插件gulp-ruby-sass和livereload插件
查看>>
免费的大数据学习资料,这一份就足够
查看>>
clientWidth、clientHeight、offsetWidth、offsetHeight以及scrollWidth、scrollHeight
查看>>
企业级应用与互联网应用的区别
查看>>
itext jsp页面打印
查看>>
Perl正则表达式匹配
查看>>
DB Change
查看>>
nginx --rhel6.5
查看>>
Eclipse Python插件 PyDev
查看>>
selenium+python3模拟键盘实现粘贴、复制
查看>>
第一篇博客
查看>>
网站搭建(一)
查看>>
SDWebImage源码解读之SDWebImageDownloaderOperation
查看>>
elastaticsearch
查看>>