|
29 | 29 | import com.arpnetworking.metrics.incubator.PeriodicMetrics;
|
30 | 30 | import com.arpnetworking.metrics.mad.model.Record;
|
31 | 31 | import com.arpnetworking.metrics.mad.model.statistics.Statistic;
|
| 32 | +import com.arpnetworking.metrics.mad.model.statistics.StatisticFactory; |
32 | 33 | import com.arpnetworking.steno.LogValueMapFactory;
|
33 | 34 | import com.arpnetworking.steno.Logger;
|
34 | 35 | import com.arpnetworking.steno.LoggerFactory;
|
| 36 | +import com.arpnetworking.tsdcore.model.CalculatedValue; |
35 | 37 | import com.arpnetworking.tsdcore.model.DefaultKey;
|
36 | 38 | import com.arpnetworking.tsdcore.model.Key;
|
37 | 39 | import com.arpnetworking.tsdcore.sinks.Sink;
|
38 | 40 | import com.arpnetworking.utility.Launchable;
|
39 | 41 | import com.google.common.cache.CacheBuilder;
|
40 | 42 | import com.google.common.cache.CacheLoader;
|
41 | 43 | import com.google.common.cache.LoadingCache;
|
| 44 | +import com.google.common.collect.ImmutableList; |
42 | 45 | import com.google.common.collect.ImmutableMap;
|
43 | 46 | import com.google.common.collect.ImmutableSet;
|
44 | 47 | import com.google.common.collect.Lists;
|
@@ -122,6 +125,33 @@ public void notify(final Observable observable, final Object event) {
|
122 | 125 |
|
123 | 126 | final Record record = (Record) event;
|
124 | 127 | final Key key = new DefaultKey(record.getDimensions());
|
| 128 | + |
| 129 | + _periodicMetrics.recordGauge( |
| 130 | + "aggregator/samples", |
| 131 | + record.getMetrics().values().stream() |
| 132 | + .map(m -> { |
| 133 | + final ImmutableList<CalculatedValue<?>> countStatistic = m.getStatistics().get( |
| 134 | + STATISTIC_FACTORY.getStatistic("count")); |
| 135 | + if (countStatistic != null) { |
| 136 | + return countStatistic.stream() |
| 137 | + .map(s -> s.getValue().getValue()) |
| 138 | + .reduce(Double::sum) |
| 139 | + .orElse(0.0d) |
| 140 | + + |
| 141 | + m.getValues().size(); |
| 142 | + } |
| 143 | + if (!m.getStatistics().isEmpty()) { |
| 144 | + LOGGER.warn() |
| 145 | + .setMessage("Received record with statistics but with no count") |
| 146 | + .addData("record", record) |
| 147 | + .addData("key", key) |
| 148 | + .log(); |
| 149 | + } |
| 150 | + return (double) m.getValues().size(); |
| 151 | + }) |
| 152 | + .reduce(Double::sum) |
| 153 | + .orElse(0.0d)); |
| 154 | + |
125 | 155 | LOGGER.trace()
|
126 | 156 | .setMessage("Sending record to aggregation actor")
|
127 | 157 | .addData("record", record)
|
@@ -251,6 +281,7 @@ public Optional<ImmutableSet<Statistic>> load(final String metric) throws Except
|
251 | 281 | private final LoadingCache<String, Optional<ImmutableSet<Statistic>>> _cachedDependentStatistics;
|
252 | 282 | private final Map<Key, List<ActorRef>> _periodWorkerActors = Maps.newConcurrentMap();
|
253 | 283 |
|
| 284 | + private static final StatisticFactory STATISTIC_FACTORY = new StatisticFactory(); |
254 | 285 | private static final Timeout SHUTDOWN_TIMEOUT = Timeout.apply(1, TimeUnit.SECONDS);
|
255 | 286 | private static final Logger LOGGER = LoggerFactory.getLogger(Aggregator.class);
|
256 | 287 |
|
|
0 commit comments