001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.regionserver; 019 020import org.apache.hadoop.hbase.CompatibilitySingletonFactory; 021import org.apache.hadoop.hbase.TableName; 022import org.apache.hadoop.hbase.metrics.MetricRegistries; 023import org.apache.yetus.audience.InterfaceAudience; 024 025/** 026 * Captures operation metrics by table. Separates metrics collection for table metrics away from 027 * {@link MetricsRegionServer} for encapsulation and ease of testing. 028 */ 029@InterfaceAudience.Private 030public class RegionServerTableMetrics { 031 032 private final MetricsTableLatencies latencies; 033 private MetricsTableQueryMeter queryMeter; 034 035 public RegionServerTableMetrics(boolean enableTableQueryMeter) { 036 latencies = CompatibilitySingletonFactory.getInstance(MetricsTableLatencies.class); 037 if (enableTableQueryMeter) { 038 queryMeter = new MetricsTableQueryMeterImpl(MetricRegistries.global() 039 .get(((MetricsTableLatenciesImpl) latencies).getMetricRegistryInfo()).get()); 040 } 041 } 042 043 public void updatePut(TableName table, long time) { 044 latencies.updatePut(table.getNameAsString(), time); 045 } 046 047 public void updatePutBatch(TableName table, long time) { 048 latencies.updatePutBatch(table.getNameAsString(), time); 049 } 050 051 public void updateGet(TableName table, long time) { 052 latencies.updateGet(table.getNameAsString(), time); 053 } 054 055 public void updateIncrement(TableName table, long time) { 056 latencies.updateIncrement(table.getNameAsString(), time); 057 } 058 059 public void updateAppend(TableName table, long time) { 060 latencies.updateAppend(table.getNameAsString(), time); 061 } 062 063 public void updateDelete(TableName table, long time) { 064 latencies.updateDelete(table.getNameAsString(), time); 065 } 066 067 public void updateDeleteBatch(TableName table, long time) { 068 latencies.updateDeleteBatch(table.getNameAsString(), time); 069 } 070 071 public void updateCheckAndDelete(TableName table, long time) { 072 latencies.updateCheckAndDelete(table.getNameAsString(), time); 073 } 074 075 public void updateCheckAndPut(TableName table, long time) { 076 latencies.updateCheckAndPut(table.getNameAsString(), time); 077 } 078 079 public void updateCheckAndMutate(TableName table, long time) { 080 latencies.updateCheckAndMutate(table.getNameAsString(), time); 081 } 082 083 public void updateScanTime(TableName table, long time) { 084 latencies.updateScanTime(table.getNameAsString(), time); 085 } 086 087 public void updateScanSize(TableName table, long size) { 088 latencies.updateScanSize(table.getNameAsString(), size); 089 } 090 091 public void updateTableReadQueryMeter(TableName table, long count) { 092 if (queryMeter != null) { 093 queryMeter.updateTableReadQueryMeter(table, count); 094 } 095 } 096 097 public void updateTableWriteQueryMeter(TableName table, long count) { 098 if (queryMeter != null) { 099 queryMeter.updateTableWriteQueryMeter(table, count); 100 } 101 } 102 103 public void updateTableWriteQueryMeter(TableName table) { 104 if (queryMeter != null) { 105 queryMeter.updateTableWriteQueryMeter(table); 106 } 107 } 108}