2020-12-14 12:36:48 +01:00
{% import "github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
%}
2021-06-18 09:53:10 +02:00
{% stripspace %}
2020-12-14 12:36:48 +01:00
2021-06-18 09:53:10 +02:00
{% func TargetsResponsePlain(jts []jobTargetsStatuses, emptyJobs []string, showOriginLabels bool) %}
2020-12-14 12:36:48 +01:00
{% for _, js := range jts %}
2021-07-26 11:22:48 +02:00
job={%q= js.job %} ({%d js.upCount %}/{%d js.targetsTotal %}{% space %}up)
2020-12-14 12:36:48 +01:00
{% newline %}
{% for _, ts := range js.targetsStatus %}
{% code
labels := promLabelsString(ts.labels)
ol := promLabelsString(ts.originalLabels)
%}
2021-06-18 09:53:10 +02:00
{%s= "\t" %}state={% if ts.up %}up{% else %}down{% endif %},{% space %}
2021-06-28 20:23:29 +02:00
endpoint={%s= ts.endpoint %},{% space %}
2020-12-15 11:37:19 +01:00
labels={%s= labels %}
2021-06-18 09:53:10 +02:00
{% if showOriginLabels %}, originalLabels={%s= ol %}{% endif %},{% space %}
last_scrape={%f.3 ts.lastScrapeTime.Seconds() %}s ago,{% space %}
scrape_duration={%f.3 ts.scrapeDuration.Seconds() %}s,{% space %}
samples_scraped={%d ts.samplesScraped %},{% space %}
2021-06-14 13:01:13 +02:00
error={%q= ts.errMsg %}
2020-12-14 12:36:48 +01:00
{% newline %}
{% endfor %}
{% endfor %}
2021-06-18 09:53:10 +02:00
{% for _, jobName := range emptyJobs %}
job={%q= jobName %} (0/0 up)
2020-12-14 12:36:48 +01:00
{% newline %}
2021-06-18 09:53:10 +02:00
{% endfor %}
2020-12-14 12:36:48 +01:00
{% endfunc %}
2021-10-27 19:03:24 +02:00
{% func TargetsResponseHTML(jts []jobTargetsStatuses, emptyJobs []string, onlyUnhealthy bool) %}
2020-12-14 12:36:48 +01:00
<!DOCTYPE html>
2020-12-15 10:58:53 +01:00
<html lang="en">
<head>
2020-12-15 11:37:19 +01:00
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
2021-07-01 10:48:07 +02:00
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
2020-12-15 10:58:53 +01:00
<title>Scrape targets</title>
</head>
2020-12-15 11:37:19 +01:00
<body class="m-3">
<h1>Scrape targets</h1>
<div>
2021-10-27 19:03:24 +02:00
<button type="button" class="btn{% space %}{% if !onlyUnhealthy %}btn-primary{% else %}btn-secondary{% endif %}" onclick="location.href='targets'">
2020-12-15 11:37:19 +01:00
All
</button>
2021-10-27 19:03:24 +02:00
<button type="button" class="btn{% space %}{% if onlyUnhealthy %}btn-primary{% else %}btn-secondary{% endif %}" onclick="location.href='targets?show_only_unhealthy=true'">
2020-12-15 11:37:19 +01:00
Unhealthy
</button>
2020-12-14 12:36:48 +01:00
</div>
2021-10-13 14:59:55 +02:00
{% for i, js := range jts %}
2020-12-15 11:37:19 +01:00
{% if onlyUnhealthy && js.upCount == js.targetsTotal %}{% continue %}{% endif %}
<div>
<h4>
2021-10-27 19:03:24 +02:00
{%s js.job %}{% space %}({%d js.upCount %}/{%d js.targetsTotal %}{% space %}up)
<button type="button" class="btn btn-primary" onclick="document.getElementById('table-{%d i %}').style.display='none'">collapse</button>
<button type="button" class="btn btn-secondary" onclick="document.getElementById('table-{%d i %}').style.display='block'">expand</button>
2020-12-15 11:37:19 +01:00
</h4>
2021-10-27 19:03:24 +02:00
<div id="table-{%d i %}">
2020-12-15 11:37:19 +01:00
<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>
2021-06-14 13:01:13 +02:00
<th scope="col">Samples Scraped</th>
2020-12-15 11:37:19 +01:00
<th scope="col">Error</th>
</tr>
</thead>
<tbody>
2021-10-13 14:59:55 +02:00
{% for j, ts := range js.targetsStatus %}
2020-12-15 11:37:19 +01:00
{% if onlyUnhealthy && ts.up %}{% continue %}{% endif %}
2021-08-15 15:03:54 +02:00
<tr {% if !ts.up %}{%space%}class="alert alert-danger" role="alert"{% endif %}>
2022-02-03 17:57:36 +01:00
<td><a href="{%s ts.endpoint %}">{%s ts.endpoint %}</a> (
<a href="target_response?id={%s ts.targetID %}" target="_blank">fetch response</a>
)</td>
2020-12-15 11:37:19 +01:00
<td>{% if ts.up %}UP{% else %}DOWN{% endif %}</td>
2021-10-13 14:59:55 +02:00
<td>
<button type="button" class="btn btn-sm btn-outline-info" onclick="document.getElementById('original_labels_{%d i %}_{%d j %}').style.display='block'">show original labels</button>{% space %}
2020-12-15 11:37:19 +01:00
{%= formatLabel(ts.labels) %}
2021-10-13 14:59:55 +02:00
<div style="display:none" id="original_labels_{%d i %}_{%d j %}">
<button type="button" class="btn btn-sm btn-outline-info" onclick="document.getElementById('original_labels_{%d i %}_{%d j %}').style.display='none'">hide original labels</button>{% space %}
{%= formatLabel(ts.originalLabels) %}
</div>
2020-12-15 11:37:19 +01:00
</td>
<td>{%f.3 ts.lastScrapeTime.Seconds() %}s ago</td>
<td>{%f.3 ts.scrapeDuration.Seconds() %}s</td>
2021-06-14 13:01:13 +02:00
<td>{%d ts.samplesScraped %}</td>
<td>{%s ts.errMsg %}</td>
2020-12-15 11:37:19 +01:00
</tr>
{% endfor %}
</tbody>
</table>
2021-10-27 19:03:24 +02:00
</div>
2020-12-15 11:37:19 +01:00
</div>
2020-12-14 12:36:48 +01:00
{% endfor %}
2021-06-18 09:53:10 +02:00
{% for _, jobName := range emptyJobs %}
<div>
<h4>
<a>{%s jobName %} (0/0 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">Samples Scraped</th>
<th scope="col">Error</th>
</tr>
</thead>
</table>
</div>
{% endfor %}
2020-12-15 10:58:53 +01:00
</body>
2020-12-14 12:36:48 +01:00
</html>
{% endfunc %}
{% func formatLabel(labels []prompbmarshal.Label) %}
2021-10-11 11:40:46 +02:00
{
{% for i, label := range labels %}
{%s label.Name %}={%q label.Value %}
2021-10-13 14:59:55 +02:00
{% if i+1 < len(labels) %},{% space %}{% endif %}
2021-10-11 11:40:46 +02:00
{% endfor %}
}
2020-12-14 12:36:48 +01:00
{% endfunc %}
2020-12-15 10:58:53 +01:00
2021-06-18 09:53:10 +02:00
{% endstripspace %}