{% import ( "net/url" "strconv" "strings" "github.com/VictoriaMetrics/VictoriaMetrics/lib/htmlcomponents" "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={%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 %} {% newline %} {% endfor %} {% endfor %} {% for _, jobName := range tsr.emptyJobs %} job={%s= jobName %}{% space %}(0/0 up) {% newline %} {% endfor %} {% endfunc %} {% func TargetsResponseHTML(tsr *targetsStatusResult, filter *requestFilter) %} {%= htmlcomponents.CommonHeader() %} Active Targets {%= htmlcomponents.Navbar() %}
{% if tsr.err != nil %} {%= htmlcomponents.ErrorNotification(tsr.err) %} {% endif %}

Active Targets


{%= filtersForm(filter) %}
{%= targetsTabs(tsr, filter, "scrapeTargets") %}
{% endfunc %} {% func ServiceDiscoveryResponse(tsr *targetsStatusResult, filter *requestFilter) %} {%= htmlcomponents.CommonHeader() %} Discovered Targets {%= htmlcomponents.Navbar() %}
{% if tsr.err != nil %} {%= htmlcomponents.ErrorNotification(tsr.err) %} {% endif %}

Discovered Targets


{%= filtersForm(filter) %}
{%= targetsTabs(tsr, filter, "discoveredTargets") %}
{% 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, tsr.hasOriginalLabels) %} {% endfor %} {% for i, jobName := range tsr.emptyJobs %} {% code num := i + len(tsr.jobTargetsStatuses) jts := &jobTargetsStatuses{ jobName: jobName, } %} {%= scrapeJobTargets(num, jts, tsr.hasOriginalLabels) %} {% endfor %}
{% endfunc %} {% func scrapeJobTargets(num int, jts *jobTargetsStatuses, hasOriginalLabels bool) %}

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

{% if hasOriginalLabels %} {% endif %} {% for _, ts := range jts.targetsStatus %} {% code endpoint := ts.sw.Config.ScrapeURL originalLabels := ts.sw.Config.OriginalLabels // The target is uniquely identified by a pointer to its original labels. targetID := getLabelsID(originalLabels) %} {% if hasOriginalLabels %} {% endif %} {% endfor %}
Endpoint State LabelsDebug relabelingScrapes Errors Last Scrape Duration Samples Last error
{%s endpoint %} {% if hasOriginalLabels %} {% space %} (response) {% endif %} {% if ts.up %} UP {% else %} DOWN {% endif %}
{%= formatLabels(ts.sw.Config.Labels) %}
{% if hasOriginalLabels %} {% endif %}
target{% space %} metrics {%d ts.scrapesTotal %} {%d ts.scrapesFailed %} {%s ts.getDurationFromLastScrape() %} {%d int(ts.scrapeDuration) %}ms {%d ts.samplesScraped %} {% if ts.err != nil %}{%s ts.err.Error() %}{% endif %}
{% endfunc %} {% func discoveredTargets(tsr *targetsStatusResult) %} {% if !tsr.hasOriginalLabels %} {% return %} {% endif %} {% if n := droppedTargetsMap.getTotalTargets(); n > *maxDroppedTargets %} {% endif %} {% 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 Debug relabeling
{% if t.up %} UP {% elseif t.labels.Len() > 0 %} DOWN {% else %} DROPPED ({%s string(t.dropReason) %}) {% if len(t.clusterMemberNums) > 0 %}
exists at{% space %} {% for i, memberNum := range t.clusterMemberNums %} {% if *clusterMemberURLTemplate == "" %} shard-{%d memberNum %} {% else %} shard-{%d memberNum %} {% endif %} {% if i+1 < len(t.clusterMemberNums) %},{% space %}{% endif %} {% endfor %} {% endif %} {% endif %}
{%= formatLabels(t.originalLabels) %} {%= formatLabels(t.labels) %} {% code targetID := getLabelsID(t.originalLabels) %} debug
{% 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 %} {% endstripspace %}