前部戏曲
阿里云的文档地址
https://help.aliyun.com/document_detail/35178.html?spm=5176.product28572.6.549.xOKkM5
https://help.aliyun.com/document_detail/28606.html?spm=5176.doc28605.6.618.HtwGPE
反正以上我是看着啊,有点儿摸不着头脑。索性自己写一篇。
先展示一下我的自定义监控脚本。py+shell


#!/usr/bin/python import subprocess import os,sys import cms_post # 此模块到阿里官网下载。 def status(): actions = subprocess.Popen('sh server_port.sh',shell=True,stderr=subprocess.PIPE,stdout=subprocess.PIPE) a= int(actions.stdout.read().strip()) + int(actions2.stdout.read().strip()) return a a = status() cms_post.post("userid","WebServer",a,"WebServer","ecsinstanceId=i-28zdkoobp")


#!/bin/sh a=`netstat -plunt | grep 80|wc -l` echo $a
以上是对80端口简单的做监测。
然后放入定时任务,每五分钟执行一次即可。(根据实际情况而定)
当然,我是不指望你能马上懂。
首先咱解释一下python程序。
#!/usr/bin/python
import subprocess
import os,sys
import cms_post # 此模块到阿里官网下载。
# 以上三处填写的是调用模块,或者说导入模块。不了解者可以查看博主的博客,估计还是看不懂。
# 定义一个函数,专门查看
def status():
# 这是subprocess调用shell函数,so,此模块需要学习学习。
actions = subprocess.Popen('sh server_port.sh',shell=True,stderr=subprocess.PIPE,stdout=subprocess.PIPE)
a= int(actions.stdout.read().strip()) + int(actions2.stdout.read().strip())
# 返回shell 脚本得到的结果 。。
return a
a = status()
# 下面这一行才是重点,咱另起一处解答下
cms_post.post("userid","WebServer",a,"WebServer","ecsinstanceId=i-28zdkoobp")
专门解释一下阿里调用接口脚本
cms_post.post("userid","WebServer",a,"WebServer","ecsinstanceId=i-28zdkoobp")
userid:就是用户的个人账户ID。点击自己头像就能看到啦。
WebServer:
a: 这个就是你想返回给阿里云监控的值。这个值呢,我暂时只能看到是数字,其他的例如字符串,列表还有待尝试。
WebServer:
ecsinstanceId=i-28zdkoobp:
后续
经过反复的研究,阿里云的自定义监控完全不够使用,还得配合个zabbix进行使用。