Strom运行监控

总所周知,storm提供的UI界面进行查看运行情况,但是在storm的运行过程中,无法时刻进行观察storm UI界面是否有失败或者处理延时等情况,根据STORM提供的API进行抓取storm运行情况并输出log文件,进行文件监控,若发生失败场景进行报警处理。

由于使用log日志监控,使用python进行编写此案例,示例代码如下:

#!/usr/bin/python
# -*- coding:UTF-8 -*-

import json
import urllib
import urllib2
import os

global cbe_id
global out_id

cbe_id = ''
out_id = ''


def storm_topology():
    req = urllib2.Request('http://127.0.0.1:8080/api/v1/topology/summary')
    response = urllib2.urlopen(req)
    topology = response.read().replace('"',"'",-1).replace("false","'false'",-1).replace("true","'true'",-1).replace("null","'null'",-1)
    topo = eval(topology)
    jsonStromArray = json.loads(json.dumps(topo))
    for ids in jsonStromArray['topologies']:
        if ids['name'] == "otsp_storm-out":
            global out_id
            out_id = ids['id']
        else:
            global cbe_id
            cbe_id = ids['id']


def cbe_summary(cbe_id):
    request = urllib2.Request('http://127.0.0.1:8080/api/v1/topology/' + cbe_id)
    response = urllib2.urlopen(request)
    cbe_topology = response.read().replace('"',"'",-1).replace("false","'false'",-1).replace("true","'true'",-1).replace("null","'null'",-1)
    cbe_topology = eval(cbe_topology)
    jsonCbeArray = json.loads(json.dumps(cbe_topology))
    for stats in jsonCbeArray['topologyStats']:
         if (stats['failed'] == 'null' or stats['failed'] == 0):
               stat = "%s\n" % ('0')
         else:
               stat = "%s\n" % ('0'+str(stats['failed']))
         to_csv_cbe(stat)
         break


def out_summary(out_id):
    request = urllib2.Request('http://127.0.0.1:8080/api/v1/topology/' + out_id)
    response = urllib2.urlopen(request)
    out_topology = response.read().replace('"',"'",-1).replace("false","'false'",-1).replace("true","'true'",-1).replace("null","'null'",-1)
    out_topology = eval(out_topology)
    jsonOutArray = json.loads(json.dumps(out_topology))
    for stats in jsonOutArray['topologyStats']:
        if (stats['failed'] == 'null' or stats['failed'] == 0):
              stat = "%s\n" % ('0')
        else:
              stat = "%s\n" % ('0'+str(stats['failed']))
        to_csv_out(stat)
        break

def to_csv_cbe(data):
    with open("/home/wenxuechao/storm_cbe.result", "a") as csvfile:
        csvfile.write(data)
        csvfile.close()

def to_csv_out(data):
    with open("/home/wenxuechao/storm_out.result", "a") as csvfile:
        csvfile.write(data)
        csvfile.close()


storm_topology()
cbe_summary(cbe_id)
out_summary(out_id)

由于本次案例运行有两个拓扑,因此代码同时监控两个拓扑信息,本次示例仅抓去了最近10分钟的失败数,同样如果要监控CAPACITY或者latency等信息从数组进行获取即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wenxuechaozhe

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值