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