HBASE-21843 RegionGroupingProvider breaks the meta wal file name pattern which may...
[hbase.git] / hbase-server / src / main / java / org / apache / hadoop / hbase / util / YammerHistogramUtils.java
blob3070fb37277db33668207f6c972e680d3f92f533
1 /**
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org.apache.hadoop.hbase.util;
21 import com.codahale.metrics.Histogram;
22 import com.codahale.metrics.Reservoir;
23 import com.codahale.metrics.Snapshot;
24 import java.lang.reflect.Constructor;
25 import java.text.DecimalFormat;
26 import org.apache.yetus.audience.InterfaceAudience;
28 /** Utility functions for working with Yammer Metrics. */
29 @InterfaceAudience.Private
30 public final class YammerHistogramUtils {
32 // not for public consumption
33 private YammerHistogramUtils() {}
35 /**
36 * Used formatting doubles so only two places after decimal point.
38 private static DecimalFormat DOUBLE_FORMAT = new DecimalFormat("#0.00");
40 /**
41 * Create a new {@link com.codahale.metrics.Histogram} instance. These constructors are
42 * not public in 2.2.0, so we use reflection to find them.
44 public static Histogram newHistogram(Reservoir sample) {
45 try {
46 Constructor<?> ctor =
47 Histogram.class.getDeclaredConstructor(Reservoir.class);
48 ctor.setAccessible(true);
49 return (Histogram) ctor.newInstance(sample);
50 } catch (Exception e) {
51 throw new RuntimeException(e);
55 /** @return an abbreviated summary of {@code hist}. */
56 public static String getShortHistogramReport(final Histogram hist) {
57 Snapshot sn = hist.getSnapshot();
58 return "mean=" + DOUBLE_FORMAT.format(sn.getMean()) +
59 ", min=" + DOUBLE_FORMAT.format(sn.getMin()) +
60 ", max=" + DOUBLE_FORMAT.format(sn.getMax()) +
61 ", stdDev=" + DOUBLE_FORMAT.format(sn.getStdDev()) +
62 ", 95th=" + DOUBLE_FORMAT.format(sn.get95thPercentile()) +
63 ", 99th=" + DOUBLE_FORMAT.format(sn.get99thPercentile());
66 /** @return a summary of {@code hist}. */
67 public static String getHistogramReport(final Histogram hist) {
68 Snapshot sn = hist.getSnapshot();
69 return "mean=" + DOUBLE_FORMAT.format(sn.getMean()) +
70 ", min=" + DOUBLE_FORMAT.format(sn.getMin()) +
71 ", max=" + DOUBLE_FORMAT.format(sn.getMax()) +
72 ", stdDev=" + DOUBLE_FORMAT.format(sn.getStdDev()) +
73 ", 50th=" + DOUBLE_FORMAT.format(sn.getMedian()) +
74 ", 75th=" + DOUBLE_FORMAT.format(sn.get75thPercentile()) +
75 ", 95th=" + DOUBLE_FORMAT.format(sn.get95thPercentile()) +
76 ", 99th=" + DOUBLE_FORMAT.format(sn.get99thPercentile()) +
77 ", 99.9th=" + DOUBLE_FORMAT.format(sn.get999thPercentile()) +
78 ", 99.99th=" + DOUBLE_FORMAT.format(sn.getValue(0.9999)) +
79 ", 99.999th=" + DOUBLE_FORMAT.format(sn.getValue(0.99999));
82 /** @return pretty summary of {@code hist}. */
83 public static String getPrettyHistogramReport(final Histogram h) {
84 Snapshot sn = h.getSnapshot();
85 return
86 "Mean = " + DOUBLE_FORMAT.format(sn.getMean()) + "\n" +
87 "Min = " + DOUBLE_FORMAT.format(sn.getMin()) + "\n" +
88 "Max = " + DOUBLE_FORMAT.format(sn.getMax()) + "\n" +
89 "StdDev = " + DOUBLE_FORMAT.format(sn.getStdDev()) + "\n" +
90 "50th = " + DOUBLE_FORMAT.format(sn.getMedian()) + "\n" +
91 "75th = " + DOUBLE_FORMAT.format(sn.get75thPercentile()) + "\n" +
92 "95th = " + DOUBLE_FORMAT.format(sn.get95thPercentile()) + "\n" +
93 "99th = " + DOUBLE_FORMAT.format(sn.get99thPercentile()) + "\n" +
94 "99.9th = " + DOUBLE_FORMAT.format(sn.get999thPercentile()) + "\n" +
95 "99.99th = " + DOUBLE_FORMAT.format(sn.getValue(0.9999)) + "\n" +
96 "99.999th = " + DOUBLE_FORMAT.format(sn.getValue(0.99999));