2022-02-03 18:22:35 +00:00
|
|
|
{% import (
|
|
|
|
"time"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
|
|
|
|
) %}
|
2020-12-14 11:36:48 +00:00
|
|
|
|
2021-06-18 07:53:10 +00:00
|
|
|
{% stripspace %}
|
2020-12-14 11:36:48 +00:00
|
|
|
|
2021-06-18 07:53:10 +00:00
|
|
|
{% func TargetsResponsePlain(jts []jobTargetsStatuses, emptyJobs []string, showOriginLabels bool) %}
|
2020-12-14 11:36:48 +00:00
|
|
|
|
|
|
|
{% for _, js := range jts %}
|
2021-07-26 09:22:48 +00:00
|
|
|
job={%q= js.job %} ({%d js.upCount %}/{%d js.targetsTotal %}{% space %}up)
|
2020-12-14 11:36:48 +00:00
|
|
|
{% newline %}
|
|
|
|
{% for _, ts := range js.targetsStatus %}
|
2022-02-03 18:22:35 +00:00
|
|
|
{%s= "\t" %}
|
|
|
|
state={% if ts.up %}up{% else %}down{% endif %},{% space %}
|
|
|
|
endpoint={%s= ts.sw.Config.ScrapeURL %},{% space %}
|
|
|
|
labels={%s= promLabelsString(promrelabel.FinalizeLabels(nil, ts.sw.Config.Labels)) %},{% space %}
|
|
|
|
{% if showOriginLabels %}originalLabels={%s= promLabelsString(ts.sw.Config.OriginalLabels) %},{% space %}{% endif %}
|
|
|
|
scrapes_total={%d ts.scrapesTotal %},{% space %}
|
|
|
|
scrapes_failed={%d ts.scrapesFailed %},{% space %}
|
|
|
|
last_scrape={%f.3 ts.getDurationFromLastScrape().Seconds() %}s ago,{% space %}
|
|
|
|
scrape_duration={%d int(ts.scrapeDuration) %}ms,{% space %}
|
2021-06-18 07:53:10 +00:00
|
|
|
samples_scraped={%d ts.samplesScraped %},{% space %}
|
2022-02-03 18:22:35 +00:00
|
|
|
error={% if ts.err != nil %}{%s= ts.err.Error() %}{% endif %}
|
2020-12-14 11:36:48 +00:00
|
|
|
{% newline %}
|
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
2021-06-18 07:53:10 +00:00
|
|
|
|
|
|
|
{% for _, jobName := range emptyJobs %}
|
|
|
|
job={%q= jobName %} (0/0 up)
|
2020-12-14 11:36:48 +00:00
|
|
|
{% newline %}
|
2021-06-18 07:53:10 +00:00
|
|
|
{% endfor %}
|
2020-12-14 11:36:48 +00:00
|
|
|
|
|
|
|
{% endfunc %}
|
|
|
|
|
2021-10-27 17:03:24 +00:00
|
|
|
{% func TargetsResponseHTML(jts []jobTargetsStatuses, emptyJobs []string, onlyUnhealthy bool) %}
|
2020-12-14 11:36:48 +00:00
|
|
|
<!DOCTYPE html>
|
2020-12-15 09:58:53 +00:00
|
|
|
<html lang="en">
|
|
|
|
<head>
|
2020-12-15 10:37:19 +00:00
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
2021-07-01 08:48:07 +00: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 09:58:53 +00:00
|
|
|
<title>Scrape targets</title>
|
2022-02-12 16:40:29 +00:00
|
|
|
<script>
|
|
|
|
function collapse_all() {
|
|
|
|
for (var i = 0; i < {%d len(jts) %}; i++) {
|
|
|
|
var id = "table-" + i;
|
|
|
|
document.getElementById(id).style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function expand_all() {
|
|
|
|
for (var i = 0; i < {%d len(jts) %}; i++) {
|
|
|
|
var id = "table-" + i;
|
|
|
|
document.getElementById(id).style.display = 'block';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2020-12-15 09:58:53 +00:00
|
|
|
</head>
|
2020-12-15 10:37:19 +00:00
|
|
|
<body class="m-3">
|
|
|
|
<h1>Scrape targets</h1>
|
2022-02-12 16:40:29 +00:00
|
|
|
<div style="padding: 3px">
|
2021-10-27 17:03:24 +00:00
|
|
|
<button type="button" class="btn{% space %}{% if !onlyUnhealthy %}btn-primary{% else %}btn-secondary{% endif %}" onclick="location.href='targets'">
|
2020-12-15 10:37:19 +00:00
|
|
|
All
|
|
|
|
</button>
|
2021-10-27 17:03:24 +00: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 10:37:19 +00:00
|
|
|
Unhealthy
|
|
|
|
</button>
|
2022-02-12 16:40:29 +00:00
|
|
|
<button type="button" class="btn btn-primary" onclick="collapse_all()">
|
|
|
|
Collapse all
|
|
|
|
</button>
|
|
|
|
<button type="button" class="btn btn-secondary" onclick="expand_all()">
|
|
|
|
Expand all
|
|
|
|
</button>
|
2020-12-14 11:36:48 +00:00
|
|
|
</div>
|
2021-10-13 12:59:55 +00:00
|
|
|
{% for i, js := range jts %}
|
2020-12-15 10:37:19 +00:00
|
|
|
{% if onlyUnhealthy && js.upCount == js.targetsTotal %}{% continue %}{% endif %}
|
|
|
|
<div>
|
|
|
|
<h4>
|
2021-10-27 17:03:24 +00: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 10:37:19 +00:00
|
|
|
</h4>
|
2021-10-27 17:03:24 +00:00
|
|
|
<div id="table-{%d i %}">
|
2020-12-15 10:37:19 +00:00
|
|
|
<table class="table table-striped table-hover table-bordered table-sm">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th scope="col">Endpoint</th>
|
|
|
|
<th scope="col">State</th>
|
2022-02-03 18:22:35 +00:00
|
|
|
<th scope="col" title="scrape target labels">Labels</th>
|
|
|
|
<th scope="col" title="total scrapes">Scrapes</th>
|
|
|
|
<th scope="col" title="total scrape errors">Errors</th>
|
|
|
|
<th scope="col" title="the time of the last scrape">Last Scrape</th>
|
|
|
|
<th scope="col" title="the duration of the last scrape">Duration</th>
|
|
|
|
<th scope="col" title="the number of metrics scraped during the last scrape">Samples</th>
|
|
|
|
<th scope="col" title="error from the last scrape (if any)">Last error</th>
|
2020-12-15 10:37:19 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2022-02-03 18:22:35 +00:00
|
|
|
{% for _, ts := range js.targetsStatus %}
|
|
|
|
{% code
|
|
|
|
endpoint := ts.sw.Config.ScrapeURL
|
|
|
|
targetID := getTargetID(ts.sw)
|
|
|
|
lastScrapeTime := ts.getDurationFromLastScrape()
|
|
|
|
%}
|
2020-12-15 10:37:19 +00:00
|
|
|
{% if onlyUnhealthy && ts.up %}{% continue %}{% endif %}
|
2021-08-15 13:03:54 +00:00
|
|
|
<tr {% if !ts.up %}{%space%}class="alert alert-danger" role="alert"{% endif %}>
|
2022-02-03 18:22:35 +00:00
|
|
|
<td><a href="{%s endpoint %}" target="_blank">{%s endpoint %}</a> (
|
|
|
|
<a href="target_response?id={%s targetID %}" target="_blank" title="click to fetch target response on behalf of the scraper">response</a>
|
2022-02-03 16:57:36 +00:00
|
|
|
)</td>
|
2020-12-15 10:37:19 +00:00
|
|
|
<td>{% if ts.up %}UP{% else %}DOWN{% endif %}</td>
|
2021-10-13 12:59:55 +00:00
|
|
|
<td>
|
2022-02-03 18:22:35 +00:00
|
|
|
<div title="click to show original labels" onclick="document.getElementById('original_labels_{%s targetID %}').style.display='block'">
|
|
|
|
{%= formatLabel(promrelabel.FinalizeLabels(nil, ts.sw.Config.Labels)) %}
|
|
|
|
</div>
|
|
|
|
<div style="display:none" id="original_labels_{%s targetID %}">
|
|
|
|
{%= formatLabel(ts.sw.Config.OriginalLabels) %}
|
2021-10-13 12:59:55 +00:00
|
|
|
</div>
|
2020-12-15 10:37:19 +00:00
|
|
|
</td>
|
2022-02-03 18:22:35 +00:00
|
|
|
<td>{%d ts.scrapesTotal %}</td>
|
|
|
|
<td>{%d ts.scrapesFailed %}</td>
|
|
|
|
<td>
|
|
|
|
{% if lastScrapeTime < 365*24*time.Hour %}
|
|
|
|
{%f.3 lastScrapeTime.Seconds() %}s ago
|
|
|
|
{% else %}
|
|
|
|
none
|
|
|
|
{% endif %}
|
|
|
|
<td>{%d int(ts.scrapeDuration) %}ms</td>
|
2021-06-14 11:01:13 +00:00
|
|
|
<td>{%d ts.samplesScraped %}</td>
|
2022-02-03 18:22:35 +00:00
|
|
|
<td>{% if ts.err != nil %}{%s ts.err.Error() %}{% endif %}</td>
|
2020-12-15 10:37:19 +00:00
|
|
|
</tr>
|
|
|
|
{% endfor %}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2021-10-27 17:03:24 +00:00
|
|
|
</div>
|
2020-12-15 10:37:19 +00:00
|
|
|
</div>
|
2020-12-14 11:36:48 +00:00
|
|
|
{% endfor %}
|
2021-06-18 07:53:10 +00: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 09:58:53 +00:00
|
|
|
</body>
|
2020-12-14 11:36:48 +00:00
|
|
|
</html>
|
|
|
|
{% endfunc %}
|
|
|
|
|
|
|
|
{% func formatLabel(labels []prompbmarshal.Label) %}
|
2021-10-11 09:40:46 +00:00
|
|
|
{
|
|
|
|
{% for i, label := range labels %}
|
|
|
|
{%s label.Name %}={%q label.Value %}
|
2021-10-13 12:59:55 +00:00
|
|
|
{% if i+1 < len(labels) %},{% space %}{% endif %}
|
2021-10-11 09:40:46 +00:00
|
|
|
{% endfor %}
|
|
|
|
}
|
2020-12-14 11:36:48 +00:00
|
|
|
{% endfunc %}
|
2020-12-15 09:58:53 +00:00
|
|
|
|
2021-06-18 07:53:10 +00:00
|
|
|
{% endstripspace %}
|