openfalcon 添加http远程监控 (for status code and for content match)
来源:互联网 发布:科比生涯总数据 编辑:程序博客网 时间:2024/06/03 15:36
做个falcon的小脚本,一来可以监控http的返回吗,如果是2xx或者3xx就是对的,否则就是111; 二来监控内容是否包含, 如果包含那就是对的,否则返回111
直接上代码
#!/usr/bin/env python#coding: utf-8import os, sys, reimport jsonimport requestsimport timeimport urllib2, base64from socket import *def checkHttp(httpurl,neirong=''): # 获取数据 try: r = requests.get(httpurl, timeout=3) # 判断http返回码是不是正常 if r.status_code in [ 200, 201, 301, 302]: pass else: return 111 # 判断返回的里面有没有指定字符串 results = re.findall('%s'%neirong,r.text) if len(results) > 0: return 0 else: return 111 except Exception: return 111# 上报def uploadToAgent(p): 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"}' % connectionprint "开始 "# 准备上报数据def zuzhuangData(tags = '', value = ''): endpoint = "10.0.2.90" metric = "userdefine" key = "remotehttpcheck" timestamp = int(time.time()) step = 60 vtype = "GAUGE" i = { 'Metric' :'%s.%s'%(metric,key), 'Endpoint': endpoint, 'Timestamp': timestamp, 'Step': step, 'value': value, 'CounterType': vtype, 'TAGS': tags } return ip = []with open("./remotehttpcheck.txt") as f: for line in f: results = re.findall("(\S+)",line) print results httpurl = results[0] description = results[1] neirong = results[2] tags = "httpurl=%s,description=%s,neirong=%s"%(httpurl,description,neirong) value = checkHttp(httpurl,neirong) p.append(zuzhuangData(tags,value))print json.dumps(p, sort_keys=True,indent = 4)uploadToAgent(p)
- 上配置文件
http://www.baidu.com/ 百度 新闻https://www.baidu.com/ 百度 新闻
- 加cron
* * * * * cd /data/openfalcon/agent/userdefine && ./remotehttpcheck 1>>/tmp/1.txt 2>&1
- 看是否可以找到上报数据
- 添加报警template
咱们直接在上一个tcpcheck的 template模板里面进行添加
- 等待报警中…
- 搞定, 修改报警值
0 0
- openfalcon 添加http远程监控 (for status code and for content match)
- openfalcon 添加监控远程tcp端口异常情况
- HTTP Status Codes for Beginners
- XMLHttpRequest cannot load http://xxx. Response for preflight has invalid HTTP status code 404
- http status code and http1.1
- Js 跨域CORS报错 Response for preflight has invalid HTTP status code 405
- 通过url获取远程文件(for http and https)
- HTTP Status 500 No adapter for handler
- HTTP Status 500 - For input string: " 1"
- HTTP Status 404 - There is no Action mapped for namespace /jsp and action name login. type Status re
- “HTTP Status 404 - No result defined for action ****** and result result”错误解决方法
- HTTP Status 404 - No result defined for action XXXX and result success 处理
- HTTP Status 404 There is no Action mapped for namespace / and action name
- HTTP Status 404 - No result defined for action and result input
- HTTP Status 404 - No result defined for action …… and result input。
- struts2 上传文件 HTTP Status 404 - No result defined for action.....and result input
- HTTP Status 404 - No result defined for action com.lnzkx.action.PeronAction and result success
- Struts2:HTTP Status 404 - There is no Action mapped for namespace[ / ]and action name singleUpload.
- Gradle 's dependency cache may be corrupt
- Spark Python API 学习(1)
- Synergy 在ubuntu和windows中共用一套鼠标和键盘
- GitHub上收集的最全的前端资源汇总(包括前端学习、求职、开发资源)
- vector/list/map/set的插入、删除、遍历
- openfalcon 添加http远程监控 (for status code and for content match)
- ModelAndView详解
- replaceNode
- java面试题
- git ssh key生成步骤
- gpio驱动-》gpioHal-》gpioJni-》gpioService-》gpioTest
- R语言 hjust = 0, vjust = 1属性设置
- python中修改.properties文件方法
- java Queue中 add/offer,element/peek,remove/poll区别