Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vadv committed May 17, 2020
1 parent cbb7a9f commit 9827e18
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
10 changes: 5 additions & 5 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions merger/merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ 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 {
url string
labels []*prom.LabelPair
}

func New(timeout time.Duration) Merger {
func New(scrapTimeout time.Duration) Merger {
client := &http.Client{
Transport: &http.Transport{
DisableKeepAlives: false,
Expand All @@ -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,
}
}

Expand All @@ -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)
}

0 comments on commit 9827e18

Please sign in to comment.