<h1>Overview</h1>
<% if (user_monitor) { %>
<%= format('partition', {'nodes': nodes}) %>
<% } %>
<div class="section">
<h2>Totals</h2>
<div class="hider">
<% if (overview.statistics_db_node != 'not_running') { %>
  <%= queue_lengths('lengths-over', overview.queue_totals) %>
<% if (statistics_level == 'fine') { %>
  <%= message_rates('msg-rates-over', overview.message_stats) %>
<% } %>
<% } else { %>
    Totals not available
<% } %>

<div class="updatable">
  <h3>Global counts <span class="help" id="resource-counts"></span></h3>

  <div class="box">
    <div class="micro-highlight">
      <a href="#/connections">
        Connections: <strong><%= overview.object_totals.connections %></strong>
      </a>
    </div>
    <div class="micro-highlight">
      <a href="#/channels">
        Channels: <strong><%= overview.object_totals.channels %></strong>
      </a>
    </div>
    <div class="micro-highlight">
      <a href="#/exchanges">
        Exchanges: <strong><%= overview.object_totals.exchanges %></strong>
      </a>
    </div>
    <div class="micro-highlight">
      <a href="#/queues">
        Queues: <strong><%= overview.object_totals.queues %></strong>
      </a>
    </div>
<% if (overview.object_totals['consumers'] != undefined) { %>    <tr>
    <div class="micro-highlight">
      Consumers: <strong><%= overview.object_totals.consumers %></strong>
    </div>
<% } %>
  </div>
 </div>

</div>
</div>

<% if (user_monitor) { %>
<div class="section">
<h2>Nodes</h2>
<div class="hider updatable">
<table class="list">
  <tr>
    <th>Name</th>
    <th>
      File descriptors <span class="help" id="file-descriptors"></span>
    </th>
    <th>
      Socket descriptors <span class="help" id="socket-descriptors"></span>
    </th>
    <th>
      Erlang processes
    </th>
    <th>
      Memory
    </th>
    <th>
      Disk space
    </th>
    <th>Uptime</th>
    <th>Type</th>
  </tr>
<%
   for (var i = 0; i < nodes.length; i++) {
     var node = nodes[i];
%>
   <tr<%= alt_rows(i)%>>
     <td>
       <%= link_node(node.name) %>
       <% if (rabbit_versions_interesting) { %>
         <sub>RabbitMQ <%= fmt_rabbit_version(node.applications) %></sub>
       <% } %>
     </td>
<% if (!node.running) { %>
     <td colspan="6">
       <div class="status-red">
         Node not running
       </div>
     </td>
<% } else if (node.os_pid == undefined) { %>
     <td colspan="6">
       <div class="status-yellow">
         <acronym title="The rabbitmq_management_agent plugin should be enabled on this node. If it is not, various statistics will be inaccurate.">
           Node statistics not available</acronym>
       </div>
     </td>
<% } else { %>
     <td>
<%= fmt_resource_bar_count(fmt_fd_used(node.fd_used, node.fd_total), node.fd_total, FD_THRESHOLDS) %>
     </td>
     <td>
<%= fmt_resource_bar_count(node.sockets_used, node.sockets_total, FD_THRESHOLDS) %>
     </td>
     <td>
<%= fmt_resource_bar_count(node.proc_used, node.proc_total, PROCESS_THRESHOLDS) %>
     </td>
     <td>
<% if (node.mem_limit != 'memory_monitoring_disabled') { %>
   <%= fmt_resource_bar(fmt_bytes(node.mem_used),
                        fmt_bytes(node.mem_limit) + ' high watermark',
                        node.mem_used / node.mem_limit,
                        node.mem_alarm ? 'red' : 'green',
                        node.mem_alarm ? 'memory-alarm' : null) %>
<% } else { %>
       <%= fmt_bytes(node.mem_used) %>
<% } %>
     </td>
     <td>
<% if (node.disk_free_limit != 'disk_free_monitoring_disabled') { %>
   <%= fmt_resource_bar(fmt_bytes(node.disk_free),
                        fmt_bytes(node.disk_free_limit) + ' low watermark',
                        node.disk_free_limit / node.disk_free,
                        node.disk_free_alarm ? 'red' : 'green',
                        node.disk_free_alarm ? 'disk-free-alarm' : null) %>
<% } else { %>
         (not available)
<% } %>
     </td>
     <td class="r">
       <%= fmt_uptime(node.uptime) %>
     </td>
<% } %>
     <td class="c">
       <% if (node.type == 'disc') { %>
         <acronym title="Broker definitions are held on disc.">Disc</acronym>
       <% } else { %>
         <acronym title="Broker definitions are held in RAM. Messages will still be written to disc if necessary.">RAM</acronym>
       <% } %>
       <% if (overview.statistics_db_node == node.name) { %>
         <acronym title="This node contains the management statistics database">Stats</acronym>
       <% } %>
       <% if (overview.node == node.name) { %>
         <acronym title="You are accessing the management UI from this node.">*</acronym>
       <% } %>
     </td>
   </tr>
<% } %>
</table>

<% if (overview.statistics_db_node == 'not_running') { %>
  <p class="status-error">Statistics database could not be contacted. Message rates and queue lengths will not be shown.</p>
<% } %>
</div>
</div>

<div class="section">
<h2>Ports and contexts</h2>
<div class="hider updatable">
<h3>Listening ports</h3>
<table class="list">
  <tr>
    <th>Protocol</th>
<% if (nodes_interesting) { %>
    <th>Node</th>
<% } %>
    <th>Bound to</th>
    <th>Port</th>
  </tr>
  <%
      for (var i = 0; i < overview.listeners.length; i++) {
          var listener = overview.listeners[i];
  %>
  <tr<%= alt_rows(i)%>>
    <td><%= listener.protocol %></td>
<% if (nodes_interesting) { %>
    <td><%= fmt_node(listener.node) %></td>
<% } %>
    <td><%= listener.ip_address %></td>
    <td><%= listener.port %></td>
  </tr>
  <% } %>
</table>
<h3>Web contexts</h3>
<table class="list">
  <tr>
    <th>Context</th>
<% if (nodes_interesting) { %>
    <th>Node</th>
<% } %>
    <th>Bound to</th>
    <th>Port</th>
    <th>SSL</th>
    <th>Path</th>
  </tr>
  <%
    for (var i = 0; i < overview.contexts.length; i++) {
        var context = overview.contexts[i];
  %>
    <tr<%= alt_rows(i)%>>
      <td><%= context.description %></td>
<% if (nodes_interesting) { %>
      <td><%= fmt_node(context.node) %></td>
<% } %>
      <td><%= (context.ip != undefined) ? context.ip : "0.0.0.0" %></td>
      <td><%= context.port %></td>
      <td class="c"><%= fmt_boolean(context.ssl || false) %></td>
      <td><%= context.path %></td>
    </tr>
  <% } %>
</table>
</div>
</div>

<div class="section-hidden administrator-only">
<h2>Import / export definitions</h2>
<div class="hider">
  <form action="api/definitions" method="post" enctype="multipart/form-data">
    <table class="two-col-layout">
      <tr>
        <td>
          <h3>Export</h3>
          <p>
            <label for="download-filename">Filename for download:</label><br/>
            <input type="text" id="download-filename" value="<%= fmt_download_filename(overview.node) %>" class="wide" />
          </p>
        </td>
        <td>
          <h3>Import</h3>
          <p>
            <label>Definitions file:</label><br/>
            <input type="file" name="file"/>
          </p>
        </td>
      </tr>
      <tr>
        <td>
          <p>
            <button id="download-definitions">Download broker definitions</button>
            <span class="help" id="export-definitions"></span>
          </p>
        </td>
        <td>
          <p>
            <input type="hidden" name="redirect" value="../#/import-succeeded"/>
            <input type="submit" value="Upload broker definitions"/>
            <span class="help" id="import-definitions"></span>
          </p>
        </td>
      </tr>
    </table>
  </form>
</div>
</div>

<% if (overview.statistics_level != 'fine') { %>
<div class="section-hidden">
<h2>Message Rates Disabled</h2>
<div class="hider">
<p>
  The statistics level in this RabbitMQ server is currently set to
  <code><%= overview.statistics_level %></code>. Message rates are therefore
  disabled.
</p>
<p>
  To re-enable message rates, edit your configuration file and either
  set <code>collect_statistics</code> to <code>fine</code> in
  the <code>rabbit</code> application, or
  set <code>force_fine_statistics</code> to <code>true</code> in
  the <code>rabbitmq_management_agent</code> application
</p>
</div>
</div>
<% } %>
<% } %>
