From 9827e1865af3dbce16f08b546d478fc963d49cde Mon Sep 17 00:00:00 2001 From: Dmitry Vasiliev Date: Sun, 17 May 2020 16:58:41 +0300 Subject: [PATCH] update readme --- README.md | 27 +++++++++++++++++++++++++++ cmd/config.go | 10 +++++----- cmd/main.go | 2 +- merger/merger.go | 18 +++++++++--------- 4 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8a4d225 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# prometheus-exporter-merger + +Merges Prometheus metrics from multiple sources. + +## But Why?! + +> [prometheus/prometheus#3756](https://github.com/prometheus/prometheus/issues/3756) + +To start the exporter: + +``` +prometheus-exporter-merger --config config.yaml +``` + +Config example: + +```yaml +listen: :8080 +scrap_timeout: 20s +sources: + - url: http://127.0.0.1:8081/metrics + labels: + key1: value1 + - url: http://127.0.0.1:8082/metrics + labels: + key2: value2 +``` \ No newline at end of file diff --git a/cmd/config.go b/cmd/config.go index 24e95b5..9dfbad3 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -13,9 +13,9 @@ type source struct { } type config struct { - Listen string `yaml:"listen"` - Timeout time.Duration `yaml:"timeout"` - Sources []*source `yaml:"sources"` + Listen string `yaml:"listen"` + ScrapTimeout time.Duration `yaml:"scrap_timeout"` + Sources []*source `yaml:"sources"` } func parseConfig(filename string) (*config, error) { @@ -24,8 +24,8 @@ func parseConfig(filename string) (*config, error) { return nil, err } result := &config{ - Listen: ":8080", - Timeout: 15 * time.Second, + Listen: ":8080", + ScrapTimeout: 15 * time.Second, } return result, yaml.Unmarshal(data, result) } diff --git a/cmd/main.go b/cmd/main.go index 2b0b85d..59cc74e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -24,7 +24,7 @@ func Execute() { panic(err) } - m := merger.New(c.Timeout) + m := merger.New(c.ScrapTimeout) for _, s := range c.Sources { var labels []*prom.LabelPair for k, v := range s.Labels { diff --git a/merger/merger.go b/merger/merger.go index 60d0b55..c8710d5 100644 --- a/merger/merger.go +++ b/merger/merger.go @@ -16,10 +16,10 @@ type Merger interface { } type merger struct { - mu sync.Mutex - timeout time.Duration - client *http.Client - sources []*source + mu sync.Mutex + scrapTimeout time.Duration + client *http.Client + sources []*source } type source struct { @@ -27,7 +27,7 @@ type source struct { labels []*prom.LabelPair } -func New(timeout time.Duration) Merger { +func New(scrapTimeout time.Duration) Merger { client := &http.Client{ Transport: &http.Transport{ DisableKeepAlives: false, @@ -37,11 +37,11 @@ func New(timeout time.Duration) Merger { MaxConnsPerHost: 10, IdleConnTimeout: 5 * time.Minute, }, - Timeout: timeout, + Timeout: scrapTimeout, } return &merger{ - timeout: timeout, - client: client, + scrapTimeout: scrapTimeout, + client: client, } } @@ -56,7 +56,7 @@ func (m *merger) AddSource(url string, labels []*prom.LabelPair) { func (m *merger) Merge(w io.Writer) error { m.mu.Lock() defer m.mu.Unlock() - ctx, cancel := context.WithTimeout(context.Background(), m.timeout) + ctx, cancel := context.WithTimeout(context.Background(), m.scrapTimeout) defer cancel() return m.merge(ctx, w) }