falcon 监控 tcp closewait

今天我们有台服务器,cpu使用率占满了,但是上去看,发现cpu steal使用超高,大概70%,后来同事可能是由于closewait高造成的。但是当前我们没有监控手段,还没有上。

这里就搞搞白。

查看了下过去的资料,发现其实之前有写过,但是资料不好找,所以干脆重新写个吧,考虑到本身falcon的监控指标里面已经有了很多tcp的状态,我只是补充一个closewait白。

#!/usr/bin/env python
#coding: utf8

import sys
import json
import requests
import time
import urllib2, base64
import commands

# 获取数据
value = commands.getoutput("ss -ane | grep -i 'close-wait' | wc -l")
value = int(value)

# 准备上报数据
p = []
endpoint = "10.0.2.90"
metric = "ss"
key = "closewait"
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

或者直接下载脚本

http://ojv12llai.bkt.clouddn.com/uploads/20170219195205.expand

crontab

* * * * * cd /data/openfalcon/open-falcon/agent/userdefine && ./ss.closewait

or

* * * * * cd /opt/machtalk/agent/userdefine && ./ss.closewait

/etc/crontab确保mailto = ”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值