com.arpnetworking.clusteraggregator.PeriodicStatisticsActor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metrics-cluster-aggregator Show documentation
Show all versions of metrics-cluster-aggregator Show documentation
(Re)Aggregates host level statistics across clusters and writes both host and cluster statistics to various destinations.
/*
* Copyright 2014 Groupon.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arpnetworking.clusteraggregator;
import akka.actor.AbstractActor;
import akka.actor.Props;
import com.arpnetworking.clusteraggregator.models.MetricsRequest;
import com.arpnetworking.clusteraggregator.models.PeriodMetrics;
import com.arpnetworking.metrics.MetricsFactory;
import com.arpnetworking.tsdcore.model.AggregatedData;
import com.google.common.collect.Maps;
import org.joda.time.Period;
import java.util.Map;
/**
* Actor that listens for metrics messages, updates internal state, and emits them.
*
* @author Brandon Arp (brandon dot arp at inscopemetrics dot com)
*/
public class PeriodicStatisticsActor extends AbstractActor {
/**
* Creates a Props
for construction in Akka.
*
* @param metricsFactory A MetricsFactory
to use for metrics creation.
* @return A new Props
.
*/
public static Props props(final MetricsFactory metricsFactory) {
return Props.create(PeriodicStatisticsActor.class, metricsFactory);
}
/**
* Public constructor.
*
* @param metricsFactory A MetricsFactory
to use for metrics creation.
*/
public PeriodicStatisticsActor(final MetricsFactory metricsFactory) {
_metricsFactory = metricsFactory;
}
@SuppressWarnings("deprecation")
@Override
public Receive createReceive() {
return receiveBuilder()
.match(AggregatedData.class, report -> {
final Period period = report.getPeriod();
PeriodMetrics metrics = _periodMetrics.get(period);
if (metrics == null) {
metrics = new PeriodMetrics(_metricsFactory);
_periodMetrics.put(period, metrics);
}
metrics.recordAggregation(report);
})
.match(MetricsRequest.class, message -> getSender().tell(_periodMetrics, getSelf()))
.build();
}
private final Map _periodMetrics = Maps.newHashMap();
private final MetricsFactory _metricsFactory;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy