<!DOCTYPE html>
{{/*
Copyright 2014 The Prometheus Authors
Licensed 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.
*/}}
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Prometheus Pushgateway</title>

    <script src="/static/jquery-2.1.4.js"></script>
    <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/bootstrap/css/bootstrap-theme.min.css">
    <script src="/static/bootstrap/js/bootstrap.min.js"></script>
    <script src="/static/functions.js"></script>

    <style type="text/css">
      .cursor-pointer {
        cursor: pointer;
      }
    </style>
  </head>
  <body>
  <nav class="navbar navbar-inverse" role="navigation">
    <div class="container-fluid">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
	<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
	</button>
	<a class="navbar-brand" href="#">Pushgateway</a>
      </div>
      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse" id="navbar-collapse-1">
	<ul class="nav navbar-nav">
          <li onclick="pushgateway.switchToMetrics()"
	      id="metrics-li" class="active">
	    <a href="#">Metrics</a>
	  </li>
          <li onclick="pushgateway.switchToStatus()"
	      id="status-li">
	    <a href="#">Status</a>
	  </li>
	</ul>
      </div>
    </div>
  </nav>
  <div class="container-fluid" id="metrics-div">
    {{$data := .}}
    <div class="panel-group" id="job-accordion">
      {{range .MetricGroups}}
      {{$gCount := $data.Count}}
      <div class="panel panel-default" id="group-panel-{{$gCount}}">
	<div class="panel-heading cursor-pointer" data-toggle="collapse" data-parent="#job-accordion" data-target="#j-{{$gCount}}">
	  <h4 class="panel-title">
	    <span class="caret"></span>
	    {{$metricGroup := .}}
	    {{range $i, $ln := .SortedLabels}}
	    <span class="label {{if eq $ln "job"}}label-warning{{else if eq $ln "instance"}}label-primary{{else}}label-info{{end}}">{{$ln}}="{{index $metricGroup.Labels $ln}}"</span>
	    {{end}}
	    <button class="btn btn-xs btn-danger pull-right" onclick="pushgateway.showDelModal({ {{range $i, $ln := .SortedLabels}}{{if $i}}, {{end}}'{{$ln}}': '{{index $metricGroup.Labels $ln}}'{{end}} }, 'group-panel-{{$gCount}}', event)">Delete Group</button>
	  </h4>
	</div>
	<div id="j-{{$gCount}}" class="panel-collapse collapse">
	  <div class="panel-body">
	    <div class="panel-group" id="metric-accordion-{{$gCount}}">
	      {{range $name, $tmf := .Metrics }}
	      {{$mCount := $data.Count}}
	      <div class="panel panel-default">
		<div class="panel-heading cursor-pointer" data-toggle="collapse" data-parent="#metric-accordion-{{$gCount}}" data-target="#m-{{$mCount}}">
		  <h4 class="panel-title">
		    <span class="caret"></span>
		    {{$name}}
		    <span class="badge">{{$tmf.MetricFamily.GetHelp}}</span>
		    <span class="label label-success">{{$tmf.MetricFamily.GetType}}</span>
		    last pushed: {{$tmf.Timestamp}}
		  </h4>
		</div>
		<div id="m-{{$mCount}}" class="panel-collapse collapse">
		  <div class="panel-body">
		    <table class="table table-striped table-bordered table-hover">
		      <thead>
			<tr>
			  <th>Labels</th>
			  <th>Value</th>
			  <th>Timestamp</th>
			</tr>
		      </thead>
		      <tbody>
			{{range $tmf.MetricFamily.Metric}}
			<tr>
			  <td>
			    {{range .Label}}
			    <span class="label {{if eq .GetName "job"}}label-warning{{else if eq .GetName "instance"}}label-primary{{else}}label-info{{end}}">{{.Name}}="{{.Value}}"</span>
			    {{end}}
			  </td>
			  <td>
			    {{with .Gauge}}
			    {{value .Value}}
			    {{else}}
			    {{with .Counter}}
			    {{value .Value}}
			    {{else}}
			    {{with .Untyped}}
			    {{value .Value}}
			    {{else}}
			    {{with .Summary}}
			    <table class="table table-striped table-bordered table-hover">
			      {{range .Quantile}}
			      <tr>
				<th scope="row">Quantile {{.Quantile}}</th>
				<td>{{value .Value}}</td>
			      </tr>
			      {{end}}
			      <tr>
				<th scope="row">Sample Count</th>
				<td>{{.SampleCount}}</td>
			      </tr>
			      <tr>
				<th scope="row">Sample Sum</th>
				<td>{{value .SampleSum}}</td>
			      </tr>
			    </table>
			    {{else}}
			    {{with .Histogram}}
			    <table class="table table-striped table-bordered table-hover">
			      {{range .Bucket}}
			      <tr>
				<th scope="row">Sample values &le; {{value .UpperBound}}</th>
				<td>{{.CumulativeCount}}</td>
			      </tr>
			      {{end}}
			      <tr>
				<th scope="row">Total sample Count</th>
				<td>{{.SampleCount}}</td>
			      </tr>
			      <tr>
				<th scope="row">Sample Sum</th>
				<td>{{value .SampleSum}}</td>
			      </tr>
			    </table>
			    {{end}}
    			    {{end}}
			    {{end}}
			    {{end}}
			    {{end}}
			  </td>
			  <td>
			    {{if .TimestampMs}}
			    {{$t := .TimestampMs | $data.FormatTimestamp}}{{$t}} {{/* Indirection via $t needed. Bug in template/html? */}}
			    {{end}}
			  </td>
			</tr>
			{{end}}
		      </tbody>
		    </table>
		  </div>
		</div>
	      </div>
	      {{end}}
	    </div>
	  </div>
	</div>
      </div>
      {{end}}
    </div>
  </div>
  <div class="container-fluid hidden" id="status-div">
    <h2>Runtime Information</h2>
    <table class="table table-condensed table-bordered table-striped table-hover">
      <tbody>
        <tr>
          <th>Started</th>
          <td>{{.Birth}}</td>
        </tr>
      </tbody>
    </table>

    <h2>Build Information</h2>
    <table class="table table-condensed table-bordered table-striped table-hover">
      <tbody>
        {{range $key, $value := .BuildInfo}}
        <tr>
          <th scope="row">{{$key}}</th>
          <td>{{$value}}</td>
        </tr>
        {{end}}
      </tbody>
    </table>

    <h2>Startup Flags</h2>
    <table class="table table-condensed table-bordered table-striped table-hover">
      <tbody>
        {{range $key, $value := .Flags}}
        <tr>
          <th scope="row">{{$key}}</th>
          <td>{{$value}}</td>
        </tr>
        {{end}}
      </tbody>
    </table>
  </div>
  <div class="container-fluid">
    <hr class="clear-top">
    <footer>
      <p>
        Code: <a href="https://github.com/prometheus/pushgateway">prometheus/pushgateway</a>
        Contact: <a href="mailto:prometheus-developers@googlegroups.com">prometheus-developers</a>
        © Prometheus Authors 2014
      </p>
    </footer>
  </div>

  <!-- del modal -->
  <div id="del-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="del-header" aria-hidden="true">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
	<div class="modal-header">
	  <button type="button" class="close" data-dismiss="modal">&times;</button>
	  <h3 id="del-header">Deletion Confirmation</h3>
	</div>
	<div class="modal-body">
	  <p id="del-modal-msg"><!-- To be filled dynamically. --></p>
	</div>
	<div class="modal-footer">
	  <button class="btn" data-dismiss="modal">Cancel</button>
	  <button class="btn btn-primary btn-danger" onclick="pushgateway.deleteGroup()">Delete</button>
	</div>
      </div>
    </div>
  </div>
  
</body>
</html>
