update readme

This commit is contained in:
Dmitry Vasiliev 2020-05-17 16:58:41 +03:00
parent cbb7a9f17a
commit 9827e1865a
No known key found for this signature in database
GPG Key ID: C9A6FF8856B941E3
4 changed files with 42 additions and 15 deletions

27
README.md Normal file
View File

@ -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
```

View File

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

View File

@ -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 {

View File

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