org.apache.hadoop.hbase.regionserver.metrics
Class SchemaMetrics

java.lang.Object
  extended by org.apache.hadoop.hbase.regionserver.metrics.SchemaMetrics

public class SchemaMetrics
extends Object

A collection of metric names in a given column family or a (table, column family) combination. The following "dimensions" are supported:

An instance of this class does not store any metric values. It just allows to determine the correct metric name for each combination of the above dimensions.

Metric key Per-table metrics conf setting Description
On Off
tbl.T.cf.CF.M Include Skip A specific column family of a specific table
tbl.T.M Skip Skip All column families in the given table
cf.CF.M Skip Include A specific column family in all tables
M Include Include All column families in all tables


Nested Class Summary
static class SchemaMetrics.BlockMetricType
           
static interface SchemaMetrics.SchemaAware
           
static class SchemaMetrics.StoreMetricType
           
 
Field Summary
static SchemaMetrics ALL_SCHEMA_METRICS
          Metrics for all tables and column families.
static String BLOCK_TYPE_PREFIX
           
static String CF_BAD_FAMILY_PREFIX
           
static String CF_PREFIX
           
static String CF_UNKNOWN_PREFIX
           
static String METRIC_GETSIZE
           
static String METRIC_NEXTSIZE
           
static boolean NO_COMPACTION
          Use for readability when obtaining non-compaction counters
static String REGION_PREFIX
           
static String TABLE_PREFIX
           
static String TOTAL_KEY
          A special schema metric value that means "all tables aggregated" or "all column families aggregated" when used as a table name or a column family name.
static String UNKNOWN
          A string used when column family or table name is unknown, and in some unit tests.
 
Method Summary
 void accumulateStoreMetric(Map<String,org.apache.commons.lang.mutable.MutableDouble> tmpMap, SchemaMetrics.StoreMetricType storeMetricType, double val)
          Used to accumulate store metrics across multiple regions in a region server.
 void addToCacheSize(BlockType.BlockCategory category, long cacheSizeDelta)
          Adds the given delta to the cache size for the given block category and the aggregate metric for all block categories.
static void configureGlobally(org.apache.hadoop.conf.Configuration conf)
          Sets the flag whether to use table name in metric names according to the given configuration.
static Map<String,Long> diffMetrics(Map<String,Long> a, Map<String,Long> b)
           
 void flushMetrics()
          Notify the SchemaMetrics to flush all of the the metrics
static String formatMetrics(Map<String,Long> metrics)
          Formats the given map of metrics in a human-readable way.
static String generateSchemaMetricsPrefix(byte[] tableName, byte[] cfName)
           
static String generateSchemaMetricsPrefix(String tableName, Set<byte[]> families)
          Method to transform a set of column families in byte[] format with table name into a metric key prefix.
static String generateSchemaMetricsPrefix(String tableName, String cfName)
          Method to transform a combination of a table name and a column family name into a metric key prefix.
 String getBlockMetricName(BlockType.BlockCategory blockCategory, boolean isCompaction, SchemaMetrics.BlockMetricType metricType)
           
 String getBloomMetricName(boolean isInBloom)
           
static SchemaMetrics getInstance(String tableName, String cfName)
          Returns a SchemaMetrics object for the given table and column family, instantiating it if necessary.
static long getLong(Map<String,Long> m, String k)
           
static Map<String,Long> getMetricsSnapshot()
           
 String getStoreMetricName(SchemaMetrics.StoreMetricType storeMetricType)
           
 String getStoreMetricNameMax(SchemaMetrics.StoreMetricType storeMetricType)
           
static SchemaMetrics getUnknownInstanceForTest()
          Creates an instance pretending both the table and column family are unknown.
