mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmagent: expose -promscrape.config contents at /config page as Prometheus does
See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1695
This commit is contained in:
parent
1e56d19c09
commit
aeedfe2fe2
4 changed files with 30 additions and 3 deletions
|
@ -159,6 +159,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool {
|
||||||
httpserver.WriteAPIHelp(w, [][2]string{
|
httpserver.WriteAPIHelp(w, [][2]string{
|
||||||
{"/targets", "discovered targets list"},
|
{"/targets", "discovered targets list"},
|
||||||
{"/api/v1/targets", "advanced information about discovered targets in JSON format"},
|
{"/api/v1/targets", "advanced information about discovered targets in JSON format"},
|
||||||
|
{"/config", "-promscrape.config contents"},
|
||||||
{"/metrics", "available service metrics"},
|
{"/metrics", "available service metrics"},
|
||||||
{"/-/reload", "reload configuration"},
|
{"/-/reload", "reload configuration"},
|
||||||
})
|
})
|
||||||
|
@ -259,6 +260,11 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool {
|
||||||
promscrapeTargetsRequests.Inc()
|
promscrapeTargetsRequests.Inc()
|
||||||
promscrape.WriteHumanReadableTargetsStatus(w, r)
|
promscrape.WriteHumanReadableTargetsStatus(w, r)
|
||||||
return true
|
return true
|
||||||
|
case "/config":
|
||||||
|
promscrapeConfigRequests.Inc()
|
||||||
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
|
promscrape.WriteConfigData(w)
|
||||||
|
return true
|
||||||
case "/api/v1/targets":
|
case "/api/v1/targets":
|
||||||
promscrapeAPIV1TargetsRequests.Inc()
|
promscrapeAPIV1TargetsRequests.Inc()
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
@ -427,6 +433,8 @@ var (
|
||||||
promscrapeTargetsRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/targets"}`)
|
promscrapeTargetsRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/targets"}`)
|
||||||
promscrapeAPIV1TargetsRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/api/v1/targets"}`)
|
promscrapeAPIV1TargetsRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/api/v1/targets"}`)
|
||||||
|
|
||||||
|
promscrapeConfigRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/config"}`)
|
||||||
|
|
||||||
promscrapeConfigReloadRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/-/reload"}`)
|
promscrapeConfigReloadRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/-/reload"}`)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ sort: 15
|
||||||
|
|
||||||
## tip
|
## tip
|
||||||
|
|
||||||
|
* FEATURE: vmagent: expose `-promscrape.config` contents at `/config` page as Prometheus does. See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1695).
|
||||||
* FEATURE: add trigonometric functions, which are going to be added in [Prometheus 2.31](https://github.com/prometheus/prometheus/pull/9239): [acosh](https://docs.victoriametrics.com/MetricsQL.html#acosh), [asinh](https://docs.victoriametrics.com/MetricsQL.html#asinh), [atan](https://docs.victoriametrics.com/MetricsQL.html#atan), [atanh](https://docs.victoriametrics.com/MetricsQL.html#atanh), [cosh](https://docs.victoriametrics.com/MetricsQL.html#cosh), [deg](https://docs.victoriametrics.com/MetricsQL.html#deg), [rad](https://docs.victoriametrics.com/MetricsQL.html#rad), [sinh](https://docs.victoriametrics.com/MetricsQL.html#sinh), [tan](https://docs.victoriametrics.com/MetricsQL.html#tan), [tanh](https://docs.victoriametrics.com/MetricsQL.html#tanh). Also add `atan2` binary operator. See [this pull request](https://github.com/prometheus/prometheus/pull/9248).
|
* FEATURE: add trigonometric functions, which are going to be added in [Prometheus 2.31](https://github.com/prometheus/prometheus/pull/9239): [acosh](https://docs.victoriametrics.com/MetricsQL.html#acosh), [asinh](https://docs.victoriametrics.com/MetricsQL.html#asinh), [atan](https://docs.victoriametrics.com/MetricsQL.html#atan), [atanh](https://docs.victoriametrics.com/MetricsQL.html#atanh), [cosh](https://docs.victoriametrics.com/MetricsQL.html#cosh), [deg](https://docs.victoriametrics.com/MetricsQL.html#deg), [rad](https://docs.victoriametrics.com/MetricsQL.html#rad), [sinh](https://docs.victoriametrics.com/MetricsQL.html#sinh), [tan](https://docs.victoriametrics.com/MetricsQL.html#tan), [tanh](https://docs.victoriametrics.com/MetricsQL.html#tanh). Also add `atan2` binary operator. See [this pull request](https://github.com/prometheus/prometheus/pull/9248).
|
||||||
* FEATURE: consistently return the same set of time series from [limitk](https://docs.victoriametrics.com/MetricsQL.html#limitk) function. This improves the usability of periodically refreshed graphs.
|
* FEATURE: consistently return the same set of time series from [limitk](https://docs.victoriametrics.com/MetricsQL.html#limitk) function. This improves the usability of periodically refreshed graphs.
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,8 @@ var (
|
||||||
// Config represents essential parts from Prometheus config defined at https://prometheus.io/docs/prometheus/latest/configuration/configuration/
|
// Config represents essential parts from Prometheus config defined at https://prometheus.io/docs/prometheus/latest/configuration/configuration/
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Global GlobalConfig `yaml:"global,omitempty"`
|
Global GlobalConfig `yaml:"global,omitempty"`
|
||||||
ScrapeConfigs []ScrapeConfig `yaml:"scrape_configs"`
|
ScrapeConfigs []ScrapeConfig `yaml:"scrape_configs,omitempty"`
|
||||||
ScrapeConfigFiles []string `yaml:"scrape_config_files"`
|
ScrapeConfigFiles []string `yaml:"scrape_config_files,omitempty"`
|
||||||
|
|
||||||
// This is set to the directory from where the config has been loaded.
|
// This is set to the directory from where the config has been loaded.
|
||||||
baseDir string
|
baseDir string
|
||||||
|
@ -121,7 +121,7 @@ type ScrapeConfig struct {
|
||||||
MetricsPath string `yaml:"metrics_path,omitempty"`
|
MetricsPath string `yaml:"metrics_path,omitempty"`
|
||||||
HonorLabels bool `yaml:"honor_labels,omitempty"`
|
HonorLabels bool `yaml:"honor_labels,omitempty"`
|
||||||
HonorTimestamps bool `yaml:"honor_timestamps,omitempty"`
|
HonorTimestamps bool `yaml:"honor_timestamps,omitempty"`
|
||||||
FollowRedirects *bool `yaml:"follow_redirects"` // omitempty isn't set, since the default value for this flag is true.
|
FollowRedirects *bool `yaml:"follow_redirects,omitempty"`
|
||||||
Scheme string `yaml:"scheme,omitempty"`
|
Scheme string `yaml:"scheme,omitempty"`
|
||||||
Params map[string][]string `yaml:"params,omitempty"`
|
Params map[string][]string `yaml:"params,omitempty"`
|
||||||
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
|
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
@ -70,8 +71,22 @@ var (
|
||||||
// PendingScrapeConfigs - zero value means, that
|
// PendingScrapeConfigs - zero value means, that
|
||||||
// all scrapeConfigs are inited and ready for work.
|
// all scrapeConfigs are inited and ready for work.
|
||||||
PendingScrapeConfigs int32
|
PendingScrapeConfigs int32
|
||||||
|
|
||||||
|
// configData contains -promscrape.config data
|
||||||
|
configData atomic.Value
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WriteConfigData writes -promscrape.config contents to w
|
||||||
|
func WriteConfigData(w io.Writer) {
|
||||||
|
v := configData.Load()
|
||||||
|
if v == nil {
|
||||||
|
// Nothing to write to w
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b := v.(*[]byte)
|
||||||
|
w.Write(*b)
|
||||||
|
}
|
||||||
|
|
||||||
func runScraper(configFile string, pushData func(wr *prompbmarshal.WriteRequest), globalStopCh <-chan struct{}) {
|
func runScraper(configFile string, pushData func(wr *prompbmarshal.WriteRequest), globalStopCh <-chan struct{}) {
|
||||||
if configFile == "" {
|
if configFile == "" {
|
||||||
// Nothing to scrape.
|
// Nothing to scrape.
|
||||||
|
@ -89,6 +104,7 @@ func runScraper(configFile string, pushData func(wr *prompbmarshal.WriteRequest)
|
||||||
logger.Fatalf("cannot read %q: %s", configFile, err)
|
logger.Fatalf("cannot read %q: %s", configFile, err)
|
||||||
}
|
}
|
||||||
data := cfg.marshal()
|
data := cfg.marshal()
|
||||||
|
configData.Store(&data)
|
||||||
cfg.mustStart()
|
cfg.mustStart()
|
||||||
|
|
||||||
scs := newScrapeConfigs(pushData)
|
scs := newScrapeConfigs(pushData)
|
||||||
|
@ -132,6 +148,7 @@ func runScraper(configFile string, pushData func(wr *prompbmarshal.WriteRequest)
|
||||||
cfgNew.mustStart()
|
cfgNew.mustStart()
|
||||||
cfg = cfgNew
|
cfg = cfgNew
|
||||||
data = dataNew
|
data = dataNew
|
||||||
|
configData.Store(&data)
|
||||||
case <-tickerCh:
|
case <-tickerCh:
|
||||||
cfgNew, err := loadConfig(configFile)
|
cfgNew, err := loadConfig(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -147,6 +164,7 @@ func runScraper(configFile string, pushData func(wr *prompbmarshal.WriteRequest)
|
||||||
cfgNew.mustStart()
|
cfgNew.mustStart()
|
||||||
cfg = cfgNew
|
cfg = cfgNew
|
||||||
data = dataNew
|
data = dataNew
|
||||||
|
configData.Store(&data)
|
||||||
case <-globalStopCh:
|
case <-globalStopCh:
|
||||||
cfg.mustStop()
|
cfg.mustStop()
|
||||||
logger.Infof("stopping Prometheus scrapers")
|
logger.Infof("stopping Prometheus scrapers")
|
||||||
|
|
Loading…
Reference in a new issue