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