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
023import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
024
025/**
026 * Container class for commonly collected metrics for most operations. Instantiate this class to
027 * collect submitted count, failed count and time histogram for an operation.
028 */
029@InterfaceAudience.Private
030public class OperationMetrics {
031  private static final String SUBMITTED_COUNT = "SubmittedCount";
032  private static final String TIME = "Time";
033  private static final String FAILED_COUNT = "FailedCount";
034
035  final private Counter submittedCounter;
036  final private Histogram timeHisto;
037  final private Counter failedCounter;
038
039  public OperationMetrics(final MetricRegistry registry, final String metricNamePrefix) {
040    Preconditions.checkNotNull(registry);
041    Preconditions.checkNotNull(metricNamePrefix);
042
043    /**
044     * TODO: As of now, Metrics description cannot be added/ registered with
045     * {@link MetricRegistry}. As metric names are unambiguous but concise, descriptions of
046     * metrics need to be made available someplace for users.
047     */
048    submittedCounter = registry.counter(metricNamePrefix + SUBMITTED_COUNT);
049    timeHisto = registry.histogram(metricNamePrefix + TIME);
050    failedCounter = registry.counter(metricNamePrefix + FAILED_COUNT);
051  }
052
053  public Counter getSubmittedCounter() {
054    return submittedCounter;
055  }
056
057  public Histogram getTimeHisto() {
058    return timeHisto;
059  }
060
061  public Counter getFailedCounter() {
062    return failedCounter;
063  }
064}