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.rest;
020
021import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
022import org.apache.hadoop.metrics2.MetricHistogram;
023import org.apache.hadoop.metrics2.lib.MutableFastCounter;
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * Hadoop Two implementation of a metrics2 source that will export metrics from the Rest server to
028 * the hadoop metrics2 subsystem.
029 *
030 * Implements BaseSource through BaseSourceImpl, following the pattern
031 */
032@InterfaceAudience.Private
033public class MetricsRESTSourceImpl extends BaseSourceImpl implements MetricsRESTSource {
034  private MutableFastCounter request;
035  private MutableFastCounter sucGet;
036  private MutableFastCounter sucPut;
037  private MutableFastCounter sucDel;
038  private MutableFastCounter sucScan;
039  private MutableFastCounter sucAppend;
040  private MutableFastCounter sucIncrement;
041  private MutableFastCounter fGet;
042  private MutableFastCounter fPut;
043  private MutableFastCounter fDel;
044  private MutableFastCounter fScan;
045  private MutableFastCounter fAppend;
046  private MutableFastCounter fIncrement;
047
048  // pause monitor metrics
049  private final MutableFastCounter infoPauseThresholdExceeded;
050  private final MutableFastCounter warnPauseThresholdExceeded;
051  private final MetricHistogram pausesWithGc;
052  private final MetricHistogram pausesWithoutGc;
053
054  public MetricsRESTSourceImpl() {
055    this(METRICS_NAME, METRICS_DESCRIPTION, CONTEXT, JMX_CONTEXT);
056  }
057
058  public MetricsRESTSourceImpl(String metricsName,
059                               String metricsDescription,
060                               String metricsContext,
061                               String metricsJmxContext) {
062    super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
063
064    // pause monitor metrics
065    infoPauseThresholdExceeded = getMetricsRegistry().newCounter(INFO_THRESHOLD_COUNT_KEY,
066      INFO_THRESHOLD_COUNT_DESC, 0L);
067    warnPauseThresholdExceeded = getMetricsRegistry().newCounter(WARN_THRESHOLD_COUNT_KEY,
068      WARN_THRESHOLD_COUNT_DESC, 0L);
069    pausesWithGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITH_GC_KEY);
070    pausesWithoutGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITHOUT_GC_KEY);
071  }
072
073  @Override
074  public void init() {
075    super.init();
076    request = getMetricsRegistry().getCounter(REQUEST_KEY, 0L);
077
078    sucGet = getMetricsRegistry().getCounter(SUCCESSFUL_GET_KEY, 0L);
079    sucPut = getMetricsRegistry().getCounter(SUCCESSFUL_PUT_KEY, 0L);
080    sucDel = getMetricsRegistry().getCounter(SUCCESSFUL_DELETE_KEY, 0L);
081    sucScan = getMetricsRegistry().getCounter(SUCCESSFUL_SCAN_KEY, 0L);
082    sucAppend = getMetricsRegistry().getCounter(SUCCESSFUL_APPEND_KEY, 0L);
083    sucIncrement = getMetricsRegistry().getCounter(SUCCESSFUL_INCREMENT_KEY, 0L);
084
085    fGet = getMetricsRegistry().getCounter(FAILED_GET_KEY, 0L);
086    fPut = getMetricsRegistry().getCounter(FAILED_PUT_KEY, 0L);
087    fDel = getMetricsRegistry().getCounter(FAILED_DELETE_KEY, 0L);
088    fScan = getMetricsRegistry().getCounter(FAILED_SCAN_KEY, 0L);
089    fAppend = getMetricsRegistry().getCounter(FAILED_APPEND_KEY, 0L);
090    fIncrement = getMetricsRegistry().getCounter(FAILED_INCREMENT_KEY, 0L);
091  }
092
093  @Override
094  public void incrementRequests(int inc) {
095    request.incr(inc);
096  }
097
098  @Override
099  public void incrementSucessfulGetRequests(int inc) {
100    sucGet.incr(inc);
101  }
102
103  @Override
104  public void incrementSucessfulPutRequests(int inc) {
105    sucPut.incr(inc);
106  }
107
108  @Override
109  public void incrementSucessfulDeleteRequests(int inc) {
110    sucDel.incr(inc);
111  }
112
113  @Override
114  public void incrementFailedGetRequests(int inc) {
115    fGet.incr(inc);
116  }
117
118  @Override
119  public void incrementFailedPutRequests(int inc) {
120    fPut.incr(inc);
121  }
122
123  @Override
124  public void incrementFailedDeleteRequests(int inc) {
125    fDel.incr(inc);
126  }
127
128  @Override
129  public void incrementSucessfulScanRequests(int inc) {
130    sucScan.incr(inc);
131  }
132
133  @Override
134  public void incrementFailedScanRequests(int inc) {
135    fScan.incr(inc);
136  }
137
138  @Override
139  public void incrementSucessfulAppendRequests(int inc) {
140    sucAppend.incr(inc);
141  }
142
143  @Override
144  public void incrementFailedAppendRequests(int inc) {
145    fAppend.incr(inc);
146  }
147
148  @Override
149  public void incrementSucessfulIncrementRequests(int inc) {
150    sucIncrement.incr(inc);
151  }
152
153  @Override
154  public void incrementFailedIncrementRequests(int inc) {
155    fIncrement.incr(inc);
156  }
157
158  @Override
159  public void incInfoThresholdExceeded(int count) {
160    infoPauseThresholdExceeded.incr(count);
161  }
162
163  @Override
164  public void incWarnThresholdExceeded(int count) {
165    warnPauseThresholdExceeded.incr(count);
166  }
167
168  @Override
169  public void updatePauseTimeWithGc(long t) {
170    pausesWithGc.add(t);
171  }
172
173  @Override
174  public void updatePauseTimeWithoutGc(long t) {
175    pausesWithoutGc.add(t);
176  }
177}