falcon + url 获得json 数值画图并报警
2017-02-07 15:14
183 查看
有这么个需求,一个api可以获得当前设备的在线总数,如果少于某个数值,那么就得报警。
想来想去,接入falcon还是非常不错的。
首先我们需要一个脚本,可以获取api返回的json串,把数值挖出来,画图然后报警。
模板,需要添加yw.onlinetotal的报警
报警
绑定到host
想来想去,接入falcon还是非常不错的。
首先我们需要一个脚本,可以获取api返回的json串,把数值挖出来,画图然后报警。
脚本
#!/usr/bin/env python #coding: utf8 import sys import json import requests import time import urllib2, base64 # 获取数据 r = requests.get('http://xx/ss') r2 = json.loads(r.text) value = r2['online']['total'] # 准备上报数据 p = [] endpoint = "10.0.2.90" metric = "yw" key = "onlinetotal" timestamp = int(time.time()) step = 60 vtype = "GAUGE" tags = '' i = { 'Metric' :'%s.%s'%(metric,key), 'Endpoint': endpoint, 'Timestamp': timestamp, 'Step': step, 'value': value, 'CounterType': vtype, 'TAGS': tags } p.append(i) print json.dumps(p, sort_keys=True,indent = 4) sys.exit(0) # 上报 method = "POST" handler = urllib2.HTTPhandler() opener = urllib2.build_opener(handler) url = "http://127.0.0.1:1988/v1/push" request = urllib2.Request(url, data=json.dumps(p)) request.add_header('Content-Type','application/json') request.get_method = lambda: method try: connection = opener.open(request) except urllib2.HTTPError,e: connection = e if connection.code == 200: print connection.read() else: print '{"err":1,"msg":"%s"}' % connection
falcon 的设置
cron, 一分钟运行一次,记得 修改/etc/crontab,把mailto改成空,要不很有可能造成FD不够用,因为都是一个个小邮件模板,需要添加yw.onlinetotal的报警
报警
绑定到host
相关文章推荐
- Falcon教程
- 简析运维监控系统及Open-Falcon
- 玩转open-falcon
- 小米监控系统open-falcon安装
- open-falcon "Dashboard" 报SSL错
- open-falcon监控windows机器
- open-falcon+grafana出图
- 小米开源监控系统Open-Falcon安装使用笔记
- MYISAM,INNODB,FALCON的速度简单比较
- DSG RealSync与Falcon CDP的容灾技术对比
- falcon存储引擎入门(一)
- falcon-web文件监控
- Open-falcon监控的部署
- Open-Falcon安装详解
- Open-Falcon install script(Open-Falcon监控一键安装脚本)
- CentOS 7单机部署Open-Falcon监控
- open-falcon简介
- falcon接口统计
- 【小米开源监控系统】open-falcon
- open-falcon部署