惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

Rat's Blog - ping

SmartPing:一个服务器Ping值监测工具,带报警功能 - Rat's Blog uPing:一个简单的服务器Ping值监测小工具 - Rat's Blog mPing:一键测试服务器回程ping脚本 - Rat's Blog
一个基于Python3的VPS服务器在线监控脚本 - Rat's Blog
博主: Rat's · 2018-03-13 · via Rat's Blog - ping
  •  发布时间:
  •  15040 次浏览
  •   2 条评论
  •  1214 字数
  • 分类: 主机教程
  1.  首页
  2. 正文  
  3. 分享到:

简介

本脚本基于Python3写的,原理是通过监测端定时运行监测程序来ping被监测端的VPS,只进行一次ping操作,并对反馈回来的数据进行分析,一旦发现ping失败了,就通过server酱推送到微信上,通知VPS服务器已经断线了。

使用

本脚本需要配合server酱的sckey使用,没有的去http://sc.ftqq.com申请一个。

1、安装Python3
一般Ubuntu系统都是自带Python3CentosDebian系统使用以下脚本进行安装。

#检查系统是否有Python3
python3 -V

#安装Python3
#CentOS系统
wget https://www.moerats.com/usr/shell/Python3/CentOS_Python3.6.sh && sh CentOS_Python3.6.sh
#Debian系统
wget https://www.moerats.com/usr/shell/Python3/Debian_Python3.6.sh && sh Debian_Python3.6.sh

2、安装requests
运行命令:

pip3 install requests

3、下载并编辑脚本

#下载脚本
wget https://www.moerats.com/usr/shell/Python3/ping_jk.py
#编辑脚本
nano ping_jk.py

修改以下两个地方:

key = 'SCKEY'  #SCKEY替换成你自己的SCKEY
hostname = "xx.xx.xx.xx"  #换成你需要监控的VPS的IP

然后Ctrl+C保存并退出。

4、运行脚本

python3 ping_jk.py

请配合crontab定时任务使用,建议每15分钟运行一次,参考:Linux系统Crontab的安装及定时任务的命令详解

提示:如果想监控多个VPS服务器,把pingcontent那里重复一下就可以了。不会重复的多用几个同样脚本,命名不同的脚本名称,并在监控提示那里编辑好服务器信息用来区分就可以了。

脚本来源:Hostloc论坛


版权声明:本文为原创文章,版权归 Rat's Blog 所有,转载请注明出处!

本文链接:https://www.moerats.com/archives/537/

如教程需要更新,或者相关链接出现404,可以在文章下面评论留言。

Vultr新用户注册送100美元/16个机房按小时计费,支持支付宝,【点击查看】。