Permalink
Browse files

Added configuration option to set listening address for GELF service,…

… refs #SERVER-27
  • Loading branch information...
1 parent 476aa28 commit 105a9796112082d3992b4f7739074d84ad93fd98 @joschi joschi committed Dec 5, 2011
View
@@ -40,6 +40,7 @@ mongodb_threads_allowed_to_block_multiplier = 5
# Graylog Extended Log Format (GELF)
use_gelf = true
+gelf_listen_address = 0.0.0.0
gelf_listen_port = 12201
# Drools Rule File (Use to rewrite incoming log messages)
@@ -101,6 +101,9 @@
@Parameter(value = "use_gelf", required = true)
private boolean useGELF = false;
+ @Parameter(value = "gelf_listen_address")
+ private String gelfListenAddress = "0.0.0.0";
+
@Parameter(value = "gelf_listen_port", required = true, validator = InetPortValidator.class)
private int gelfListenPort = 12201;
@@ -206,6 +209,10 @@ public boolean isUseGELF() {
return useGELF;
}
+ public String getGelfListenAddress() {
+ return gelfListenAddress;
+ }
+
public int getGelfListenPort() {
return gelfListenPort;
}
@@ -37,22 +37,23 @@
import org.graylog2.messagehandlers.gelf.ChunkedGELFClientManager;
import org.graylog2.messagehandlers.gelf.GELFMainThread;
import org.graylog2.messagehandlers.syslog.SyslogServerThread;
+import org.graylog2.messagequeue.MessageQueue;
+import org.graylog2.messagequeue.MessageQueueFlusher;
+import org.graylog2.periodical.BulkIndexerThread;
import org.graylog2.periodical.ChunkedGELFClientManagerThread;
import org.graylog2.periodical.HostCounterCacheWriterThread;
import org.graylog2.periodical.MessageCountWriterThread;
+import org.graylog2.periodical.MessageRetentionThread;
+import org.graylog2.periodical.ServerValueWriterThread;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
+import java.net.InetSocketAddress;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-import org.graylog2.messagequeue.MessageQueue;
-import org.graylog2.messagequeue.MessageQueueFlusher;
-import org.graylog2.periodical.BulkIndexerThread;
-import org.graylog2.periodical.MessageRetentionThread;
-import org.graylog2.periodical.ServerValueWriterThread;
/**
* Main class of Graylog2.
@@ -167,7 +168,7 @@ public static void main(String[] args) {
// Start GELF threads
if (configuration.isUseGELF()) {
- initializeGELFThreads(configuration.getGelfListenPort(), scheduler);
+ initializeGELFThreads(configuration.getGelfListenAddress(), configuration.getGelfListenPort(), scheduler);
}
// Initialize AMQP Broker if enabled
@@ -230,8 +231,8 @@ private static void initializeMessageRetentionThread(ScheduledExecutorService sc
LOG.info("Retention time management active.");
}
- private static void initializeGELFThreads(int gelfPort, ScheduledExecutorService scheduler) {
- GELFMainThread gelfThread = new GELFMainThread(gelfPort);
+ private static void initializeGELFThreads(String gelfAddress, int gelfPort, ScheduledExecutorService scheduler) {
+ GELFMainThread gelfThread = new GELFMainThread(new InetSocketAddress(gelfAddress, gelfPort));
gelfThread.start();
scheduler.scheduleAtFixedRate(new ChunkedGELFClientManagerThread(ChunkedGELFClientManager.getInstance()), ChunkedGELFClientManagerThread.INITIAL_DELAY, ChunkedGELFClientManagerThread.PERIOD, TimeUnit.SECONDS);
@@ -23,6 +23,7 @@
import org.apache.log4j.Logger;
import java.net.DatagramPacket;
+import java.net.InetSocketAddress;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -37,26 +38,26 @@
private static final Logger LOG = Logger.getLogger(GELFMainThread.class);
- private int port = 0;
+ private InetSocketAddress socketAddress;
private ExecutorService threadPool = Executors.newCachedThreadPool();
/**
* Thread responsible for listening for GELF messages.
*
- * @param port The TCP port to listen on
+ * @param socketAddress The {@link InetSocketAddress} to bind to
*/
- public GELFMainThread(int port) {
- this.port = port;
+ public GELFMainThread(InetSocketAddress socketAddress) {
+ this.socketAddress = socketAddress;
}
/**
* Run the thread. Runs forever!
*/
@Override public void run() {
GELFServer server = new GELFServer();
- if (!server.create(this.port)) {
- throw new RuntimeException("Could not start GELF server. Do you have permissions to listen on UDP port " + this.port + "?");
+ if (!server.create(socketAddress)) {
+ throw new RuntimeException("Could not start GELF server. Do you have permissions to bind to " + socketAddress + "?");
}
// Run forever.
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
+import java.net.InetSocketAddress;
/**
* GELFThread.java: Jun 23, 2010 6:58:07 PM
@@ -47,17 +48,19 @@
/**
* Create the UDP socket.
*
- * @param port The port to listen on.
+ * @param socketAddress The {@link InetSocketAddress} to bind to
* @return boolean
*/
- public boolean create(int port) {
+ public boolean create(InetSocketAddress socketAddress) {
try {
- this.serverSocket = new DatagramSocket(port);
+ this.serverSocket = new DatagramSocket(socketAddress);
} catch(IOException e) {
LOG.fatal("Could not create ServerSocket in GELFServer::create(): " + e.getMessage(), e);
return false;
}
+ LOG.info("Started GELF server on " + socketAddress);
+
return true;
}

0 comments on commit 105a979

Please sign in to comment.