
alluxio.master.metrics.DefaultMetricsMaster Maven / Gradle / Ivy
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/
package alluxio.master.metrics;
import alluxio.Constants;
import alluxio.clock.SystemClock;
import alluxio.conf.Configuration;
import alluxio.conf.PropertyKey;
import alluxio.grpc.GrpcService;
import alluxio.grpc.MetricValue;
import alluxio.grpc.ServiceType;
import alluxio.heartbeat.FixedIntervalSupplier;
import alluxio.heartbeat.HeartbeatContext;
import alluxio.heartbeat.HeartbeatExecutor;
import alluxio.heartbeat.HeartbeatThread;
import alluxio.master.CoreMaster;
import alluxio.master.CoreMasterContext;
import alluxio.master.journal.NoopJournaled;
import alluxio.metrics.Metric;
import alluxio.metrics.MetricInfo;
import alluxio.metrics.MetricKey;
import alluxio.metrics.MetricsSystem;
import alluxio.metrics.MultiValueMetricsAggregator;
import alluxio.metrics.aggregator.SingleTagValueAggregator;
import alluxio.security.authentication.ClientContextServerInjector;
import alluxio.util.executor.ExecutorServiceFactories;
import alluxio.util.executor.ExecutorServiceFactory;
import com.codahale.metrics.Gauge;
import com.google.common.annotations.VisibleForTesting;
import io.grpc.ServerInterceptors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.time.Clock;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
* Default implementation of the metrics master.
*/
public class DefaultMetricsMaster extends CoreMaster implements MetricsMaster, NoopJournaled {
private static final Logger LOG = LoggerFactory.getLogger(DefaultMetricsMaster.class);
// A map from the to be aggregated metric name to aggregator itself
// This registry only holds aggregator for master metrics
private final Map mAggregatorRegistry = new HashMap<>();
private final MetricsStore mMetricsStore;
/**
* Creates a new instance of {@link MetricsMaster}.
*
* @param masterContext the context for metrics master
*/
DefaultMetricsMaster(CoreMasterContext masterContext) {
this(masterContext, new SystemClock(),
ExecutorServiceFactories.fixedThreadPool(Constants.METRICS_MASTER_NAME,
Configuration.getInt(PropertyKey.MASTER_METRICS_SERVICE_THREADS)));
}
/**
* Creates a new instance of {@link MetricsMaster}.
*
* @param masterContext the context for metrics master
* @param clock the clock to use for determining the time
* @param executorServiceFactory a factory for creating the executor service to use for running
* maintenance threads
*/
DefaultMetricsMaster(CoreMasterContext masterContext, Clock clock,
ExecutorServiceFactory executorServiceFactory) {
super(masterContext, clock, executorServiceFactory);
mMetricsStore = new MetricsStore(mClock);
registerAggregators();
}
@VisibleForTesting
protected void addAggregator(MultiValueMetricsAggregator aggregator) {
mAggregatorRegistry.put(aggregator.getFilterMetricName(), aggregator);
}
private void updateMultiValueMasterMetrics() {
Map> masterMetricsMap
= MetricsSystem.getMasterMetrics(mAggregatorRegistry.keySet());
for (Map.Entry> entry : masterMetricsMap.entrySet()) {
MultiValueMetricsAggregator aggregator = mAggregatorRegistry.get(entry.getKey());
for (Entry updated : aggregator.updateValues(entry.getValue()).entrySet()) {
MetricsSystem.registerGaugeIfAbsent(updated.getKey(), new Gauge
© 2015 - 2025 Weber Informatics LLC | Privacy Policy