<%doc>

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</%doc>
<%args>
MetricsRegionServerWrapper mWrap;
</%args>
<%import>
java.util.*;
org.apache.hadoop.hbase.regionserver.HRegionServer;
org.apache.hadoop.hbase.regionserver.MetricsRegionServerWrapper;
org.apache.hadoop.hbase.util.Bytes;
org.apache.hadoop.hbase.HRegionInfo;
org.apache.hadoop.hbase.ServerName;
org.apache.hadoop.hbase.HBaseConfiguration;
org.apache.hadoop.hbase.protobuf.ProtobufUtil;
org.apache.hadoop.hbase.protobuf.generated.AdminProtos.ServerInfo;
org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.RegionLoad;
org.apache.hadoop.hbase.metrics.histogram.MetricsHistogram;
org.apache.hadoop.hbase.util.DirectMemoryUtils;
org.apache.hadoop.util.StringUtils;
com.yammer.metrics.stats.Snapshot;
java.lang.management.ManagementFactory;
</%import>
<div class="tabbable">
    <ul class="nav nav-pills">
        <li class="active"><a href="#tab_baseStats" data-toggle="tab">Base Stats</a></li>
        <li class=""><a href="#tab_memoryStats" data-toggle="tab">Memory</a></li>
        <li class=""><a href="#tab_requestStats" data-toggle="tab">Requests</a></li>
        <li class=""><a href="#tab_hlogStats" data-toggle="tab">hlogs</a></li>
        <li class=""><a href="#tab_storeStats" data-toggle="tab">Storefiles</a></li>
        <li class=""><a href="#tab_queueStats" data-toggle="tab">Queues</a></li>
        <li class=""><a href="#tab_blockCacheStats" data-toggle="tab">Block Cache</a></li>
    </ul>
    <div class="tab-content" style="padding-bottom: 9px; border-bottom: 1px solid #ddd;">
        <div class="tab-pane active" id="tab_baseStats">
            <& baseStats; mWrap = mWrap &>
        </div>
        <div class="tab-pane" id="tab_memoryStats">
            <& memoryStats; mWrap = mWrap &>
        </div>
        <div class="tab-pane" id="tab_requestStats">
            <& requestStats; mWrap = mWrap &>
        </div>
        <div class="tab-pane" id="tab_hlogStats">
            <& hlogStats; mWrap = mWrap &>
        </div>
        <div class="tab-pane" id="tab_storeStats">
            <& storeStats; mWrap = mWrap &>
        </div>
        <div class="tab-pane" id="tab_queueStats">
            <& queueStats; mWrap = mWrap  &>
        </div>
        <div class="tab-pane" id="tab_blockCacheStats">
            <& blockCacheStats; mWrap = mWrap &>
        </div>
    </div>
</div>

<%def baseStats>
<%args>
    MetricsRegionServerWrapper mWrap;
</%args>
<table class="table table-striped">
    <tr>

        <th>Requests Per Second</th>
        <th>Num. Regions</th>
        <th>Block locality</th>
        <th>Slow HLog Append Count</th>
    </tr>
    <tr>
        <td><% String.format("%.0f", mWrap.getRequestsPerSecond()) %></td>
        <td><% mWrap.getNumOnlineRegions() %></td>
        <td><% mWrap.getPercentFileLocal() %></td>
        <td><% 0 %></td>
    </tr>
</table>
</%def>

<%def memoryStats>
<%args>
MetricsRegionServerWrapper mWrap;
</%args>
<table class="table table-striped">
<tr>
    <tr>
        <th>Used Heap</th>
        <th>Max Heap</th>
        <th>Direct Memory Used</th>
        <th>Direct Memory Configured</th>
        <th>Memstore Size</th>
    </tr>
