MB-7130 Refactor btree stats

Move the code that computes the statistics into a
separate module and make it easier to add new metrics.
Also add 90%, 95% and 99% percentiles to all metrics.

Example:

$ curl -s http://localhost:9500/_set_view/default/_design/C/_btree_stats | json
{
  "id_btree": {
    "btree_size": 73351175,
    "file_size": 13003147447,
    "fragmentation": 99.43589676807885,
    "kv_chunk_threshold": 7168,
    "kp_chunk_threshold": 6144,
    "kv_count": 1986453,
    "kp_nodes": 2589,
    "kv_nodes": 48685,
    "max_depth": 5,
    "min_depth": 5,
    "avg_depth": 5,
    "depth_90_percentile": 5,
    "depth_95_percentile": 5,
    "depth_99_percentile": 5,
    "max_reduction_size": 133,
    "min_reduction_size": 133,
    "avg_reduction_size": 133,
    "reduction_size_90_percentile": 133,
    "reduction_size_95_percentile": 133,
    "reduction_size_99_percentile": 133,
    "max_elements_per_kp_node": 32,
    "min_elements_per_kp_node": 2,
    "avg_elements_per_kp_node": 19.80417149478563,
    "elements_per_kp_node_90_percentile": 31,
    "elements_per_kp_node_95_percentile": 32,
    "elements_per_kp_node_99_percentile": 32,
    "max_elements_per_kv_node": 68,
    "min_elements_per_kv_node": 32,
    "avg_elements_per_kv_node": 40.80215672178289,
    "elements_per_kv_node_90_percentile": 48,
    "elements_per_kv_node_95_percentile": 51,
    "elements_per_kv_node_99_percentile": 62,
    "max_kp_node_size": 5377,
    "min_kp_node_size": 337,
    "avg_kp_node_size": 3328.100811123986,
    "kp_node_size_90_percentile": 5209,
    "kp_node_size_95_percentile": 5377,
    "kp_node_size_99_percentile": 5377,
    "max_compressed_kp_node_size": 4039,
    "min_compressed_kp_node_size": 264,
    "avg_compressed_kp_node_size": 2116.863267670915,
    "compressed_kp_node_size_90_percentile": 3207,
    "compressed_kp_node_size_95_percentile": 3264,
    "compressed_kp_node_size_99_percentile": 3396,
    "max_kv_node_size": 6055,
    "min_kv_node_size": 2931,
    "avg_kv_node_size": 3789.253918044572,
    "kv_node_size_90_percentile": 4419,
    "kv_node_size_95_percentile": 4701,
    "kv_node_size_99_percentile": 5829,
    "max_compressed_kv_node_size": 2312,
    "min_compressed_kv_node_size": 1047,
    "avg_compressed_kv_node_size": 1385.282078668994,
    "compressed_kv_node_size_90_percentile": 1608,
    "compressed_kv_node_size_95_percentile": 1711,
    "compressed_kv_node_size_99_percentile": 2076,
    "max_key_size": 16,
    "min_key_size": 16,
    "avg_key_size": 16,
    "key_size_90_percentile": 16,
    "key_size_95_percentile": 16,
    "key_size_99_percentile": 16,
    "max_value_size": 73,
    "min_value_size": 53,
    "avg_value_size": 71.84445290172987,
    "value_size_90_percentile": 73,
    "value_size_95_percentile": 73,
    "value_size_99_percentile": 73
  },
  "experts2": {
    "btree_size": 41358068,
    "file_size": 13003147447,
    "fragmentation": 99.68193802178608,
    "kv_chunk_threshold": 7168,
    "kp_chunk_threshold": 6144,
    "kv_count": 1986453,
    "kp_nodes": 1576,
    "kv_nodes": 32524,
    "max_depth": 5,
    "min_depth": 5,
    "avg_depth": 5,
    "depth_90_percentile": 5,
    "depth_95_percentile": 5,
    "depth_99_percentile": 5,
    "max_reduction_size": 133,
    "min_reduction_size": 133,
    "avg_reduction_size": 133,
    "reduction_size_90_percentile": 133,
    "reduction_size_95_percentile": 133,
    "reduction_size_99_percentile": 133,
    "max_elements_per_kp_node": 31,
    "min_elements_per_kp_node": 4,
    "avg_elements_per_kp_node": 21.63642131979696,
    "elements_per_kp_node_90_percentile": 30,
    "elements_per_kp_node_95_percentile": 31,
    "elements_per_kp_node_99_percentile": 31,
    "max_elements_per_kv_node": 123,
    "min_elements_per_kv_node": 1,
    "avg_elements_per_kv_node": 61.07652810232444,
    "elements_per_kv_node_90_percentile": 100,
    "elements_per_kv_node_95_percentile": 104,
    "elements_per_kv_node_99_percentile": 111,
    "max_kp_node_size": 5581,
    "min_kp_node_size": 719,
    "avg_kp_node_size": 3889.072335025381,
    "kp_node_size_90_percentile": 5368,
    "kp_node_size_95_percentile": 5546,
    "kp_node_size_99_percentile": 5580,
    "max_compressed_kp_node_size": 4954,
    "min_compressed_kp_node_size": 225,
    "avg_compressed_kp_node_size": 2479.73540609137,
    "compressed_kp_node_size_90_percentile": 3377,
    "compressed_kp_node_size_95_percentile": 3576,
    "compressed_kp_node_size_99_percentile": 4395,
    "max_kv_node_size": 5088,
    "min_kv_node_size": 38,
    "avg_kv_node_size": 2548.569979092363,
    "kv_node_size_90_percentile": 4171,
    "kv_node_size_95_percentile": 4324,
    "kv_node_size_99_percentile": 4639,
    "max_compressed_kv_node_size": 2275,
    "min_compressed_kv_node_size": 40,
    "avg_compressed_kv_node_size": 1142.756887221744,
    "compressed_kv_node_size_90_percentile": 1851,
    "compressed_kv_node_size_95_percentile": 1922,
    "compressed_kv_node_size_99_percentile": 2057,
    "max_key_size": 28,
    "min_key_size": 23,
    "avg_key_size": 27.71111322543247,
    "key_size_90_percentile": 28,
    "key_size_95_percentile": 28,
    "key_size_99_percentile": 28,
    "max_value_size": 9,
    "min_value_size": 9,
    "avg_value_size": 9,
    "value_size_90_percentile": 9,
    "value_size_95_percentile": 9,
    "value_size_99_percentile": 9
  },
  "category": {
    "btree_size": 97917630,
    "file_size": 13003147447,
    "fragmentation": 99.24696977867008,
    "kv_chunk_threshold": 7168,
    "kp_chunk_threshold": 6144,
    "kv_count": 1986453,
    "kp_nodes": 2345,
    "kv_nodes": 46057,
    "max_depth": 5,
    "min_depth": 5,
    "avg_depth": 5,
    "depth_90_percentile": 5,
    "depth_95_percentile": 5,
    "depth_99_percentile": 5,
    "max_reduction_size": 133,
    "min_reduction_size": 133,
    "avg_reduction_size": 133,
    "reduction_size_90_percentile": 133,
    "reduction_size_95_percentile": 133,
    "reduction_size_99_percentile": 133,
    "max_elements_per_kp_node": 30,
    "min_elements_per_kp_node": 4,
    "avg_elements_per_kp_node": 20.64008528784648,
    "elements_per_kp_node_90_percentile": 30,
    "elements_per_kp_node_95_percentile": 30,
    "elements_per_kp_node_99_percentile": 30,
    "max_elements_per_kv_node": 69,
    "min_elements_per_kv_node": 34,
    "avg_elements_per_kv_node": 43.1303167813796,
    "elements_per_kv_node_90_percentile": 50,
    "elements_per_kv_node_95_percentile": 53,
    "elements_per_kv_node_99_percentile": 64,
    "max_kp_node_size": 5551,
    "min_kp_node_size": 740,
    "avg_kp_node_size": 3813.549680170576,
    "kp_node_size_90_percentile": 5541,
    "kp_node_size_95_percentile": 5546,
    "kp_node_size_99_percentile": 5549,
    "max_compressed_kp_node_size": 5063,
    "min_compressed_kp_node_size": 246,
    "avg_compressed_kp_node_size": 2451.555223880597,
    "compressed_kp_node_size_90_percentile": 3443,
    "compressed_kp_node_size_95_percentile": 3487,
    "compressed_kp_node_size_99_percentile": 4355,
    "max_kv_node_size": 5989,
    "min_kv_node_size": 2948,
    "avg_kv_node_size": 3784.008098660356,
    "kv_node_size_90_percentile": 4394,
    "kv_node_size_95_percentile": 4653,
    "kv_node_size_99_percentile": 5629,
    "max_compressed_kv_node_size": 3182,
    "min_compressed_kv_node_size": 1526,
    "avg_compressed_kv_node_size": 1992.260590138307,
    "compressed_kv_node_size_90_percentile": 2299,
    "compressed_kv_node_size_95_percentile": 2425,
    "compressed_kv_node_size_99_percentile": 2945,
    "max_key_size": 33,
    "min_key_size": 28,
    "avg_key_size": 32.71111322543247,
    "key_size_90_percentile": 33,
    "key_size_95_percentile": 33,
    "key_size_99_percentile": 33,
    "max_value_size": 50,
    "min_value_size": 50,
    "avg_value_size": 50,
    "value_size_90_percentile": 50,
    "value_size_95_percentile": 50,
    "value_size_99_percentile": 50
  },
  "realm3": {
    "btree_size": 95096840,
    "file_size": 13003147447,
    "fragmentation": 99.2686629111328,
    "kv_chunk_threshold": 7168,
    "kp_chunk_threshold": 6144,
    "kv_count": 1986453,
    "kp_nodes": 2401,
    "kv_nodes": 45082,
    "max_depth": 5,
    "min_depth": 5,
    "avg_depth": 5,
    "depth_90_percentile": 5,
    "depth_95_percentile": 5,
    "depth_99_percentile": 5,
    "max_reduction_size": 133,
    "min_reduction_size": 133,
    "avg_reduction_size": 133,
    "reduction_size_90_percentile": 133,
    "reduction_size_95_percentile": 133,
    "reduction_size_99_percentile": 133,
    "max_elements_per_kp_node": 30,
    "min_elements_per_kp_node": 4,
    "avg_elements_per_kp_node": 19.7759266972095,
    "elements_per_kp_node_90_percentile": 30,
    "elements_per_kp_node_95_percentile": 30,
    "elements_per_kp_node_99_percentile": 30,
    "max_elements_per_kv_node": 70,
    "min_elements_per_kv_node": 35,
    "avg_elements_per_kv_node": 44.06310722683111,
    "elements_per_kv_node_90_percentile": 51,
    "elements_per_kv_node_95_percentile": 54,
    "elements_per_kv_node_99_percentile": 65,
    "max_kp_node_size": 5491,
    "min_kp_node_size": 732,
    "avg_kp_node_size": 3614.363182007497,
    "kp_node_size_90_percentile": 5468,
    "kp_node_size_95_percentile": 5486,
    "kp_node_size_99_percentile": 5490,
    "max_compressed_kp_node_size": 4847,
    "min_compressed_kp_node_size": 239,
    "avg_compressed_kp_node_size": 2353.94543940025,
    "compressed_kp_node_size_90_percentile": 3425,
    "compressed_kp_node_size_95_percentile": 3476,
    "compressed_kp_node_size_99_percentile": 4476,
    "max_kv_node_size": 5951,
    "min_kv_node_size": 2963,
    "avg_kv_node_size": 3777.697972583293,
    "kv_node_size_90_percentile": 4380,
    "kv_node_size_95_percentile": 4634,
    "kv_node_size_99_percentile": 5578,
    "max_compressed_kv_node_size": 3169,
    "min_compressed_kv_node_size": 1513,
    "avg_compressed_kv_node_size": 1975.109467193115,
    "compressed_kv_node_size_90_percentile": 2280,
    "compressed_kv_node_size_95_percentile": 2401,
    "compressed_kv_node_size_99_percentile": 2882,
    "max_key_size": 31,
    "min_key_size": 26,
    "avg_key_size": 30.71111322543247,
    "key_size_90_percentile": 31,
    "key_size_95_percentile": 31,
    "key_size_99_percentile": 31,
    "max_value_size": 50,
    "min_value_size": 50,
    "avg_value_size": 50,
    "value_size_90_percentile": 50,
    "value_size_95_percentile": 50,
    "value_size_99_percentile": 50
  },
  "realm2": {
    "btree_size": 52542690,
    "file_size": 13003147447,
    "fragmentation": 99.59592329307839,
    "kv_chunk_threshold": 7168,
    "kp_chunk_threshold": 6144,
    "kv_count": 1986453,
    "kp_nodes": 1545,
    "kv_nodes": 30876,
    "max_depth": 5,
    "min_depth": 5,
    "avg_depth": 5,
    "depth_90_percentile": 5,
    "depth_95_percentile": 5,
    "depth_99_percentile": 5,
    "max_reduction_size": 133,
    "min_reduction_size": 133,
    "avg_reduction_size": 133,
    "reduction_size_90_percentile": 133,
    "reduction_size_95_percentile": 133,
    "reduction_size_99_percentile": 133,
    "max_elements_per_kp_node": 30,
    "min_elements_per_kp_node": 4,
    "avg_elements_per_kp_node": 20.98381877022654,
    "elements_per_kp_node_90_percentile": 26,
    "elements_per_kp_node_95_percentile": 28,
    "elements_per_kp_node_99_percentile": 30,
    "max_elements_per_kv_node": 118,
    "min_elements_per_kv_node": 1,
    "avg_elements_per_kv_node": 64.336474931986,
    "elements_per_kv_node_90_percentile": 94,
    "elements_per_kv_node_95_percentile": 98,
    "elements_per_kv_node_99_percentile": 105,
    "max_kp_node_size": 5489,
    "min_kp_node_size": 732,
    "avg_kp_node_size": 3834.906796116505,
    "kp_node_size_90_percentile": 4759,
    "kp_node_size_95_percentile": 5119,
    "kp_node_size_99_percentile": 5477,
    "max_compressed_kp_node_size": 5220,
    "min_compressed_kp_node_size": 241,
    "avg_compressed_kp_node_size": 2607.493851132686,
    "compressed_kp_node_size_90_percentile": 3218,
    "compressed_kp_node_size_95_percentile": 3375,
    "compressed_kp_node_size_99_percentile": 4833,
    "max_kv_node_size": 5169,
    "min_kv_node_size": 42,
    "avg_kv_node_size": 2877.555415209224,
    "kv_node_size_90_percentile": 4218,
    "kv_node_size_95_percentile": 4372,
    "kv_node_size_99_percentile": 4675,
    "max_compressed_kv_node_size": 2834,
    "min_compressed_kv_node_size": 44,
    "avg_compressed_kv_node_size": 1562.440082912294,
    "compressed_kv_node_size_90_percentile": 2275,
    "compressed_kv_node_size_95_percentile": 2363,
    "compressed_kv_node_size_99_percentile": 2525,
    "max_key_size": 31,
    "min_key_size": 26,
    "avg_key_size": 30.71111322543247,
    "key_size_90_percentile": 31,
    "key_size_95_percentile": 31,
    "key_size_99_percentile": 31,
    "max_value_size": 9,
    "min_value_size": 9,
    "avg_value_size": 9,
    "value_size_90_percentile": 9,
    "value_size_95_percentile": 9,
    "value_size_99_percentile": 9
  }
}

Change-Id: I353f68901475eb07a390e59793e7af0b191a50b7
Reviewed-on: http://review.couchbase.org/22368
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Reviewed-by: Farshid Ghods <farshid@couchbase.com>
Tested-by: Farshid Ghods <farshid@couchbase.com>