use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.
the class NetFlowUdpTransportTest method setUp.
@Before
public void setUp() {
final NettyTransportConfiguration nettyTransportConfiguration = new NettyTransportConfiguration("nio", "jdk", 1);
eventLoopGroupFactory = new EventLoopGroupFactory(nettyTransportConfiguration);
eventLoopGroup = new NioEventLoopGroup(1);
transport = new NetFlowUdpTransport(Configuration.EMPTY_CONFIGURATION, eventLoopGroupFactory, nettyTransportConfiguration, new ThroughputCounter(eventLoopGroup), new LocalMetricRegistry());
transport.setMessageAggregator(new NetflowV9CodecAggregator());
}
use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.
the class AbstractTcpTransport method getChildChannelHandlers.
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getChildChannelHandlers(MessageInput input) {
final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
final CodecAggregator aggregator = getAggregator();
handlers.put("channel-registration", () -> new ChannelRegistrationHandler(childChannels));
handlers.put("traffic-counter", () -> throughputCounter);
handlers.put("connection-counter", () -> connectionCounter);
if (tlsEnable) {
LOG.info("Enabled TLS for input [{}/{}]. key-file=\"{}\" cert-file=\"{}\"", input.getName(), input.getId(), tlsKeyFile, tlsCertFile);
handlers.put("tls", getSslHandlerCallable(input));
}
handlers.putAll(getCustomChildChannelHandlers(input));
if (aggregator != null) {
LOG.debug("Adding codec aggregator {} to channel pipeline", aggregator);
handlers.put("codec-aggregator", () -> new ByteBufMessageAggregationHandler(aggregator, localRegistry));
}
handlers.put("rawmessage-handler", () -> new RawMessageHandler(input));
handlers.put("exception-logger", () -> new ExceptionLoggingChannelHandler(input, LOG, this.tcpKeepalive));
return handlers;
}
use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.
the class BeatsTransportTest method customChildChannelHandlersContainBeatsHandler.
@Test
public void customChildChannelHandlersContainBeatsHandler() {
final NettyTransportConfiguration nettyTransportConfiguration = new NettyTransportConfiguration("nio", "jdk", 1);
final EventLoopGroupFactory eventLoopGroupFactory = new EventLoopGroupFactory(nettyTransportConfiguration);
final BeatsTransport transport = new BeatsTransport(Configuration.EMPTY_CONFIGURATION, eventLoopGroup, eventLoopGroupFactory, nettyTransportConfiguration, new ThroughputCounter(eventLoopGroup), new LocalMetricRegistry(), tlsConfiguration);
final MessageInput input = mock(MessageInput.class);
assertThat(transport.getCustomChildChannelHandlers(input)).containsKey("beats");
}
use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.
the class AbstractTcpTransportTest method getChildChannelHandlersFailsIfTempDirIsNoDirectory.
@Test
public void getChildChannelHandlersFailsIfTempDirIsNoDirectory() throws IOException {
final File file = temporaryFolder.newFile();
assumeTrue(file.isFile());
System.setProperty("java.io.tmpdir", file.getAbsolutePath());
final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "localhost", "port", 12345, "tls_enable", true));
final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, eventLoopGroup, eventLoopGroupFactory, nettyTransportConfiguration, tlsConfiguration) {
};
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Couldn't write to temporary directory: " + file.getAbsolutePath());
transport.getChildChannelHandlers(input);
}
use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.
the class AbstractTcpTransportTest method testTrafficCounter.
@Test
@Ignore("Disabled test due to being unreliable. For details see https://github.com/Graylog2/graylog2-server/issues/4702.")
public void testTrafficCounter() throws Exception {
final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "127.0.0.1", "port", 0));
final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, eventLoopGroup, eventLoopGroupFactory, nettyTransportConfiguration, tlsConfiguration) {
};
transport.launch(input);
await().atMost(5, TimeUnit.SECONDS).until(() -> transport.getLocalAddress() != null);
final InetSocketAddress localAddress = (InetSocketAddress) transport.getLocalAddress();
assertThat(localAddress).isNotNull();
final ChannelFuture channelFuture = clientChannel(localAddress.getHostString(), localAddress.getPort());
channelFuture.channel().writeAndFlush(Unpooled.copiedBuffer(new byte[1024])).syncUninterruptibly();
channelFuture.channel().writeAndFlush(Unpooled.copiedBuffer(new byte[1024])).addListener(ChannelFutureListener.CLOSE).syncUninterruptibly();
// Wait 1s so that the cumulative throughput can be calculated
Thread.sleep(1000L);
assertThat(throughputCounter.gauges().get(ThroughputCounter.READ_BYTES_TOTAL).getValue()).isEqualTo(2048L);
assertThat(throughputCounter.gauges().get(ThroughputCounter.READ_BYTES_1_SEC).getValue()).isEqualTo(2048L);
}
Aggregations