</tr>
<tr>
    <td>
        <% StringUtils.humanReadableInt(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed()) %>
    </td>
    <td>
        <% StringUtils.humanReadableInt(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()) %>
    </td>
    <td>
        <% StringUtils.humanReadableInt(DirectMemoryUtils.getDirectMemoryUsage()) %>
    </td>
    <td>
        <% StringUtils.humanReadableInt(DirectMemoryUtils.getDirectMemorySize()) %>
    </td>
    <td><% StringUtils.humanReadableInt(mWrap.getMemstoreSize()) %></td>
</tr>
</table>
</%def>

<%def hlogStats>
<%args>
MetricsRegionServerWrapper mWrap;
</%args>
<table class="table table-striped">
<tr>
    <tr>
        <th>Num. HLog Files</th>
        <th>Size. HLog Files (bytes)</th>
    </tr>
</tr>
<tr>
    <td><% mWrap.getNumHLogFiles() %></td>
    <td><% mWrap.getHLogFileSize() %></td>
</tr>
</table>
</%def>

<%def storeStats>
<%args>
MetricsRegionServerWrapper mWrap;
</%args>
<table class="table table-striped">
<tr>

    <th>Num. Stores</th>
    <th>Num. Storefiles</th>
    <th>Root Index Size (bytes)</th>
    <th>Index Size (bytes)</th>
    <th>Bloom Size (bytes)</th>
</tr>
<tr>
    <td><% StringUtils.humanReadableInt(mWrap.getNumStores()) %></td>
    <td><% StringUtils.humanReadableInt(mWrap.getNumStoreFiles()) %></td>
    <td><% StringUtils.humanReadableInt(mWrap.getStoreFileIndexSize()) %></td>
    <td><% StringUtils.humanReadableInt(mWrap.getTotalStaticIndexSize()) %></td>
    <td><% StringUtils.humanReadableInt(mWrap.getTotalStaticBloomSize()) %></td>
</tr>
</table>
</%def>


<%def requestStats>
<%args>
MetricsRegionServerWrapper mWrap;
</%args>
<table class="table table-striped">
<tr>
    <th>Request Per Second</th>
    <th>Read Request Count</th>
    <th>Write Request Count</th>
</tr>
<tr>
    <td><% String.format("%.0f", mWrap.getRequestsPerSecond()) %></td>
    <td><% mWrap.getReadRequestsCount() %></td>
    <td><% mWrap.getWriteRequestsCount() %></td>
</tr>
</table>
</%def>

<%def queueStats>
<%args>
MetricsRegionServerWrapper mWrap;
</%args>
<table class="table table-striped">
<tr>
    <th>Compaction Queue Size</th>
    <th>Flush Queue Size</th>

</tr>
<tr>
    <td><% mWrap.getCompactionQueueSize() %></td>
    <td><% mWrap.getFlushQueueSize() %></td>
</tr>
</table>
</%def>


<%def blockCacheStats>
<%args>
MetricsRegionServerWrapper mWrap;
</%args>
<table class="table table-striped">
<tr>
    <th>Cache Size (bytes)</th>
    <th>Cache Free (bytes)</th>
    <th>Cache Count (blocks)</th>
    <th>Cache Hit Count</th>
    <th>Cache Miss Count</th>
    <th>Cache Hit Ratio</th>
    <th>Cache Eviction Count</th>

</tr>
<tr>
    <td><% StringUtils.humanReadableInt(mWrap.getBlockCacheSize()) %></td>
    <td><% StringUtils.humanReadableInt(mWrap.getBlockCacheFreeSize()) %></td>
    <td><% StringUtils.humanReadableInt(mWrap.getBlockCacheCount()) %></td>
    <td><% StringUtils.humanReadableInt(mWrap.getBlockCacheHitCount()) %></td>
    <td><% StringUtils.humanReadableInt(mWrap.getBlockCacheMissCount()) %></td>
    <td><% mWrap.getBlockCacheHitPercent() %>%</td>
    <td><% StringUtils.humanReadableInt(mWrap.getBlockCacheEvictedCount()) %></td>
</tr>
</table>
</%def>
