org.graylog2.gelfclient.GelfTransports Java Examples

The following examples show how to use org.graylog2.gelfclient.GelfTransports. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GelfAppender.java    From logback-gelf-appender with Apache License 2.0 5 votes vote down vote up
private GelfConfiguration getGelfConfiguration() {

        final InetSocketAddress serverAddress = new InetSocketAddress(server, port);
        final GelfTransports gelfProtocol = GelfTransports.valueOf(protocol().toUpperCase());

        return new GelfConfiguration(serverAddress).transport(gelfProtocol)
            .queueSize(queueSize)
            .connectTimeout(connectTimeout)
            .reconnectDelay(reconnectDelay)
            .sendBufferSize(sendBufferSize)
            .tcpNoDelay(tcpNoDelay)
            .tcpKeepAlive(tcpKeepAlive);
    }
 
Example #2
Source File: GelfTransportsConverter.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public GelfTransports convertFrom(String value) {
    try {
        return GelfTransports.valueOf(Strings.nullToEmpty(value).toUpperCase(Locale.ENGLISH));
    } catch (IllegalArgumentException e) {
        throw new ParameterException("Couldn't convert value \"" + value + "\" to GELF transport.", e);
    }
}
 
Example #3
Source File: GelfTransportsConverter.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String convertTo(GelfTransports value) {
    if (value == null) {
        throw new ParameterException("Couldn't convert \"null\" to string.");
    }
    return value.name();
}
 
Example #4
Source File: Graylog2Plugin.java    From play2-graylog2 with Apache License 2.0 5 votes vote down vote up
public Graylog2Plugin(Application app) {
    final Configuration config = app.configuration();

    accessLogEnabled = config.getBoolean("graylog2.appender.send-access-log", false);
    queueCapacity = config.getInt("graylog2.appender.queue-size", 512);
    reconnectInterval = config.getMilliseconds("graylog2.appender.reconnect-interval", 500L);
    connectTimeout = config.getMilliseconds("graylog2.appender.connect-timeout", 1000L);
    isTcpNoDelay = config.getBoolean("graylog2.appender.tcp-nodelay", false);
    sendBufferSize = config.getInt("graylog2.appender.sendbuffersize", 0); // causes the socket default to be used
    try {
        canonicalHostName = config.getString("graylog2.appender.sourcehost", InetAddress.getLocalHost().getCanonicalHostName());
    } catch (UnknownHostException e) {
        canonicalHostName = "localhost";
        log.error("Unable to resolve canonical localhost name. " +
                "Please set it manually via graylog2.appender.sourcehost or fix your lookup service, falling back to {}", canonicalHostName);
    }
    // TODO make this a list and dynamically accessible from the application
    final String hostString = config.getString("graylog2.appender.host", "127.0.0.1:12201");
    final String protocol = config.getString("graylog2.appender.protocol", "tcp");

    final HostAndPort hostAndPort = HostAndPort.fromString(hostString);

    final GelfTransports gelfTransport = GelfTransports.valueOf(protocol.toUpperCase());

    final GelfConfiguration gelfConfiguration = new GelfConfiguration(hostAndPort.getHostText(), hostAndPort.getPort())
            .transport(gelfTransport)
            .reconnectDelay(reconnectInterval.intValue())
            .queueSize(queueCapacity)
            .connectTimeout(connectTimeout.intValue())
            .tcpNoDelay(isTcpNoDelay)
            .sendBufferSize(sendBufferSize);

    this.transport = GelfTransports.create(gelfConfiguration);

    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);

    gelfAppender = new GelfclientAppender(transport, getLocalHostName());
    gelfAppender.setContext(lc);
}
 
Example #5
Source File: MetricsGelfReporterConfiguration.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 4 votes vote down vote up
public GelfTransports getTransport() {
    return transport;
}
 
Example #6
Source File: GelfTransportsConverterTest.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void convertFromValidString() throws Exception {
    Assert.assertEquals(GelfTransports.UDP, new GelfTransportsConverter().convertFrom("UDP"));
}
 
Example #7
Source File: GelfTransportsConverterTest.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void convertFromValidLowerCaseString() throws Exception {
    assertEquals(GelfTransports.TCP, new GelfTransportsConverter().convertFrom("tcp"));
}
 
Example #8
Source File: GelfTransportsConverterTest.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void convertTo() throws Exception {
    assertEquals("UDP", new GelfTransportsConverter().convertTo(GelfTransports.UDP));
}
 
Example #9
Source File: GelfAppender.java    From log4j2-gelf with Apache License 2.0 4 votes vote down vote up
@Override
public void start() {
    super.start();
    client = GelfTransports.create(gelfConfiguration);
}
 
Example #10
Source File: GelfAppender.java    From logback-gelf-appender with Apache License 2.0 2 votes vote down vote up
private void createGelfClient() {

        client = GelfTransports.create(getGelfConfiguration());
    }