python怎么引入thrift文件_Python thrift-tools包_程序模块 - PyPI - Python中文网

本文介绍了如何利用thrift-tool工具进行Thrift协议的交互式分析,包括从网络流量中实时捕获和分析Thrift消息,以及从离线PCAP文件中进行内省。此外,还展示了如何通过JSON输出和jq筛选特定方法调用,以及统计Thrift服务的延迟信息。
摘要由CSDN通过智能技术生成

工具

节俭工具可以在互动模式下分析生活节俭

消息:$ sudo thrift-tool --iface eth0 --port 9091 dump --show-all --pretty

[00:39:42:850848] 10.1.8.7:49858 -> 10.1.2.20:3636: method=dosomething, type=call, seqid=1120

header: ()

fields: [ ( 'struct',

1,

[ ('string', 1, 'something to do'),

('i32', 3, 0),

( 'struct',

9,

[ ('i32', 3, 2),

('i32', 14, 0),

('i32', 16, 0),

('i32', 18, 25)])])]

------>[00:39:42:856204] 10.1.2.20:3636 -> 10.1.8.7:49858: method=dosomething, type=reply, seqid=1120

header: ()

fields: [ ( 'struct',

0,

[ ('string', 1, 'did something'),

('string', 2, 'did something else'),

('string', 3, 'did some other thing'),

('string', 4, 'did the last thing'),

('i32', 6, 3),

('i32', 7, 11),

('i32', 8, 0),

('i32', 9, 0),

('list', 10, [0]),

...

或者,脱机PCAP文件可以被内省:$ sudo thrift-tool --port 9091 --pcap-file /path/to/myservice.pcap dump

...

注意,您仍然需要设置正确的端口。

如果您正在使用Finagle,请尝试

例如:$ sudo thrift-tool --iface eth0 --port 9091 dump --show-all --pretty --finagle-thrift

...

json输出可用于通过jq轻松筛选和查询。为了

例如,您可以通过:$ sudo thrift-tool --port 3030 dump --unpaired --json | jq 'select(.method == "search" and .type == "call") | .src'

"10.1.18.5:48534"

"10.1.60.2:52008"

"10.1.10.27:49856"

"10.1.23.24:48116"

"10.1.26.7:60462"

"10.1.11.10:41895"

"10.1.15.13:35285"

"10.1.7.17:39759"

"10.1.1.19:35481"

...

通过^{tt1}可以收集每个方法的延迟统计信息$

命令:$ sudo thrift-tool --port 6666 stats --count 100

method count avg min max p90 p95 p99 p999

-------- ------- ---------- ---------- ---------- ---------- ---------- ---------- ----------

search2 61 0.00860996 0.00636292 0.0188479 0.010778 0.015192 0.0174422 0.0187074

doc 39 0.00134846 0.00099802 0.00274897 0.00177183 0.00199242 0.00256242 0.00273031

287 unmatched calls

您还可以指定.thrift文件以获得更好的输出:$ sudo thrift-tool --port 9091 dump --show-all --pretty --color --idl-file /path/to/myidl.thrift

...

列出所有可用选项:$ thrift-tool --help

请注意,对于具有高吞吐量的服务器(即:>两个KS数据包

每秒钟),节俭的工具可能很难跟上,因为

消息检测有点贵(而且你只能这么快

使用python)。对于这些情况,最好保存一个pcap文件

(即:通过tcpdump)然后对其进行后处理,即:$ tcpdump -nn -t port 3030 -w dump.pcap

$ sudo thrift-tool --port 3030 --pcap-file dump.pcap stats --count 40000

method count avg min max p90 p95 p99 p999

-------- ------- ---------- ---------- ---------- ---------- ---------- ---------- ----------

resize 40000 0.00850996 0.00336091 0.0101364 0.008071 0.009132 0.009890 0.01005665

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值