python监控端口脚本[jkport2.0.py]
#!/usr/bin/env python
#!coding=utf-8
import os
import time
import sys
import smtplib
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart def sendsimplemail (warning):
msg = MIMEText(warning)
msg['Subject'] = 'python first mail'
msg['From'] = 'root@localhost'
try:
smtp = smtplib.SMTP()
smtp.connect(r'pop.qq.com')
smtp.login('1427746783@qq.com', 'passwd')
smtp.sendmail('1427746783@qq.com', ['1427746783@qq.com'], msg.as_string())
smtp.close()
except Exception, e:
print e time_str = time.strftime( "%Y-%m-%d", time.localtime( ) )
file_name = "./" + time_str + ".log" while True:
print_str = "";
Pro_status = os.popen('netstat -tulnp | grep nginx','r').readlines()
now_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
try:
if Pro_status == []:
os.system('service nginx start')
new_Pro_status = os.popen('netstat -tulnp | grep nginx','r').readlines()
str1 = ''.join(new_Pro_status)
port = str1.split()[3].split(':')[-1]
if port != '9999':
print_str = print_str + "nginx start fail ..."
else:
print_str = print_str + "nginx Program abort. an internal error has occurred" + '\n'
print_str = print_str + "nginx start success ..."
# sendsimplemail(warning = "This is a warning!!!")
else:
print_str = print_str + now_time +"nginx running ..."
time.sleep(3) if os.path.exists ( file_name ) == False :
os.mknod( file_name )
handle = open ( file_name , "w" )
# print ( print_str + "**********1")
try:
handle.write( print_str)
except:
log.error('write backup error:')
finally:
handle.close()
# print ( print_str + "**********2")
else:
handle = open ( file_name , "a" )
print ( print_str + "**********3")
handle.write( print_str + '\n') except KeyboardInterrupt:
sys.exit('\n')
这个是jkport更新版, 旧版在这里:python监控端口脚本
新增日志输出功能
运行模式, 直接守护:nohup ./jkport.py &
不用像以前那么繁琐。
python监控端口脚本[jkport2.0.py]的更多相关文章
- python监控端口脚本[jkport1.0.py]
此脚本根据端口判断进程是否存活, 如果有指定的端口就证明进程是没问题的, 如果检测不到端口就是说业务进程已经挂掉了, 此时自动重启程序, 不多说下面请看脚本 创建脚本 我这里模拟的是nginx, 监控 ...
- python扫描端口脚本
# -*- coding:utf8 -*- # # Python: 2.7.8 # Platform: Windows # Authro: wucl # Program: 端口扫描 # History ...
- Python 监控脚本
Python 监控脚本 整体通过psutil模块动态获取资源信息.下为示例图: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time: 2019- ...
- centos 7中监控mysql 数据库脚本(监控端口)
centos 7中监控mysql 数据库脚本(监控端口) 监控mysql数据库的方法如下: 1.监控端口 netstat -nltp |grep 3306 2.监控进程 ps -ef |grep 33 ...
- 【JMeter4.0学习(五)】JMeter对服务器监控测试脚本开发
目录: 下载相关JMeter插件 服务器监控测试脚本开发 附:参考相关文档 本文主要来说一下如何通过JMeter插件来监控服务器CPU.内存.磁盘.网络等相关资源. 一.首先,需要下载相关JMeter ...
- python 监控redis的进程与端口
#!/usr/bin/python # -*- coding:utf-8 -*- import glob,psutil import json,os,datetime import collectio ...
- 【Linux】CentOS下升级Python和Pip版本全自动化py脚本
[Linux]CentOS下升级Python和Pip版本全自动化py脚本 CentOS7.6自带py2.7和py3.6 想要安装其它版本的话就要自己重新下载和编译py其它版本并且配置环境,主要是软链接 ...
- Zabbix如何实现批量监控端口状态
引言 ------------------------------------------------------------------------------------------------- ...
- Python数据库备份脚本
Python数据库备份脚本 #!/usr/bin/env python # author: liudong # -*- coding: utf-8 -*- # filename: db_bak.py ...
随机推荐
- 线段树(Segment Tree)总结
0 写在前面 怎么说呢,其实从入坑线段树一来,经历过两个阶段,第一个阶段是初学阶段,那个时候看网上的一些教学博文和模板入门了线段树, 然后挑选了一个线段树模板作为自己的模板,经过了一点自己的修改,然后 ...
- 用栈来递归 模板 honoi
用栈来模拟递归的技巧 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<vector> #include& ...
- angular2新建的项目上传github
前提1.git配置好,参见博文 git常用操作 2.angular2安装配置好,这个网上有很多教程,就不多说了,参见angular2快速起步 需要注意的是,大部分问题都是网络问题. 3.新建一个ng项 ...
- 统计难题---hdu1251字典树模板
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1251 node *head=(node*)malloc(sizeof(node)); for(int ...
- GDB调试qemu源码纪录
今天介绍下如何利用gdb调试qemu 1.首先获取qemu源码 获取地址:https://www.qemu.org/ 2.编译安装qemu 进入qemu目录 ./configure --enable- ...
- 借用HTML5 插入视频。音频
HTML5 规定了一种通过 video 元素来包含视频的标准方法. 插入视频 <video width="320" height="240" contro ...
- 网站/IIS/Web/WCF服务 访问共享目录 映射 的解决方案
目录 问题案例 原因分析 解决问题 总结 问题案例 环境: 电脑A:winform程序: 电脑B:部署了一个文件上传的WCF服务在IIS上.且该服务的配置文件中已经增加 <identity im ...
- Java8新特性 集合的stream的map
看该段代码(作用是把List中的对象替换): List<BlackMac> blackMacList = blackMacDao.queryBlackByMac(mac, (paginat ...
- qt——c++环境下qt编程,类的声明与构造
在c++中创建项目时,会生成以项目名字命名的QMainWindow,以及相应的头文件和CPP文件,作为主要窗口: 在项目中继续生成qt类时,比如类的名称是test,会自动生成一个test.h的头文件, ...
- MySQL找出锁等待
1.服务器级别的锁等待 可以通过show processlist看到等待锁的线程id,但是无法知道究竟哪个线程持有锁 可以通过mysqladmin debug 相关等待锁的线程以及谁持有锁可以在错误日 ...