use of loghub.configuration.ConfigException in project LogHub by fbacchella.
the class TestIntegrated method runStart.
@Test(timeout = 5000)
public void runStart() throws ConfigException, IOException, InterruptedException, IntrospectionException, InstanceNotFoundException, MalformedObjectNameException, ReflectionException {
loghub.Stats.reset();
String conffile = Configuration.class.getClassLoader().getResource("test.conf").getFile();
Start.main(new String[] { "--canexit", "-c", conffile });
Thread.sleep(500);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
StatsMBean stats = JMX.newMBeanProxy(mbs, StatsMBean.Implementation.NAME, StatsMBean.class);
JmxTimerMBean allevents_timer = JMX.newMBeanProxy(mbs, new ObjectName("metrics:name=Allevents.timer"), JmxTimerMBean.class);
JmxCounterMBean allevents_inflight = JMX.newMBeanProxy(mbs, new ObjectName("metrics:name=Allevents.inflight"), JmxCounterMBean.class);
Socket sender = tctxt.ctx.newSocket(Method.CONNECT, Type.PUB, "inproc://listener");
Socket receiver = tctxt.ctx.newSocket(Method.CONNECT, Type.PULL, "inproc://sender");
AtomicLong send = new AtomicLong();
Thread t = new Thread() {
@Override
public void run() {
try {
for (int i = 0; i < 100 && tctxt.ctx.isRunning(); i++) {
sender.send("message " + i);
send.incrementAndGet();
Thread.sleep(1);
}
} catch (InterruptedException e) {
}
logger.debug("All events sent");
}
};
t.start();
Pattern messagePattern = Pattern.compile("\\{\"a\":1,\"b\":\"google-public-dns-a\",\"message\":\"message \\d+\"\\}");
while (send.get() < 99 || allevents_inflight.getCount() != 0) {
logger.debug("send: {}, in flight: {}", send.get(), allevents_inflight.getCount());
while (receiver.getEvents() > 0) {
logger.debug("in flight: {}", allevents_inflight.getCount());
String content = receiver.recvStr();
Assert.assertTrue(messagePattern.matcher(content).find());
Thread.sleep(1);
}
;
Thread.sleep(50);
}
Thread.sleep(10);
Set<ObjectName> metrics = mbs.queryNames(new ObjectName("metrics:*"), null);
long blocked = 0;
dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=EventWaiting.") && i.toString().endsWith(".failed"), i -> (long) i.getValue(), JmxGaugeMBean.class);
dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=Pipeline.") && i.toString().endsWith(".failed"), i -> i.getCount(), JmxMeterMBean.class);
dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=Pipeline.") && i.toString().endsWith(".droped"), i -> i.getCount(), JmxMeterMBean.class);
blocked += dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=Pipeline.") && i.toString().endsWith(".blocked.in"), i -> i.getCount(), JmxMeterMBean.class);
blocked += dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=Pipeline.") && i.toString().endsWith(".blocked.out"), i -> i.getCount(), JmxMeterMBean.class);
dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=Pipeline.") && i.toString().endsWith(".inflight"), i -> i.getCount(), JmxMeterMBean.class);
logger.debug("dropped: " + stats.getDropped());
logger.debug("failed: " + stats.getFailed());
logger.debug("received: " + stats.getReceived());
logger.debug("sent: " + stats.getSent());
logger.debug(Arrays.toString(stats.getErrors()));
logger.debug(Arrays.toString(stats.getExceptions()));
long received = stats.getReceived();
Assert.assertTrue(received > 95);
Assert.assertEquals(0L, allevents_inflight.getCount());
Assert.assertEquals(received, allevents_timer.getCount());
Assert.assertEquals(received, blocked + stats.getSent());
}
use of loghub.configuration.ConfigException in project LogHub by fbacchella.
the class Start method launch.
public void launch(Properties props) throws ConfigException, IOException {
for (Source s : props.sources.values()) {
if (!s.configure(props)) {
logger.error("failed to start source {}", s.getName());
throw new IllegalStateException();
}
;
}
props.pipelines.stream().forEach(i -> i.configure(props));
for (Sender s : props.senders) {
if (s.configure(props)) {
s.start();
} else {
logger.error("failed to configure output {}", s.getName());
throw new IllegalStateException();
}
;
}
for (int i = 0; i < props.numWorkers; i++) {
Thread t = new EventsProcessor(props.mainQueue, props.outputQueues, props.namedPipeLine, props.maxSteps, props.repository);
t.setName("ProcessingThread" + i);
t.setDaemon(false);
t.start();
}
for (Receiver r : props.receivers) {
if (r.configure(props)) {
r.start();
} else {
logger.error("failed to configure input {}", r.getName());
throw new IllegalStateException();
}
}
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.registerMBean(new StatsMBean.Implementation(), StatsMBean.Implementation.NAME);
JmxReporter reporter = Properties.metrics.getJmxReporter();
reporter.start();
mbs.queryNames(ObjectName.getInstance("metrics", "name", "Pipeline.*.timer"), null).stream().map(i -> i.getKeyProperty("name")).map(i -> i.replaceAll("^Pipeline\\.(.*)\\.timer$", "$1")).forEach(i -> {
try {
mbs.registerMBean(new PipelineStat.Implementation(i), null);
} catch (NotCompliantMBeanException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
}
});
int port = props.jmxport;
if (port > 0) {
Helper.start(props.jmxproto, props.jmxlisten, port);
}
} catch (IOException | NotBoundException | NotCompliantMBeanException | MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
throw new RuntimeException("jmx configuration failed: " + e.getMessage(), e);
}
if (props.httpPort >= 0) {
AbstractHttpServer server = new DashboardHttpServer();
server.setPort(props.httpPort);
server.configure(props);
}
}
use of loghub.configuration.ConfigException in project LogHub by fbacchella.
the class Start method configure.
private void configure() {
if (testedprocessor != null) {
test = true;
dumpstats = false;
}
if (pipeLineTest != null) {
TestEventProcessing.check(pipeLineTest, configFile);
exitcode = 0;
}
if (dumpstats) {
final long starttime = System.nanoTime();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public synchronized void start() {
long endtime = System.nanoTime();
double runtime = ((double) (endtime - starttime)) / 1.0e9;
System.out.format("received: %.2f/s\n", Stats.received.get() / runtime);
System.out.format("dropped: %.2f/s\n", Stats.dropped.get() / runtime);
System.out.format("sent: %.2f/s\n", Stats.sent.get() / runtime);
System.out.format("failed: %.2f/s\n", Stats.failed.get() / runtime);
System.out.format("thrown: %.2f/s\n", Stats.thrown.get() / runtime);
}
});
}
try {
Properties props = Configuration.parse(configFile);
if (!test) {
launch(props);
logger.warn("LogHub started");
exitcode = 0;
} else if (testedprocessor != null) {
testProcessor(props, testedprocessor);
}
} catch (ConfigException e) {
Throwable t = e;
if (e.getCause() != null) {
t = e.getCause();
}
String message = t.getMessage();
if (message == null) {
message = t.getClass().getSimpleName();
}
System.out.format("Error in %s: %s\n", e.getLocation(), message);
exitcode = 1;
} catch (IllegalStateException e) {
exitcode = 1;
} catch (RuntimeException e) {
e.printStackTrace();
exitcode = 1;
} catch (IOException e) {
System.out.format("can't read configuration file %s: %s\n", configFile, e.getMessage());
exitcode = 11;
}
if (canexit && exitcode != 0) {
System.exit(exitcode);
} else if (exitcode != 0) {
throw new RuntimeException();
}
}
Aggregations