VictoriaMetrics/lib/promscrape/targets_response.qtpl
2020-12-15 12:37:56 +02:00

96 lines
3.4 KiB
Text

{% import "github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
%}
{% collapsespace %}
{% func TargetsResponsePlain (jts []jobTargetsStatuses, showOriginLabels bool) -%}
{% for _, js := range jts %}
job={%q= js.job %} ({%d js.upCount %}/{%d js.targetsTotal %} up)
{% newline %}
{% for _, ts := range js.targetsStatus %}
{% code
labels := promLabelsString(ts.labels)
ol := promLabelsString(ts.originalLabels)
%}
{%s= "\t" %}state={% if ts.up %}up{% else %}down{% endif %},
endpoint={%s= ts.endpoint %},
labels={%s= labels %}
{% if showOriginLabels %}, originalLabels={%s= ol %}{% endif %},
last_scrape={%f.3 ts.lastScrapeTime.Seconds() %}s ago,
scrape_duration={%f.3 ts.scrapeDuration.Seconds() %}s,
error={%q= ts.error %}
{% newline %}
{% endfor %}
{% endfor %}
{% newline %}
{% endfunc %}
{% func TargetsResponseHTML(jts []jobTargetsStatuses, redirectPath string, onlyUnhealthy bool) %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<title>Scrape targets</title>
</head>
<body class="m-3">
<h1>Scrape targets</h1>
<div>
<button type="button" class="btn {% if !onlyUnhealthy %}btn-primary{% else %}btn-secondary{% endif %}"
{% if onlyUnhealthy %}onclick="location.href='{%s redirectPath %}'"{% endif %}>
All
</button>
<button type="button" class="btn {% if onlyUnhealthy %}btn-primary{% else %}btn-secondary{% endif %}"
{% if !onlyUnhealthy %}onclick="location.href='{%s= redirectPath %}?show_only_unhealthy=true'"{% endif %}>
Unhealthy
</button>
</div>
{% for _,js :=range jts %}
{% if onlyUnhealthy && js.upCount == js.targetsTotal %}{% continue %}{% endif %}
<div>
<h4>
<a>{%s js.job %} ({%d js.upCount %}/{%d js.targetsTotal %} up)</a>
</h4>
<table class="table table-striped table-hover table-bordered table-sm">
<thead>
<tr>
<th scope="col">Endpoint</th>
<th scope="col">State</th>
<th scope="col">Labels</th>
<th scope="col">Last Scrape</th>
<th scope="col">Scrape Duration</th>
<th scope="col">Error</th>
</tr>
</thead>
<tbody>
{% for _, ts := range js.targetsStatus %}
{% if onlyUnhealthy && ts.up %}{% continue %}{% endif %}
<tr {% if !ts.up %}class="alert alert-danger" role="alert"{% endif %}>
<td><a href="{%s ts.endpoint %}">{%s ts.endpoint %}</a><br></td>
<td>{% if ts.up %}UP{% else %}DOWN{% endif %}</td>
<td title="Original labels: {%= formatLabel(ts.originalLabels) %}">
{%= formatLabel(ts.labels) %}
</td>
<td>{%f.3 ts.lastScrapeTime.Seconds() %}s ago</td>
<td>{%f.3 ts.scrapeDuration.Seconds() %}s</td>
<td>{%s ts.error %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endfor %}
</body>
</html>
{% endfunc %}
{% func formatLabel(labels []prompbmarshal.Label) %}
{% for _, label := range labels %}
{%s label.Name %}={%q label.Value %} {% space %}
{% endfor %}
{% endfunc %}
{% endcollapsespace %}