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