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 */ 018 019package org.apache.hadoop.hbase.metrics; 020 021import org.apache.yetus.audience.InterfaceAudience; 022 023/** 024 * BaseSource for dynamic metrics to announce to Metrics2. 025 * In hbase-hadoop{1|2}-compat there is an implementation of this interface. 026 */ 027@InterfaceAudience.Private 028public interface BaseSource { 029 030 String HBASE_METRICS_SYSTEM_NAME = "HBase"; 031 032 /** 033 * Clear out the metrics and re-prepare the source. 034 */ 035 void init(); 036 037 /** 038 * Set a gauge to a specific value. 039 * 040 * @param gaugeName the name of the gauge 041 * @param value the value 042 */ 043 void setGauge(String gaugeName, long value); 044 045 /** 046 * Add some amount to a gauge. 047 * 048 * @param gaugeName the name of the gauge 049 * @param delta the amount to change the gauge by. 050 */ 051 void incGauge(String gaugeName, long delta); 052 053 /** 054 * Subtract some amount from a gauge. 055 * 056 * @param gaugeName the name of the gauge 057 * @param delta the amount to change the gauge by. 058 */ 059 void decGauge(String gaugeName, long delta); 060 061 /** 062 * Remove a metric and no longer announce it. 063 * 064 * @param key Name of the gauge to remove. 065 */ 066 void removeMetric(String key); 067 068 /** 069 * Add some amount to a counter. 070 * 071 * @param counterName the name of the counter 072 * @param delta the amount to change the counter by. 073 */ 074 void incCounters(String counterName, long delta); 075 076 /** 077 * Add some value to a histogram. 078 * 079 * @param name the name of the histogram 080 * @param value the value to add to the histogram 081 */ 082 void updateHistogram(String name, long value); 083 084 085 /** 086 * Get the metrics context. For hadoop metrics2 system this is usually an all lowercased string. 087 * eg. regionserver, master, thriftserver 088 * 089 * @return The string context used to register this source to hadoop's metrics2 system. 090 */ 091 String getMetricsContext(); 092 093 /** 094 * Get the description of what this source exposes. 095 */ 096 String getMetricsDescription(); 097 098 /** 099 * Get the name of the context in JMX that this source will be exposed through. 100 * This is in ObjectName format. With the default context being Hadoop -> HBase 101 */ 102 String getMetricsJmxContext(); 103 104 /** 105 * Get the name of the metrics that are being exported by this source. 106 * Eg. IPC, GC, WAL 107 */ 108 String getMetricsName(); 109 110 default MetricRegistryInfo getMetricRegistryInfo() { 111 return new MetricRegistryInfo(getMetricsName(), getMetricsDescription(), 112 getMetricsContext(), getMetricsJmxContext(), true); 113 } 114 115}