static void setUseTableNameInTest(boolean useTableNameNew)
          Set the flag to use or not use table name in metric names.
 void updateBloomMetrics(boolean isInBloom)
          Increments both the per-CF and the aggregate counter of bloom positives/negatives as specified by the argument.
 void updateOnCacheHit(BlockType.BlockCategory blockCategory, boolean isCompaction)
          Updates the number of hits and the total number of block reads on a block cache hit.
 void updateOnCacheHit(BlockType.BlockCategory blockCategory, boolean isCompaction, long count)
          Updates the number of hits and the total number of block reads on a block cache hit.
 void updateOnCacheMiss(BlockType.BlockCategory blockCategory, boolean isCompaction, long timeMs)
          Updates read time, the number of misses, and the total number of block reads on a block cache miss.
 void updateOnCachePutOrEvict(BlockType.BlockCategory blockCategory, long cacheSizeDelta, boolean isEviction)
           
 void updatePersistentStoreMetric(SchemaMetrics.StoreMetricType storeMetricType, long value)
          Update a metric that does not get reset on every poll.
static void validateMetricChanges(Map<String,Long> oldMetrics)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN

public static final String UNKNOWN
A string used when column family or table name is unknown, and in some unit tests. This should not normally show up in metric names but if it does it is better than creating a silent discrepancy in total vs. per-CF/table metrics.

See Also:
Constant Field Values

TABLE_PREFIX

public static final String TABLE_PREFIX
See Also:
Constant Field Values

CF_PREFIX

public static final String CF_PREFIX
See Also:
Constant Field Values

BLOCK_TYPE_PREFIX

public static final String BLOCK_TYPE_PREFIX
See Also:
Constant Field Values

REGION_PREFIX

public static final String REGION_PREFIX
See Also:
Constant Field Values

CF_UNKNOWN_PREFIX

public static final String CF_UNKNOWN_PREFIX
See Also:
Constant Field Values

CF_BAD_FAMILY_PREFIX

public static final String CF_BAD_FAMILY_PREFIX
See Also:
Constant Field Values

NO_COMPACTION

public static final boolean NO_COMPACTION
Use for readability when obtaining non-compaction counters

See Also:
Constant Field Values

METRIC_GETSIZE

public static final String METRIC_GETSIZE
See Also:
Constant Field Values

METRIC_NEXTSIZE

public static final String METRIC_NEXTSIZE
See Also:
Constant Field Values

TOTAL_KEY

public static final String TOTAL_KEY
A special schema metric value that means "all tables aggregated" or "all column families aggregated" when used as a table name or a column family name.

See Also:
Constant Field Values

ALL_SCHEMA_METRICS

public static final SchemaMetrics ALL_SCHEMA_METRICS
Metrics for all tables and column families.

Method Detail

getInstance

public static SchemaMetrics getInstance(String tableName,
                                        String cfName)
Returns a SchemaMetrics object for the given table and column family, instantiating it if necessary.

Parameters:
tableName - table name (null is interpreted as "unknown"). This is ignored
cfName - column family name (null is interpreted as "unknown")

getBlockMetricName

public String getBlockMetricName(BlockType.BlockCategory blockCategory,
                                 boolean isCompaction,
                                 SchemaMetrics.BlockMetricType metricType)

getBloomMetricName

public String getBloomMetricName(boolean isInBloom)

accumulateStoreMetric

public void accumulateStoreMetric(Map<String,org.apache.commons.lang.mutable.MutableDouble> tmpMap,
                                  SchemaMetrics.StoreMetricType storeMetricType,
                                  double val)
Used to accumulate store metrics across multiple regions in a region server. These metrics are not "persistent", i.e. we keep overriding them on every update instead of incrementing, so we need to accumulate them in a temporary map before pushing them to the global metric collection.

Parameters:
tmpMap - a temporary map for accumulating store metrics
storeMetricType - the store metric type to increment
val - the value to add to the metric

getStoreMetricName

public String getStoreMetricName(SchemaMetrics.StoreMetricType storeMetricType)

getStoreMetricNameMax

public String getStoreMetricNameMax(SchemaMetrics.StoreMetricType storeMetricType)

updatePersistentStoreMetric

