sina kanyun 应用api-client使用问题 修改


最近在玩openstack虚拟机性能监控,在网上看见sina有个项目kanyun,就拿来看看。

说实在的,kanyun在网上的各方面资料太少了,除了源码目录下的README.rst文件可供参考,还没别的资料。

(kanyun安装配置后续)

编译成功后,在当前目录bin下运行kanyun-worker、kanyun-server、kanyun-api正常运行后,执行api-client(使用方法看帮助 --help)

当发现 api_client -l <metric>这类型命令不能正常执行,于是看api-client文件是如何写的(python语言),发现这是去调用方法show_result()

通过打印出来数据可以分析出show_result()方法根本无法解析。看了worker采集数据格式

   [('cpu', 'total', (utc_time, cpu_usage)),
    ('mem', 'total', (utc_time, max, free)),
    ('nic', 'vnet8', (utc_time, incoming, outgoing(内网))),
    ('blk', 'vda', (utc_time, read, write)),
    ('blk', 'vdb', (utc_time, read, write))],

于是把show_result 重新写成了两个方法

#show cpu or mem data<<added by yfwang 2012/11/14
def show_result_cpu_or_mem(rs):
        if rs is None:
                return
#       print rs
        if rs.has_key("data"):
                rs = rs['data']
#       print rs
        if rs:
                for i in rs:
                        #show vm_instance_id
                        print i[0]

                        rrs = i[1]
                        if rrs is None:
                                continue
                        rrrs = rrs['total']
                        if rrrs is None:
                                continue
                        for k, j in rrrs.items():
                                print "{%s:%s}" % (k,j)
                print "%d results" % (len(rrrs))
                print "spend", time.clock(), "seconds"

#show zhe blk write or read data>>added by yfwang 2012/11/14
def show_result_blk(rs):
        if rs is None:
                return
        if rs.has_key("data"):
                rs = rs['data']
        if rs:
                for i in rs:
                        #print zhe vm_instance_id
                        print i[0]

                        rrs = i[1]
                        if rrs is None:
                                continue
                        rrrs = rrs['vda']
                        if rrrs is None:
                                continue
                        for k, j in rrrs.iteritems():
                                print "{%s:%s}" % (k,j)
                print "%d results" % (len(rrrs))
                print "spend", time.clock(), "seconds"
#>>added endle

分别获取cpu、内存、磁盘读写(--help帮助里面没有blk_write 参数,测试过后也能正常使用)

再main()中修改下下面调用方法

92             show_result(rs)
丢改为

fixed zhe get cpu_mem_blk data error<<added by yfwang 2012/11/14
            if (metric == 'cpu') or (metric == 'mem_max') or (metric == 'mem_free'):
                show_result_cpu_or_mem(rs)
            elif(metric =='blk_read') or (metric == 'blk_write'):
                show_result_blk(rs)
#>>added endle

再次运行

root@PS-13:~/zyluo-kanyun-62502d2/bin# ./api-client -l cpu |more
36af2970-a74d-411d-8ade-7c51d67d669c
{1352855763:6.69233091701}
{1352878022:6.59855863378}
{1352856723:6.56101017833}
{1352883785:6.4759607841}
{1352862664:6.77603634792}
{1352857921:6.57525540079}
{1352799304:6.49893367316}
{1352798342:6.6578822537}
{1352866024:6.59187200205}
{1352797928:6.64892713501}
{1352876161:6.65871108381}
{1352877484:6.67192524452}
{1352879942:6.63418791946}
{1352800564:6.44165796132}


root@PS-13:~/zyluo-kanyun-62502d2/bin# ./api-client -l blk_read |more
36af2970-a74d-411d-8ade-7c51d67d669c
{1352855763:0}
{1352878023:0}
{1352883785:0}
{1352862664:0}
{1352857921:0}
{1352799304:0}
{1352798342:0}
{1352866024:0}
{1352797928:0}
{1352876161:0}
{1352877486:0}
{1352879943:0}
{1352873284:0}
{1352800564:0}
{1352877840:0}


得到数据正确结果


在上面没用测试网络,openstack网络还未配置完成,网络可仿上面添加即可。







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值