流量统计插件
getty提供了简单的流量统计插件,可方便统计总的字节以及规定时间内的吞吐量
AioServerStarter server = new AioServerStarter(8888);
server.bossThreadNum(10).channelInitializer(new ChannelInitializer() {
@Override
public void initChannel(AioChannel channel) throws Exception {
DefaultChannelPipeline defaultChannelPipeline = channel.getDefaultChannelPipeline();
//添加统计插件
ChannelTrafficShapingHandler channelTrafficShapingHandler= new ChannelTrafficShapingHandler(10000)
defaultChannelPipeline.addLast(channelTrafficShapingHandler);
//获取总读取字节数
channelTrafficShapingHandler.getTotalRead();
defaultChannelPipeline.addLast(new DelimiterFrameDecoder(DelimiterFrameDecoder.lineDelimiter));
defaultChannelPipeline.addLast(new StringDecoder());
defaultChannelPipeline.addLast(new SimpleHandler());
}
});
server.start();
构造方法
//checkInterval为统计时间间隔,单位为毫秒
ChannelTrafficShapingHandler(int checkInterval)
目前仅提供各通道总的读写字节数以及单位时间内的吞吐量
属性 | 类型 | 备注 |
---|---|---|
totalRead | long | 总读取字节 |
totalWrite | long | 总写出字节 |
intervalTotalRead | long | 时间间隔内读取的字节(吞吐量) |
intervalTotalWrite | long | 时间间隔内写出的字节(吞吐量) |
totalReadCount | long | 总读取次数 |
totolWriteCount | long | 总写出次数 |