public void updatePersistentStoreMetric(SchemaMetrics.StoreMetricType storeMetricType,
                                        long value)
Update a metric that does not get reset on every poll.

Parameters:
storeMetricType - the store metric to update
value - the value to update the metric to

updateOnCacheHit

public void updateOnCacheHit(BlockType.BlockCategory blockCategory,
                             boolean isCompaction)
Updates the number of hits and the total number of block reads on a block cache hit.


updateOnCacheHit

public void updateOnCacheHit(BlockType.BlockCategory blockCategory,
                             boolean isCompaction,
                             long count)
Updates the number of hits and the total number of block reads on a block cache hit.


flushMetrics

public void flushMetrics()
Notify the SchemaMetrics to flush all of the the metrics


updateOnCacheMiss

public void updateOnCacheMiss(BlockType.BlockCategory blockCategory,
                              boolean isCompaction,
                              long timeMs)
Updates read time, the number of misses, and the total number of block reads on a block cache miss.


addToCacheSize

public void addToCacheSize(BlockType.BlockCategory category,
                           long cacheSizeDelta)
Adds the given delta to the cache size for the given block category and the aggregate metric for all block categories. Updates both the per-CF counter and the counter for all CFs (four metrics total). The cache size metric is "persistent", i.e. it does not get reset when metrics are collected.


updateOnCachePutOrEvict

public void updateOnCachePutOrEvict(BlockType.BlockCategory blockCategory,
                                    long cacheSizeDelta,
                                    boolean isEviction)

updateBloomMetrics

public void updateBloomMetrics(boolean isInBloom)
Increments both the per-CF and the aggregate counter of bloom positives/negatives as specified by the argument.


configureGlobally

public static void configureGlobally(org.apache.hadoop.conf.Configuration conf)
Sets the flag whether to use table name in metric names according to the given configuration. This must be called at least once before instantiating HFile readers/writers.


generateSchemaMetricsPrefix

public static String generateSchemaMetricsPrefix(String tableName,
                                                 String cfName)
Method to transform a combination of a table name and a column family name into a metric key prefix. Tables/column family names equal to TOTAL_KEY are omitted from the prefix.

Parameters:
tableName - the table name or TOTAL_KEY for all tables
cfName - the column family name or TOTAL_KEY for all CFs
Returns:
the metric name prefix, ending with a dot.

generateSchemaMetricsPrefix

public static String generateSchemaMetricsPrefix(byte[] tableName,
                                                 byte[] cfName)

generateSchemaMetricsPrefix

public static String generateSchemaMetricsPrefix(String tableName,
                                                 Set<byte[]> families)
Method to transform a set of column families in byte[] format with table name into a metric key prefix.

Parameters:
tableName - the table name or TOTAL_KEY for all tables
families - the ordered set of column families
Returns:
the metric name prefix, ending with a dot, or an empty string in case of invalid arguments. This is OK since we always expect some CFs to be included.

getMetricsSnapshot

public static Map<String,Long> getMetricsSnapshot()

getLong

public static long getLong(Map<String,Long> m,
                           String k)

diffMetrics

public static Map<String,Long> diffMetrics(Map<String,Long> a,
                                           Map<String,Long> b)
Returns:
the difference between two sets of metrics (second minus first). Only includes keys that have nonzero difference.

validateMetricChanges

public static void validateMetricChanges(Map<String,Long> oldMetrics)

getUnknownInstanceForTest

public static SchemaMetrics getUnknownInstanceForTest()
Creates an instance pretending both the table and column family are unknown. Used in unit tests.


setUseTableNameInTest

public static void setUseTableNameInTest(boolean useTableNameNew)
Set the flag to use or not use table name in metric names. Used in unit tests, so the flag can be set arbitrarily.


formatMetrics

public static String formatMetrics(Map<String,Long> metrics)
Formats the given map of metrics in a human-readable way.



Copyright © 2015 The Apache Software Foundation. All Rights Reserved.