Package org.apache.pinot.common.metrics
Class AbstractMetrics<QP extends AbstractMetrics.QueryPhase,M extends AbstractMetrics.Meter,G extends AbstractMetrics.Gauge,T extends AbstractMetrics.Timer>
- java.lang.Object
-
- org.apache.pinot.common.metrics.AbstractMetrics<QP,M,G,T>
-
- Direct Known Subclasses:
BrokerMetrics,ControllerMetrics,MinionMetrics,ServerMetrics
public abstract class AbstractMetrics<QP extends AbstractMetrics.QueryPhase,M extends AbstractMetrics.Meter,G extends AbstractMetrics.Gauge,T extends AbstractMetrics.Timer> extends Object
Common code for metrics implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractMetrics.Gaugestatic interfaceAbstractMetrics.Meterstatic interfaceAbstractMetrics.QueryPhasestatic interfaceAbstractMetrics.Timer
-
Field Summary
Fields Modifier and Type Field Description protected String_metricPrefixprotected PinotMetricsRegistry_metricsRegistry
-
Constructor Summary
Constructors Constructor Description AbstractMetrics(String metricPrefix, PinotMetricsRegistry metricsRegistry, Class clazz)AbstractMetrics(String metricPrefix, PinotMetricsRegistry metricsRegistry, Class clazz, boolean isTableLevelMetricsEnabled, Collection<String> allowedTables)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddCallbackGauge(String metricName, Callable<Long> valueCallback)Adds a new gauge whose values are retrieved from a callback function.voidaddCallbackGaugeIfNeeded(String metricName, Callable<Long> valueCallback)Similar to addCallbackGauge method.voidaddCallbackTableGaugeIfNeeded(String tableName, G gauge, Callable<Long> valueCallback)voidaddMeteredGlobalValue(M meter, long unitCount)Logs a value to a meter.PinotMeteraddMeteredGlobalValue(M meter, long unitCount, PinotMeter reusedMeter)Logs a value to a meter.voidaddMeteredTableValue(String tableName, M meter, long unitCount)Logs a value to a table-level meter.PinotMeteraddMeteredTableValue(String tableName, M meter, long unitCount, PinotMeter reusedMeter)Logs a value to a table-level meter.voidaddPhaseTiming(String tableName, QP phase, long nanos)voidaddPhaseTiming(String tableName, QP phase, long duration, TimeUnit timeUnit)voidaddTimedTableValue(String tableName, T timer, long duration, TimeUnit timeUnit)Logs the timing for a tablevoidaddTimedValue(T timer, long duration, TimeUnit timeUnit)Logs the timing for a global timervoidaddValueToGlobalGauge(G gauge, long unitCount)Adds a value to a table gauge.voidaddValueToTableGauge(String tableName, G gauge, long unitCount)Logs a value to a table gauge.booleancontainsGauge(String metricName)Check if the metric name appears in the gauge value map.protected abstract G[]getGauges()PinotMetergetMeteredTableValue(String tableName, M meter)protected abstract M[]getMeters()PinotMetricsRegistrygetMetricsRegistry()protected abstract QP[]getQueryPhases()protected StringgetTableName(String tableName)longgetValueOfGlobalGauge(G gauge)longgetValueOfGlobalGauge(G gauge, String suffix)longgetValueOfTableGauge(String tableName, G gauge)Gets the value of a table gauge.voidinitializeGlobalMeters()Initializes all global meters (such as exceptions count) to zero.voidremoveGauge(String gaugeName)Remove gauge from Pinot metrics.voidremoveTableGauge(String tableName, G gauge)Removes a table gauge given the table name and the gauge.voidsetValueOfGlobalGauge(G gauge, long value)Sets the value of a global gauge.voidsetValueOfGlobalGauge(G gauge, String suffix, long value)Sets the value of a custom global gauge.voidsetValueOfPartitionGauge(String tableName, int partitionId, G gauge, long value)Sets the value of a table partition gauge.voidsetValueOfTableGauge(String tableName, G gauge, long value)Sets the value of a table gauge.
-
-
-
Field Detail
-
_metricPrefix
protected final String _metricPrefix
-
_metricsRegistry
protected final PinotMetricsRegistry _metricsRegistry
-
-
Constructor Detail
-
AbstractMetrics
public AbstractMetrics(String metricPrefix, PinotMetricsRegistry metricsRegistry, Class clazz)
-
AbstractMetrics
public AbstractMetrics(String metricPrefix, PinotMetricsRegistry metricsRegistry, Class clazz, boolean isTableLevelMetricsEnabled, Collection<String> allowedTables)
-
-
Method Detail
-
getMetricsRegistry
public PinotMetricsRegistry getMetricsRegistry()
-
addPhaseTiming
public void addPhaseTiming(String tableName, QP phase, long duration, TimeUnit timeUnit)
-
addTimedTableValue
public void addTimedTableValue(String tableName, T timer, long duration, TimeUnit timeUnit)
Logs the timing for a table- Parameters:
tableName- The table associated with this timertimer- The name of timerduration- The log time duration time valuetimeUnit- The log time duration time unit
-
addTimedValue
public void addTimedValue(T timer, long duration, TimeUnit timeUnit)
Logs the timing for a global timer
-
addMeteredGlobalValue
public void addMeteredGlobalValue(M meter, long unitCount)
Logs a value to a meter.- Parameters:
meter- The meter to useunitCount- The number of units to add to the meter
-
addMeteredGlobalValue
public PinotMeter addMeteredGlobalValue(M meter, long unitCount, PinotMeter reusedMeter)
Logs a value to a meter.- Parameters:
meter- The meter to useunitCount- The number of units to add to the meterreusedMeter- The meter to reuse
-
addMeteredTableValue
public void addMeteredTableValue(String tableName, M meter, long unitCount)
Logs a value to a table-level meter.- Parameters:
tableName- The table namemeter- The meter to useunitCount- The number of units to add to the meter
-
addMeteredTableValue
public PinotMeter addMeteredTableValue(String tableName, M meter, long unitCount, PinotMeter reusedMeter)
Logs a value to a table-level meter.- Parameters:
tableName- The table namemeter- The meter to useunitCount- The number of units to add to the meterreusedMeter- The meter to reuse
-
getMeteredTableValue
public PinotMeter getMeteredTableValue(String tableName, M meter)
-
addValueToTableGauge
public void addValueToTableGauge(String tableName, G gauge, long unitCount)
Logs a value to a table gauge.- Parameters:
tableName- The table namegauge- The gauge to useunitCount- The number of units to add to the gauge
-
setValueOfTableGauge
public void setValueOfTableGauge(String tableName, G gauge, long value)
Sets the value of a table gauge.- Parameters:
tableName- The table namegauge- The gauge to usevalue- The value to set the gauge to
-
setValueOfPartitionGauge
public void setValueOfPartitionGauge(String tableName, int partitionId, G gauge, long value)
Sets the value of a table partition gauge.- Parameters:
tableName- The table namepartitionId- The partition namegauge- The gauge to usevalue- The value to set the gauge to
-
setValueOfGlobalGauge
public void setValueOfGlobalGauge(G gauge, String suffix, long value)
Sets the value of a custom global gauge.- Parameters:
suffix- The suffix to attach to the gauge namegauge- The gauge to usevalue- The value to set the gauge to
-
setValueOfGlobalGauge
public void setValueOfGlobalGauge(G gauge, long value)
Sets the value of a global gauge.- Parameters:
gauge- The gauge to usevalue- The value to set the gauge to
-
addValueToGlobalGauge
public void addValueToGlobalGauge(G gauge, long unitCount)
Adds a value to a table gauge.- Parameters:
gauge- The gauge to useunitCount- The number of units to add to the gauge
-
getValueOfGlobalGauge
public long getValueOfGlobalGauge(G gauge)
-
getValueOfTableGauge
public long getValueOfTableGauge(String tableName, G gauge)
Gets the value of a table gauge.- Parameters:
tableName- The table namegauge- The gauge to use
-
initializeGlobalMeters
public void initializeGlobalMeters()
Initializes all global meters (such as exceptions count) to zero.
-
addCallbackTableGaugeIfNeeded
public void addCallbackTableGaugeIfNeeded(String tableName, G gauge, Callable<Long> valueCallback)
-
addCallbackGaugeIfNeeded
public void addCallbackGaugeIfNeeded(String metricName, Callable<Long> valueCallback)
Similar to addCallbackGauge method. This method may be called multiple times, while it will be registered to callback function only once.- Parameters:
metricName- The name of the metricvalueCallback- The callback function used to retrieve the value of the gauge
-
addCallbackGauge
public void addCallbackGauge(String metricName, Callable<Long> valueCallback)
Adds a new gauge whose values are retrieved from a callback function.- Parameters:
metricName- The name of the metricvalueCallback- The callback function used to retrieve the value of the gauge
-
removeTableGauge
public void removeTableGauge(String tableName, G gauge)
Removes a table gauge given the table name and the gauge. The add/remove is expected to work correctly in case of being invoked across multiple threads.- Parameters:
tableName- table namegauge- the gauge to be removed
-
removeGauge
public void removeGauge(String gaugeName)
Remove gauge from Pinot metrics.- Parameters:
gaugeName- gauge name
-
getQueryPhases
protected abstract QP[] getQueryPhases()
-
getMeters
protected abstract M[] getMeters()
-
getGauges
protected abstract G[] getGauges()
-
containsGauge
public boolean containsGauge(String metricName)
Check if the metric name appears in the gauge value map.- Parameters:
metricName- metric name- Returns:
- True if the metric name appears on the gauge value map. False otherwise.
-
-