{% import ( "net/url" "time" "github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils" ) %} {% stripspace %} {% func TargetsResponsePlain(tsr *targetsStatusResult, filter *requestFilter) %} {% if tsr.err != nil %} {%s= tsr.err.Error() %} {% return %} {% endif %} {% for _, jts := range tsr.jobTargetsStatuses %} job={%s= jts.jobName %}{% space %}({%d jts.upCount %}/{%d jts.targetsTotal %}{% space %}up) {% newline %} {% for _, ts := range jts.targetsStatus %} {%s= "\t" %} state={% if ts.up %}up{% else %}down{% endif %},{% space %} endpoint={%s= ts.sw.Config.ScrapeURL %},{% space %} labels={%s= ts.sw.Config.Labels.String() %},{% space %} {% 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 %} scrape_duration={%d int(ts.scrapeDuration) %}ms,{% space %} samples_scraped={%d ts.samplesScraped %},{% space %} error={% if ts.err != nil %}{%s= ts.err.Error() %}{% endif %} {% newline %} {% endfor %} {% endfor %} {% for _, jobName := range tsr.emptyJobs %} job={%s= jobName %}{% space %}(0/0 up) {% newline %} {% endfor %} {% endfunc %} {% func TargetsResponseHTML(tsr *targetsStatusResult, filter *requestFilter) %} {%= commonHeader() %} Active Targets {%= navbar() %}
{% if tsr.err != nil %} {%= errorNotification(tsr.err) %} {% endif %}

Active Targets


{%= filtersForm(filter) %}
{%= targetsTabs(tsr, filter, "scrapeTargets") %}
{% endfunc %} {% func ServiceDiscoveryResponse(tsr *targetsStatusResult, filter *requestFilter) %} {%= commonHeader() %} Discovered Targets {%= navbar() %}
{% if tsr.err != nil %} {%= errorNotification(tsr.err) %} {% endif %}

Discovered Targets


{%= filtersForm(filter) %}
{%= targetsTabs(tsr, filter, "discoveredTargets") %}
{% endfunc %} {% func commonHeader() %} {% endfunc %} {% func navbar() %} {% endfunc %} {% func filtersForm(filter *requestFilter) %}
{% endfunc %} {% func targetsTabs(tsr *targetsStatusResult, filter *requestFilter, activeTab string) %}
{% switch activeTab %} {% case "scrapeTargets" %} {%= scrapeTargets(tsr) %} {% case "discoveredTargets" %} {%= discoveredTargets(tsr) %} {% endswitch %}
{% endfunc %} {% func scrapeTargets(tsr *targetsStatusResult) %}
{% for i, jts := range tsr.jobTargetsStatuses %} {%= scrapeJobTargets(i, jts) %} {% endfor %} {% for i, jobName := range tsr.emptyJobs %} {% code num := i + len(tsr.jobTargetsStatuses) jts := &jobTargetsStatuses{ jobName: jobName, } %} {%= scrapeJobTargets(num, jts) %} {% endfor %}
{% endfunc %} {% func scrapeJobTargets(num int, jts *jobTargetsStatuses) %}

{%s jts.jobName %}{% space %}({%d jts.upCount %}/{%d jts.targetsTotal %}{% space %}up) {%= showHideScrapeJobButtons(num) %}

{% for _, ts := range jts.targetsStatus %} {% code endpoint := ts.sw.Config.ScrapeURL targetID := getTargetID(ts.sw) lastScrapeDuration := ts.getDurationFromLastScrape() %} {% endfor %}
Endpoint State Labels Scrapes Errors Last Scrape Duration Samples Last error
{%s endpoint %} ( response ) {% if ts.up %} UP {% else %} DOWN {% endif %}
{%= formatLabels(ts.sw.Config.Labels) %}
{%d ts.scrapesTotal %} {%d ts.scrapesFailed %} {% if lastScrapeDuration < 365*24*time.Hour %} {%d int(lastScrapeDuration.Milliseconds()) %}ms ago {% else %} none {% endif %} {%d int(ts.scrapeDuration) %}ms {%d ts.samplesScraped %} {% if ts.err != nil %}{%s ts.err.Error() %}{% endif %}
{% endfunc %} {% func discoveredTargets(tsr *targetsStatusResult) %} {% code tljs := tsr.getTargetLabelsByJob() %}
{% for i, tlj := range tljs %} {%= discoveredJobTargets(i, tlj) %} {% endfor %}
{% endfunc %} {% func discoveredJobTargets(num int, tlj *targetLabelsByJob) %}

{%s tlj.jobName %}{% space %}({%d tlj.activeTargets %}/{%d tlj.activeTargets+tlj.droppedTargets %}{% space %}active) {%= showHideScrapeJobButtons(num) %}

{% for _, t := range tlj.targets %} 0 %} class="alert alert-danger" {% else %} class="alert alert-warning" {% endif %} {% endif %} > {% endfor %}
Status Discovered Labels Target Labels
{% if t.up %} UP {% elseif t.labels.Len() > 0 %} DOWN {% else %} DROPPED {% endif %} {%= formatLabels(t.discoveredLabels) %} {%= formatLabels(t.labels) %}
{% endfunc %} {% func showHideScrapeJobButtons(num int) %} {% endfunc %} {% func queryArgs(filter *requestFilter, override map[string]string) %} {% code showOnlyUnhealthy := "false" if filter.showOnlyUnhealthy { showOnlyUnhealthy = "true" } m := map[string]string{ "show_only_unhealthy": showOnlyUnhealthy, "endpoint_search": filter.endpointSearch, "label_search": filter.labelSearch, } for k, v := range override { m[k] = v } qa := make(url.Values, len(m)) for k, v := range m { qa[k] = []string{v} } %} {%s qa.Encode() %} {% endfunc %} {% func formatLabels(labels *promutils.Labels) %} {% code labelsList := labels.GetLabels() %} { {% for i, label := range labelsList %} {%s label.Name %}={%q label.Value %} {% if i+1 < len(labelsList) %},{% space %}{% endif %} {% endfor %} } {% endfunc %} {% func errorNotification(err error) %} {% endfunc %} {% endstripspace %}