阿里云自定义监控

本文介绍了一种利用Python和Shell脚本实现阿里云自定义监控的方法,通过定时任务每五分钟监测一次80端口,并将结果上报至阿里云监控系统。

前部戏曲

阿里云的文档地址

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")
python调用脚本
#!/bin/sh

a=`netstat -plunt | grep 80|wc -l`
echo  $a
server_port.sh

以上是对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进行使用。

 

转载于:https://www.cnblogs.com/can-H/articles/7559663.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值