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 ...
随机推荐
- 使用sift特征点进行knn最近邻匹配
#include <opencv2/xfeatures2d/nonfree.hpp> #include <opencv2/features2d/features2d.hpp> ...
- c++中system("pause")的作用和含义
简单来说就是暂停的意思,一般在LINUX编程时会用到,等待接收信号,才会重新运行 . 在进行C/C++编程的时候,在运行程序查看输出效果时,会出现窗口闪一下就关闭的情况. 在C语言中一般通过添加get ...
- oel5.5安装mysql数据库初始化报错解决办法
[root@chavinking mysql]# scripts/mysql_install_db --user=mysqlInstalling MySQL system tables...2016- ...
- What is Gensim?
Gensim是一款开源的第三方Python工具包,用于从原始的非结构化的文本中,无监督地学习到文本隐层的主题向量表达.它支持包括TF-IDF,LSA,LDA,和word2vec在内的多种主题模型算法, ...
- 【Echarts】图表用echarts【待完善】
echarts是做数据统计. ECharts,一个纯 Javascript 的图表库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8/9/10/11,Chrome,Firefox ...
- mysql 内置功能 视图介绍
之前的多表查询本质是把多张有关系的表连接在一起组成一张虚拟表,从而进行查询 视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名], 用户使用时只需使用[名称]即 ...
- xss跨站脚本攻击及xss漏洞防范
xss跨站脚本攻击(Cross Site Scripting,因与css样式表相似故缩写为XSS).恶意攻击者往Web页面里插入恶意Script代码,当用户浏览该页之时,嵌入其中Web里面的Scrip ...
- js定位当前位置的坐标经纬度和地点名称和天气
<script src="http://api.map.baidu.com/api?v=2.0&ak=s6vFvPKgaEnI2ImqBpKGDj0m">< ...
- Kylin安装问题--/home/hadoop-2.5.1/contrib/capacity-scheduler/.jar (No such file or directory)
WARNING: Failed to process JAR [jar:file:/home/hadoop-2.5.1/contrib/capacity-scheduler/.jar!/] for T ...
- [py]django上线部署-uwsgi+nginx+py3/django1.10
https://github.com/lannyMa/django-uwsgi-nginx.git 单机调试启动-确保项目代码没问题 - 克隆代码进入项目 git clone https://gith ...