forked from apache/storm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LoggingMetricsConsumer dumps metrics to log file
* Added a LoggingMetricsConsumer example of a MetricsConsumer. Use it by adding 'conf.registerMetricsConsumer(LoggingMetricsConsumer.class);' when you construct your topology. * Added a dedicated appender to the example logback/cluster.xml called METRICS. Its log format omits the class and priority since with the dedicated appender those are redu
- Loading branch information
Philip (flip) Kromer
committed
Jul 21, 2013
1 parent
470e7cd
commit ef94d01
Showing
3 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
storm-core/src/jvm/backtype/storm/metric/LoggingMetricsConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package backtype.storm.metric; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
import backtype.storm.metric.api.IMetricsConsumer; | ||
import backtype.storm.task.IErrorReporter; | ||
import backtype.storm.task.TopologyContext; | ||
import backtype.storm.utils.Utils; | ||
|
||
/* | ||
* Listens for all metrics, dumps them to log | ||
* | ||
* To use, add this to your topology's configuration: | ||
* conf.registerMetricsConsumer(backtype.storm.metrics.LoggingMetricsConsumer.class, 1); | ||
* | ||
* Or edit the storm.yaml config file: | ||
* | ||
* topology.metrics.consumer.register: | ||
* - class: "backtype.storm.metrics.LoggingMetricsConsumer" | ||
* parallelism.hint: 1 | ||
* | ||
*/ | ||
public class LoggingMetricsConsumer implements IMetricsConsumer { | ||
public static final Logger LOG = LoggerFactory.getLogger(LoggingMetricsConsumer.class); | ||
|
||
@Override | ||
public void prepare(Map stormConf, Object registrationArgument, TopologyContext context, IErrorReporter errorReporter) { } | ||
|
||
static private String padding = " "; | ||
|
||
@Override | ||
public void handleDataPoints(TaskInfo taskInfo, Collection<DataPoint> dataPoints) { | ||
StringBuilder sb = new StringBuilder(); | ||
String header = String.format("%d\t%15s:%-4d\t%3d:%-11s\t", | ||
taskInfo.timestamp, | ||
taskInfo.srcWorkerHost, taskInfo.srcWorkerPort, | ||
taskInfo.srcTaskId, | ||
taskInfo.srcComponentId); | ||
sb.append(header); | ||
for (DataPoint p : dataPoints) { | ||
sb.delete(header.length(), sb.length()); | ||
sb.append(p.name) | ||
.append(padding).delete(header.length()+23,sb.length()).append("\t") | ||
.append(p.value); | ||
LOG.info(sb.toString()); | ||
} | ||
} | ||
|
||
@Override | ||
public void cleanup() { } | ||
} |