lib/promscrape: show never scraped message for never scraped targets at /targets page

This commit is contained in:
Aliaksandr Valialkin 2023-12-06 22:24:24 +02:00
parent 935bec447b
commit 67468a0c46
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
3 changed files with 512 additions and 527 deletions

View file

@ -304,8 +304,12 @@ type targetStatus struct {
err error
}
func (ts *targetStatus) getDurationFromLastScrape() time.Duration {
return time.Since(time.Unix(ts.scrapeTime/1000, (ts.scrapeTime%1000)*1e6))
func (ts *targetStatus) getDurationFromLastScrape() string {
if ts.scrapeTime <= 0 {
return "never scraped"
}
d := time.Since(time.Unix(ts.scrapeTime/1000, (ts.scrapeTime%1000)*1e6))
return fmt.Sprintf("%.3fs ago", d.Seconds())
}
type droppedTargets struct {

View file

@ -1,6 +1,5 @@
{% import (
"net/url"
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/htmlcomponents"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
@ -26,7 +25,7 @@
{% if filter.showOriginalLabels %}originalLabels={%s= ts.sw.Config.OriginalLabels.String() %},{% space %}{% endif %}
scrapes_total={%d ts.scrapesTotal %},{% space %}
scrapes_failed={%d ts.scrapesFailed %},{% space %}
last_scrape={%d int(ts.getDurationFromLastScrape().Milliseconds()) %}ms ago,{% space %}
last_scrape={%s ts.getDurationFromLastScrape() %},{% space %}
scrape_duration={%d int(ts.scrapeDuration) %}ms,{% space %}
samples_scraped={%d ts.samplesScraped %},{% space %}
error={% if ts.err != nil %}{%s= ts.err.Error() %}{% endif %}
@ -228,7 +227,6 @@
// The target is uniquely identified by a pointer to its original labels.
targetID := getLabelsID(originalLabels)
lastScrapeDuration := ts.getDurationFromLastScrape()
%}
<tr {% if !ts.up %}{%space%}class="alert alert-danger" role="alert" {% endif %}>
<td class="endpoint">
@ -269,12 +267,7 @@
{% endif %}
<td>{%d ts.scrapesTotal %}</td>
<td>{%d ts.scrapesFailed %}</td>
<td>
{% if lastScrapeDuration < 365*24*time.Hour %}
{%d int(lastScrapeDuration.Milliseconds()) %}ms ago
{% else %}
none
{% endif %}
<td>{%s ts.getDurationFromLastScrape() %}
<td>{%d int(ts.scrapeDuration) %}ms</td>
<td>{%d ts.samplesScraped %}</td>
<td>{% if ts.err != nil %}{%s ts.err.Error() %}{% endif %}</td>

File diff suppressed because it is too large Load diff