Skip to content

Instantly share code, notes, and snippets.

@ushkinaz
Created February 3, 2012 05:44
Show Gist options
  • Save ushkinaz/1728378 to your computer and use it in GitHub Desktop.
Save ushkinaz/1728378 to your computer and use it in GitHub Desktop.
Flood Graylog Server
package ru.agent.commons;
import org.apache.log4j.Logger;
import org.graylog2.GelfMessage;
import org.graylog2.GelfSender;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @author Dmitry Sidorenko
* @date 2/2/12
*/
public class Flood {
@SuppressWarnings({"unused"})
private static final Logger LOGGER = Logger.getLogger(Flood.class);
public static long testNum;
public static int packetsToSend;
public static String FACILITY;
public static void main(String[] args) throws UnknownHostException, SocketException {
testNum = new Date().getTime();
packetsToSend = Integer.parseInt(args[0]);
int nThreads = Integer.parseInt(args[1]);
FACILITY = String.format("test-%s-%d", new Date().toString(), packetsToSend);
final GelfSender sender = new GelfSender("graylog2.dev.agent.ru");
ExecutorService service = Executors.newFixedThreadPool(nThreads);
LOGGER.info("Start sending:" + packetsToSend);
long startTime = System.currentTimeMillis();
for (int i = 0; i < packetsToSend; i++) {
service.submit(new MyRunnable(sender, i));
}
long duration = System.currentTimeMillis() - startTime;
LOGGER.info("Stop sending:" + packetsToSend + " took " + duration + " milliseconds");
double speed = ((double) duration) / packetsToSend;
LOGGER.info(speed + " ms per message");
service.shutdown();
}
private static class MyRunnable implements Runnable {
int num;
private final GelfSender sender;
public MyRunnable(GelfSender sender, int num) {
this.sender = sender;
this.num = num;
}
@Override
public void run() {
GelfMessage message = new GelfMessage("Test id:" + num, "FullMessage", new Date(), "6");
message.setHost("microsoft.com");
message.setFacility(FACILITY);
sender.sendMessage(message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment