|
41 | 41 | import org.apache.commons.lang3.StringUtils; |
42 | 42 | import org.apache.http.HttpHeaders; |
43 | 43 | import org.apache.storm.Config; |
44 | | -import org.apache.storm.metric.api.MeanReducer; |
45 | | -import org.apache.storm.metric.api.MultiCountMetric; |
46 | | -import org.apache.storm.metric.api.MultiReducedMetric; |
47 | 44 | import org.apache.storm.task.OutputCollector; |
48 | 45 | import org.apache.storm.task.TopologyContext; |
49 | 46 | import org.apache.storm.topology.OutputFieldsDeclarer; |
|
54 | 51 | import org.apache.storm.utils.Utils; |
55 | 52 | import org.apache.stormcrawler.Constants; |
56 | 53 | import org.apache.stormcrawler.Metadata; |
| 54 | +import org.apache.stormcrawler.metrics.CrawlerMetrics; |
| 55 | +import org.apache.stormcrawler.metrics.ScopedCounter; |
| 56 | +import org.apache.stormcrawler.metrics.ScopedReducedMetric; |
57 | 57 | import org.apache.stormcrawler.persistence.Status; |
58 | 58 | import org.apache.stormcrawler.protocol.Protocol; |
59 | 59 | import org.apache.stormcrawler.protocol.ProtocolFactory; |
60 | 60 | import org.apache.stormcrawler.protocol.ProtocolResponse; |
61 | 61 | import org.apache.stormcrawler.protocol.RobotRules; |
62 | 62 | import org.apache.stormcrawler.util.ConfUtils; |
63 | | -import org.apache.stormcrawler.util.PerSecondReducer; |
64 | 63 | import org.apache.stormcrawler.util.URLUtil; |
65 | 64 | import org.slf4j.LoggerFactory; |
66 | 65 |
|
@@ -97,16 +96,16 @@ public class FetcherBolt extends StatusEmitterBolt { |
97 | 96 |
|
98 | 97 | private FetchItemQueues fetchQueues; |
99 | 98 |
|
100 | | - private MultiCountMetric eventCounter; |
101 | | - private MultiReducedMetric averagedMetrics; |
| 99 | + private ScopedCounter eventCounter; |
| 100 | + private ScopedReducedMetric averagedMetrics; |
102 | 101 |
|
103 | 102 | private ProtocolFactory protocolFactory; |
104 | 103 |
|
105 | 104 | private int taskId = -1; |
106 | 105 |
|
107 | 106 | boolean sitemapsAutoDiscovery = false; |
108 | 107 |
|
109 | | - private MultiReducedMetric perSecMetrics; |
| 108 | + private ScopedReducedMetric perSecMetrics; |
110 | 109 |
|
111 | 110 | private File debugfiletrigger; |
112 | 111 |
|
@@ -844,42 +843,34 @@ public void prepare( |
844 | 843 | // The data can be accessed by registering a "MetricConsumer" in the |
845 | 844 | // topology |
846 | 845 | this.eventCounter = |
847 | | - context.registerMetric( |
848 | | - "fetcher_counter", new MultiCountMetric(), metricsTimeBucketSecs); |
| 846 | + CrawlerMetrics.registerCounter( |
| 847 | + context, stormConf, "fetcher_counter", metricsTimeBucketSecs); |
849 | 848 |
|
850 | 849 | // create gauges |
851 | | - context.registerMetric( |
852 | | - "activethreads", |
853 | | - () -> { |
854 | | - return activeThreads.get(); |
855 | | - }, |
856 | | - metricsTimeBucketSecs); |
| 850 | + CrawlerMetrics.registerGauge( |
| 851 | + context, stormConf, "activethreads", activeThreads::get, metricsTimeBucketSecs); |
857 | 852 |
|
858 | | - context.registerMetric( |
| 853 | + CrawlerMetrics.registerGauge( |
| 854 | + context, |
| 855 | + stormConf, |
859 | 856 | "in_queues", |
860 | | - () -> { |
861 | | - return fetchQueues.inQueues.get(); |
862 | | - }, |
| 857 | + () -> fetchQueues.inQueues.get(), |
863 | 858 | metricsTimeBucketSecs); |
864 | 859 |
|
865 | | - context.registerMetric( |
| 860 | + CrawlerMetrics.registerGauge( |
| 861 | + context, |
| 862 | + stormConf, |
866 | 863 | "num_queues", |
867 | | - () -> { |
868 | | - return fetchQueues.queues.size(); |
869 | | - }, |
| 864 | + () -> fetchQueues.queues.size(), |
870 | 865 | metricsTimeBucketSecs); |
871 | 866 |
|
872 | 867 | this.averagedMetrics = |
873 | | - context.registerMetric( |
874 | | - "fetcher_average_perdoc", |
875 | | - new MultiReducedMetric(new MeanReducer()), |
876 | | - metricsTimeBucketSecs); |
| 868 | + CrawlerMetrics.registerMeanMetric( |
| 869 | + context, stormConf, "fetcher_average_perdoc", metricsTimeBucketSecs); |
877 | 870 |
|
878 | 871 | this.perSecMetrics = |
879 | | - context.registerMetric( |
880 | | - "fetcher_average_persec", |
881 | | - new MultiReducedMetric(new PerSecondReducer()), |
882 | | - metricsTimeBucketSecs); |
| 872 | + CrawlerMetrics.registerPerSecMetric( |
| 873 | + context, stormConf, "fetcher_average_persec", metricsTimeBucketSecs); |
883 | 874 |
|
884 | 875 | protocolFactory = ProtocolFactory.getInstance(conf); |
885 | 876 |
|
|
0 commit comments