lib/promscrape: add -promscrape.cluster.memberURLTemplate command-line flag for creating direct links to vmagent instances at /service-discovery page

See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4018#issuecomment-1843811569
This commit is contained in:
Aliaksandr Valialkin 2023-12-07 16:04:19 +02:00
parent 802adf3b65
commit e373bb84d5
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
4 changed files with 691 additions and 657 deletions

View file

@ -813,9 +813,15 @@ start a cluster of three `vmagent` instances, where each target is scraped by tw
Every `vmagent` in the cluster exposes all the discovered targets at `http://vmagent:8429/service-discovery` page.
Each discovered target on this page contains its status (`UP`, `DOWN` or `DROPPED` with the reason why the target has been dropped).
If the target is dropped because of sharding to other `vmagent` instances in the cluster, then the status column contains
`-promscrape.cluster.memberNum` values for `vmagent` instances where the given target is scraped. Note that `vmagent` shows
up to `-promscrape.maxDroppedTargets` dropped targets on the `/service-discovery` page. Increase the `-promscrape.maxDroppedTargets` command-line flag value
if the `/service-discovery` page misses some dropped targets.
`-promscrape.cluster.memberNum` values for `vmagent` instances where the given target is scraped.
The `/service-discovery` page provides links to the corresponding `vmagent` instances if `-promscrape.cluster.memberURLTemplate` command-line flag is set.
Every occurrence of `%d` inside the `-promscrape.cluster.memberURLTemplate` is substituted with the `-promscrape.cluster.memberNum`
for the corresponding `vmagent` instance. For examle, `-promscrape.cluster.memberURLTemplate='http://vmagent-instance-%d:8429/targets'`
generates `http://vmagent-instance-42:8429/targets` url for `vmagent` instance, which runs with `-promscrape.cluster.memberNum=42`.
Note that `vmagent` shows up to `-promscrape.maxDroppedTargets` dropped targets on the `/service-discovery` page.
Increase the `-promscrape.maxDroppedTargets` command-line flag value if the `/service-discovery` page misses some dropped targets.
If each target is scraped by multiple `vmagent` instances, then data deduplication must be enabled at remote storage pointed by `-remoteWrite.url`.
The `-dedup.minScrapeInterval` must be set to the `scrape_interval` configured at `-promscrape.config`.

View file

@ -64,6 +64,10 @@ var (
"See also -promscrape.cluster.memberLabel . See https://docs.victoriametrics.com/vmagent.html#scraping-big-number-of-targets for more info")
clusterMemberLabel = flag.String("promscrape.cluster.memberLabel", "", "If non-empty, then the label with this name and the -promscrape.cluster.memberNum value "+
"is added to all the scraped metrics. See https://docs.victoriametrics.com/vmagent.html#scraping-big-number-of-targets for more info")
clusterMemberURLTemplate = flag.String("promscrape.cluster.memberURLTemplate", "", "An optional template for URL to access vmagent instance with the given -promscrape.cluster.memberNum value. "+
"Every %d occurence in the template is substituted with -promscrape.cluster.memberNum at urls to vmagent instances responsible for scraping the given target "+
"at /service-discovery page. For example -promscrape.cluster.memberURLTemplate='http://vmagent-%d:8429/targets'. "+
"See https://docs.victoriametrics.com/vmagent.html#scraping-big-number-of-targets for more details")
clusterReplicationFactor = flag.Int("promscrape.cluster.replicationFactor", 1, "The number of members in the cluster, which scrape the same targets. "+
"If the replication factor is greater than 1, then the deduplication must be enabled at remote storage side. "+
"See https://docs.victoriametrics.com/vmagent.html#scraping-big-number-of-targets for more info")

View file

@ -1,5 +1,7 @@
{% import (
"net/url"
"strconv"
"strings"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/htmlcomponents"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
@ -335,7 +337,11 @@
<span title="The target exists at vmagent instances with the given -promscrape.cluster.memberNum values">
exists at{% space %}
{% for i, memberNum := range t.clusterMemberNums %}
{%d memberNum %}
{% if *clusterMemberURLTemplate == "" %}
{%d memberNum %}
{% else %}
<a href="{%s strings.ReplaceAll(*clusterMemberURLTemplate, "%d", strconv.Itoa(memberNum)) %}">{%d memberNum %}</a>
{% endif %}
{% if i+1 < len(t.clusterMemberNums) %},{% space %}{% endif %}
{% endfor %}
{% endif %}

File diff suppressed because it is too large Load diff