<!--
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Copyright (c) 2014 Mozilla Corporation

Contributors:
Jeff Bryner jbryner@mozilla.com
Anthony Verez averez@mozilla.com
-->

<template name="mozdefhealth">
    <div class="container">
        <div id="charts" class="row">
            <div class="fluid">
                <div id="ringChart-EPS" class="col-md-6 text-center"><h5 class="upperwhite" id="total-EPS">EPS: </h5></div>
                <div id="ringChart-LoadAverage" class="col-md-6 text-center" ><h5 class="upperwhite">Load Average</h5></div>
            </div>
        </div>
        <h6 class="upperwhite">
            {{#if currentUser}}
                {{currentUser.profile.email}}
            {{/if}}
        </h6>
        <h6 class="upperwhite lastupdate">Last update: </h6>
        <table class="table table-striped table-hover table-condensed">
        <thead>
            <tr>
                <td>ES Cluster Name</td>
                <td>Cluster Status</td>
                <td>Nodes</td>
                <td>Data Nodes</td>
                <td>Active Shards</td>
                <td>Active Primary Shards</td>
                <td>Relocating Shards</td>
                <td>Initializing Shards</td>
                <td >Unassigned Shards</td>
            </tr>
        </thead>
        <tbody>
            {{#each esclusterhealthitems}}	    
                {{>esclusterHealthTableItem}}
            {{/each}}
        </tbody>
        </table>

        <table class="table table-striped  table-hover table-condensed">
        <thead>
            <tr>
                <td>Frontend Node</td>
                <td>Load Average</td>
                <td>Queue</td>
                <td>Messages Ready</td>
                <td>Messages Unacknowledged</td>
                <td>EPS IN</td>
                <td>EPS to ElasticSearch</td>
            </tr>
        </thead>
        <tbody>
            {{#each frontendhealthitems}}
                {{>frontendHealthTableItem}}
            {{/each}}
        </tbody>
        </table>

        <table class="table table-striped  table-hover table-condensed">
        <thead>
            <tr>
                <td>ES Node</td>
                <td>CPU %</td>
                <td>Load Average</td>
                <td>JVM Memory %</td>
                <td>Disk Free (GB)</td>
                <td>Disk Total (GB)</td>
            </tr>
        </thead>
        <tbody>
            {{#each esnodeshealthitems}}
                {{>esnodesHealthTableItem}}
            {{/each}}
        </tbody>
        </table>

        Hot threads:<br>
        <code>
            {{#each eshotthreadshealthitems}}
                {{line}}<br>
            {{/each}}
        </code><br><br>
    </div>

</template>

<template name="esclusterHealthTableItem">
    <tr>
        <td>{{cluster_name}}</td>
        <td>{{status}}</td>
        <td>{{number_of_nodes}}</td>
        <td>{{number_of_data_nodes}}</td>
        <td>{{active_shards}}</td>
        <td>{{active_primary_shards}}</td>
        <td>{{relocating_shards}}</td>
        <td>{{initializing_shards}}</td>
        <td>{{unassigned_shards}}</td>		
    </tr>
</template>

<template name="esnodesHealthTableItem">
    <tr>
        <td>{{hostname}}</td>
        <td>{{cpu_usage}}</td>
        <td>{{load}}</td>
        <td>{{mem_heap_per}}</td>
        <td>{{disk_free}}</td>
        <td>{{disk_total}}</td>
    </tr>
</template>

<template name="frontendHealthTableItem">
    <tr>
        <td>{{hostname}}</td>
        <td>{{details.loadaverage}}</td>
        <td></td>
        <td>{{details.total_messages_ready}}</td>
        <td></td>
        <td>{{details.total_publish_eps}}</td>
        <td>{{details.total_deliver_eps}}</td>
    </tr>
    {{#each details.queues}}
        <tr>
            <td></td>
            <td></td>
            <td>{{queue}}</td>
            <td>{{messages_ready}}</td>
            <td>{{messages_unacknowledged}}</td>
            <td>{{publish_eps}}</td>
            <td>{{deliver_eps}}</td>
        </tr>
    {{/each}}
</template>

