update readme
This commit is contained in:
parent
cbb7a9f17a
commit
9827e1865a
27
README.md
Normal file
27
README.md
Normal 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
|
||||
```
|
@ -14,7 +14,7 @@ type source struct {
|
||||
|
||||
type config struct {
|
||||
Listen string `yaml:"listen"`
|
||||
Timeout time.Duration `yaml:"timeout"`
|
||||
ScrapTimeout time.Duration `yaml:"scrap_timeout"`
|
||||
Sources []*source `yaml:"sources"`
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ func parseConfig(filename string) (*config, error) {
|
||||
}
|
||||
result := &config{
|
||||
Listen: ":8080",
|
||||
Timeout: 15 * time.Second,
|
||||
ScrapTimeout: 15 * time.Second,
|
||||
}
|
||||
return result, yaml.Unmarshal(data, result)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -17,7 +17,7 @@ type Merger interface {
|
||||
|
||||
type merger struct {
|
||||
mu sync.Mutex
|
||||
timeout time.Duration
|
||||
scrapTimeout time.Duration
|
||||
client *http.Client
|
||||
sources []*source
|
||||
}
|
||||
@ -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,10 +37,10 @@ func New(timeout time.Duration) Merger {
|
||||
MaxConnsPerHost: 10,
|
||||
IdleConnTimeout: 5 * time.Minute,
|
||||
},
|
||||
Timeout: timeout,
|
||||
Timeout: scrapTimeout,
|
||||
}
|
||||
return &merger{
|
||||
timeout: timeout,
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user