提交 5a5632d0 编写于 作者: U unknown

modify the config

上级 883de335
......@@ -8,8 +8,7 @@ import com.dianping.cat.message.spi.MessageAnalyzer;
*/
public interface AnalyzerFactory {
public MessageAnalyzer create(String name, long start, long duration,
String domain, long extraTime);
public MessageAnalyzer create(String name, long start, long duration, String domain, long extraTime);
public void release(Object component);
......
......@@ -8,7 +8,8 @@ import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.log4j.Logger;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
......@@ -27,8 +28,52 @@ import com.site.lookup.annotation.Inject;
* @author yong.you
* @since Jan 5, 2012
*/
public class RealtimeConsumer extends ContainerHolder implements MessageConsumer, Initializable {
private static final Logger LOG = Logger.getLogger(RealtimeConsumer.class);
public class RealtimeConsumer extends ContainerHolder implements MessageConsumer, Initializable, LogEnabled {
static class Period {
private long m_startTime;
private long m_endTime;
private List<MessageQueue> m_queues;
public Period(long startTime, long endTime, List<MessageQueue> queues) {
m_startTime = startTime;
m_endTime = endTime;
m_queues = queues;
}
public List<MessageQueue> getQueues() {
return m_queues;
}
public boolean isIn(long timestamp) {
return timestamp >= m_startTime && timestamp < m_endTime;
}
}
static class Task implements Runnable {
private AnalyzerFactory m_factory;
private MessageAnalyzer m_analyzer;
private MessageQueue m_queue;
public Task(AnalyzerFactory factory, MessageAnalyzer analyzer, MessageQueue queue) {
m_factory = factory;
m_analyzer = analyzer;
m_queue = queue;
}
public MessageQueue getQueue() {
return m_queue;
}
public void run() {
m_analyzer.analyze(m_queue);
m_factory.release(m_analyzer);
m_factory.release(m_queue);
}
}
private static final long HOUR = 60 * 60 * 1000L;
......@@ -40,6 +85,9 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
private static final long FIVE_MINUTES = 5 * 60 * 1000L;
@Inject
private Logger m_logger;
@Inject
private String m_consumerId;
......@@ -94,7 +142,7 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
if (timestamp < now + MINUTE * 3 && timestamp >= nextStart) {
startTasks(tree);
} else {
LOG.warn("The message is not excepceted!" + tree);
m_logger.warn("The message is not excepceted!" + tree);
}
}
}
......@@ -109,6 +157,11 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
}
}
@Override
public void enableLogging(Logger logger) {
m_logger = logger;
}
@Override
public String getConsumerId() {
return m_consumerId;
......@@ -122,7 +175,7 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
public String getDomain() {
return m_domain;
}
public MessageAnalyzer getLastAnalyzer(String name) {
return m_lastAnalyzers.get(name);
}
......@@ -173,7 +226,7 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
private void startTasks(MessageTree tree) {
long time = tree.getMessage().getTimestamp();
long start = time - time % m_duration;
LOG.info("Start Tasks At " + new Date(start));
m_logger.info("Start Tasks At " + new Date(start));
List<MessageQueue> queues = new ArrayList<MessageQueue>();
Period current = new Period(start, start + m_duration, queues);
......@@ -200,50 +253,4 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
m_periods.add(current);
}
static class Period {
private long m_startTime;
private long m_endTime;
private List<MessageQueue> m_queues;
public Period(long startTime, long endTime, List<MessageQueue> queues) {
m_startTime = startTime;
m_endTime = endTime;
m_queues = queues;
}
public List<MessageQueue> getQueues() {
return m_queues;
}
public boolean isIn(long timestamp) {
return timestamp >= m_startTime && timestamp < m_endTime;
}
}
static class Task implements Runnable {
private AnalyzerFactory m_factory;
private MessageAnalyzer m_analyzer;
private MessageQueue m_queue;
public Task(AnalyzerFactory factory, MessageAnalyzer analyzer, MessageQueue queue) {
m_factory = factory;
m_analyzer = analyzer;
m_queue = queue;
}
public MessageQueue getQueue() {
return m_queue;
}
public void run() {
m_analyzer.analyze(m_queue);
m_factory.release(m_analyzer);
m_factory.release(m_queue);
}
}
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ import com.dianping.cat.consumer.transaction.TransactionReportAnalyzer;
import com.dianping.cat.message.spi.MessageConsumer;
import com.dianping.cat.message.spi.MessageManager;
import com.dianping.cat.message.spi.MessageQueue;
import com.dianping.cat.message.spi.MessageStorage;
import com.site.lookup.configuration.AbstractResourceConfigurator;
import com.site.lookup.configuration.Component;
......@@ -34,11 +35,14 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
, E("analyzerNames").value("failure,transaction")));
String failureTypes = "Error,RuntimeException,Exception";
all.add(C(Handler.class, "failure-handler", FailureHandler.class)//
.config(E("failureType").value(failureTypes)));
.config(E("failureType").value(failureTypes))//
.req(MessageStorage.class,"html"));
all.add(C(Handler.class, "long-url-handler", LongUrlHandler.class) //
.config(E("threshold").value("2000")));
.config(E("threshold").value("2000"))//
.req(MessageStorage.class,"html"));
all.add(C(FailureReportAnalyzer.class).is(PER_LOOKUP) //
.config(E("reportPath").value("target/report/failure")) //
......
......@@ -24,8 +24,8 @@ import com.dianping.cat.message.Message;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.message.spi.AbstractMessageAnalyzer;
import com.dianping.cat.message.spi.MessageManager;
import com.dianping.cat.message.spi.MessageStorage;
import com.dianping.cat.message.spi.MessageTree;
import com.dianping.cat.message.spi.internal.DefaultMessageTree;
import com.site.helper.Splitters;
import com.site.lookup.annotation.Inject;
......@@ -136,6 +136,14 @@ public class FailureReportAnalyzer extends AbstractMessageAnalyzer<FailureReport
}
public static abstract class AbstractHandler implements Handler {
@Inject
private MessageStorage m_storage;
public void setMessageStorage(MessageStorage storage) {
m_storage = storage;
}
protected Segment findOrCreateSegment(Message message, FailureReport report) {
long time = message.getTimestamp();
long segmentId = time - time % MINUTE;
......@@ -161,6 +169,16 @@ public class FailureReportAnalyzer extends AbstractMessageAnalyzer<FailureReport
}
return result;
}
private Entry getEntry(MessageTree tree) {
String base = m_storage.getBaseUrl().toString();
String url = m_storage.store(tree);
Entry entry = new Entry();
entry.setPath(base + url);
entry.setThreadId(tree.getThreadId());
return entry;
}
}
public static class FailureHandler extends AbstractHandler {
......@@ -168,13 +186,8 @@ public class FailureReportAnalyzer extends AbstractMessageAnalyzer<FailureReport
private Set<String> m_failureTypes;
private void addEntry(FailureReport report, Message message, MessageTree tree) {
Entry entry = super.getEntry(tree);
String messageId = tree.getMessageId();
String threadId = tree.getThreadId();
Entry entry = new Entry();
entry.setMessageId(messageId);
entry.setThreadId(threadId);
entry.setText(message.getName());
entry.setType(message.getType());
......@@ -234,15 +247,11 @@ public class FailureReportAnalyzer extends AbstractMessageAnalyzer<FailureReport
Message message = tree.getMessage();
if (message instanceof Transaction) {
String messageId = ((DefaultMessageTree) tree).getMessageId();
String threadId = ((DefaultMessageTree) tree).getThreadId();
Transaction t = (Transaction) message;
if (t.getDuration() > m_threshold) {
Entry entry = new Entry();
Entry entry = super.getEntry(tree);
entry.setMessageId(messageId);
entry.setThreadId(threadId);
entry.setText(message.getType() + message.getName());
entry.setType(LONG_URL);
......
......@@ -10,8 +10,7 @@ import com.site.helper.Files;
public class FailureReportStore {
private static final SimpleDateFormat SDF = new SimpleDateFormat(
"yyyy-MM-dd HH:mm");
private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm");
private static final String END = "\n";
......@@ -19,8 +18,7 @@ public class FailureReportStore {
try {
Files.forIO().writeTo(file, getStoreString(report));
} catch (IOException e) {
throw new RuntimeException(String.format(
"Unable to create file %s!", file), e);
throw new RuntimeException(String.format("Unable to create file %s!", file), e);
}
}
......@@ -32,13 +30,10 @@ public class FailureReportStore {
String jsonString = jsonBuilder.getString();
result.append("<html>").append(END).append("<head>").append(END)
.append("<title>").append(END).append("Failure Report ")
.append("From ").append(SDF.format(report.getStartTime()))
.append(" To ").append(SDF.format(report.getEndTime()))
.append(END).append("</title>").append(END).append("<body>")
.append(END).append(jsonString).append("</body>").append(END)
.append("</html>").append(END);
result.append("<html>").append(END).append("<head>").append(END).append("<title>").append(END).append(
"Failure Report ").append("From ").append(SDF.format(report.getStartTime())).append(" To ").append(
SDF.format(report.getEndTime())).append(END).append("</title>").append(END).append("<body>").append(END)
.append(jsonString).append("</body>").append(END).append("</html>").append(END);
return result.toString();
}
}
<model>
<entity name="failure-report" root="true">
<attribute name="domain" value-type="String" />
<attribute name="baseUrl" value-type="String" />
<attribute name="startTime" value-type="Date" format="yyyy-MM-dd HH:mm:ss" />
<attribute name="endTime" value-type="Date" format="yyyy-MM-dd HH:mm:ss" />
<entity-ref name="machines" />
......@@ -20,7 +21,7 @@
</entity>
<entity name="entry">
<attribute name="type" value-type="String" />
<attribute name="messageId" value-type="String" />
<attribute name="path" value-type="String" />
<attribute name="threadId" value-type="String" />
<element name="text" value-type="String" text="true" />
</entity>
......
......@@ -32,6 +32,12 @@
<configuration>
<failureType>Error,RuntimeException,Exception</failureType>
</configuration>
<requirements>
<requirement>
<role>com.dianping.cat.message.spi.MessageStorage</role>
<role-hint>html</role-hint>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.consumer.failure.FailureReportAnalyzer$Handler</role>
......@@ -40,6 +46,12 @@
<configuration>
<threshold>2000</threshold>
</configuration>
<requirements>
<requirement>
<role>com.dianping.cat.message.spi.MessageStorage</role>
<role-hint>html</role-hint>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.consumer.failure.FailureReportAnalyzer</role>
......
......@@ -86,7 +86,7 @@ function getIndex(object, array) {
function getUrl(type, text, messageId) {
if (type == 'RuntimeException') {
return '<a target=\'_blank\' style=\'background:red;\' href=\'www.dianping.com/messageId='
return '<a target=\'_blank\' style=\'background:red;\' href=\'w/messageId='
+ messageId + '\'>' + text + '</a>';
} else if (type == 'Exception') {
return '<a target=\'_blank\' style=\'background:#FFFF00;\' href=\'www.dianping.com/messageId='
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册