Add logging configuration.
This commit is contained in:
parent
83407453cc
commit
c97fe54152
4
pom.xml
4
pom.xml
|
@ -69,12 +69,12 @@
|
|||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.2</version>
|
||||
<version>1.7.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.2</version>
|
||||
<version>1.7.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
|
|
@ -1,65 +1,69 @@
|
|||
package com.hpcloud.mon;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import backtype.storm.Config;
|
||||
import backtype.storm.LocalCluster;
|
||||
import backtype.storm.StormSubmitter;
|
||||
import backtype.storm.generated.StormTopology;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.core.util.StatusPrinter;
|
||||
import com.hpcloud.util.Injector;
|
||||
import com.hpcloud.util.config.ConfigurationFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Alarm thresholding engine.
|
||||
*
|
||||
*
|
||||
* @author Jonathan Halterman
|
||||
*/
|
||||
public class ThresholdingEngine {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ThresholdingEngine.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ThresholdingEngine.class);
|
||||
|
||||
private final ThresholdingConfiguration threshConfig;
|
||||
private final String topologyName;
|
||||
private final boolean local;
|
||||
private final ThresholdingConfiguration threshConfig;
|
||||
private final String topologyName;
|
||||
private final boolean local;
|
||||
|
||||
public ThresholdingEngine(ThresholdingConfiguration threshConfig, String topologyName,
|
||||
boolean local) {
|
||||
this.threshConfig = threshConfig;
|
||||
this.topologyName = topologyName;
|
||||
this.local = local;
|
||||
}
|
||||
|
||||
public static final ThresholdingConfiguration configFor(String configFileName) throws Exception {
|
||||
return ConfigurationFactory.<ThresholdingConfiguration>forClass(ThresholdingConfiguration.class)
|
||||
.build(new File(configFileName));
|
||||
}
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
if (args.length < 2) {
|
||||
LOG.error("Expected configuration file name and topology name arguments");
|
||||
System.exit(1);
|
||||
public ThresholdingEngine(ThresholdingConfiguration threshConfig, String topologyName,
|
||||
boolean local) {
|
||||
this.threshConfig = threshConfig;
|
||||
this.topologyName = topologyName;
|
||||
this.local = local;
|
||||
}
|
||||
|
||||
ThresholdingEngine engine = new ThresholdingEngine(configFor(args[0]), args[1],
|
||||
args.length > 2 ? true : false);
|
||||
engine.configure();
|
||||
engine.run();
|
||||
}
|
||||
public static final ThresholdingConfiguration configFor(String configFileName) throws Exception {
|
||||
return ConfigurationFactory.<ThresholdingConfiguration>forClass(ThresholdingConfiguration.class)
|
||||
.build(new File(configFileName));
|
||||
}
|
||||
|
||||
protected void configure() {
|
||||
Injector.registerModules(new TopologyModule(threshConfig));
|
||||
}
|
||||
public static void main(String... args) throws Exception {
|
||||
|
||||
protected void run() throws Exception {
|
||||
Config config = Injector.getInstance(Config.class);
|
||||
StormTopology topology = Injector.getInstance(StormTopology.class);
|
||||
// Let's show the logging status.
|
||||
StatusPrinter.print((LoggerContext) LoggerFactory.getILoggerFactory());
|
||||
|
||||
if (local)
|
||||
new LocalCluster().submitTopology(topologyName, config, topology);
|
||||
else
|
||||
StormSubmitter.submitTopology(topologyName, config, topology);
|
||||
}
|
||||
if (args.length < 2) {
|
||||
LOG.error("Expected configuration file name and topology name arguments");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
ThresholdingEngine engine = new ThresholdingEngine(configFor(args[0]), args[1],
|
||||
args.length > 2 ? true : false);
|
||||
engine.configure();
|
||||
engine.run();
|
||||
}
|
||||
|
||||
protected void configure() {
|
||||
Injector.registerModules(new TopologyModule(threshConfig));
|
||||
}
|
||||
|
||||
protected void run() throws Exception {
|
||||
Config config = Injector.getInstance(Config.class);
|
||||
StormTopology topology = Injector.getInstance(StormTopology.class);
|
||||
|
||||
if (local)
|
||||
new LocalCluster().submitTopology(topologyName, config, topology);
|
||||
else
|
||||
StormSubmitter.submitTopology(topologyName, config, topology);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,10 +63,12 @@ public abstract class KafkaSpout extends BaseRichSpout {
|
|||
|
||||
@Override
|
||||
public void nextTuple() {
|
||||
|
||||
LOG.debug("nextTuple called");
|
||||
ConsumerIterator<byte[], byte[]> it = streams.get(0).iterator();
|
||||
if (it.hasNext()) {
|
||||
processMessage(it.next().message(), collector);
|
||||
byte[] message = it.next().message();
|
||||
LOG.debug("Received message: " + message);
|
||||
processMessage(message, collector);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<configuration scan="true" scanPeriod="30 seconds">
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!-- encoders are assigned the type
|
||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>mon-thresh.log</file>
|
||||
|
||||
<encoder>
|
||||
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<logger name="com.hpcloud" level = "debug"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
</configuration>
|
Loading…
Reference in New Issue