* add nginx plugin * update nginx.toml for nginx plugin * Update nginx.go * add custom headers in writer * Update writer.go Co-authored-by: ulricqin <ulricqin@qq.com>
This commit is contained in:
parent
01c9403fed
commit
909d5e2e7b
|
@ -38,6 +38,9 @@ basic_auth_user = ""
|
|||
# Basic auth password
|
||||
basic_auth_pass = ""
|
||||
|
||||
## Optional headers
|
||||
# headers = ["X-From", "categraf", "X-Xyz", "abc"]
|
||||
|
||||
# timeout settings, unit: ms
|
||||
timeout = 5000
|
||||
dial_timeout = 2500
|
||||
|
|
|
@ -35,9 +35,10 @@ type WriterOpt struct {
|
|||
}
|
||||
|
||||
type WriterOption struct {
|
||||
Url string `toml:"url"`
|
||||
BasicAuthUser string `toml:"basic_auth_user"`
|
||||
BasicAuthPass string `toml:"basic_auth_pass"`
|
||||
Url string `toml:"url"`
|
||||
BasicAuthUser string `toml:"basic_auth_user"`
|
||||
BasicAuthPass string `toml:"basic_auth_pass"`
|
||||
Headers []string `toml:"headers"`
|
||||
|
||||
Timeout int64 `toml:"timeout"`
|
||||
DialTimeout int64 `toml:"dial_timeout"`
|
||||
|
|
|
@ -52,6 +52,13 @@ func (w WriterType) Post(req []byte) error {
|
|||
httpReq.Header.Set("User-Agent", "categraf")
|
||||
httpReq.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0")
|
||||
|
||||
for i := 0; i < len(w.Opts.Headers); i += 2 {
|
||||
httpReq.Header.Add(w.Opts.Headers[i], w.Opts.Headers[i+1])
|
||||
if w.Opts.Headers[i] == "Host" {
|
||||
httpReq.Host = w.Opts.Headers[i+1]
|
||||
}
|
||||
}
|
||||
|
||||
if w.Opts.BasicAuthUser != "" {
|
||||
httpReq.SetBasicAuth(w.Opts.BasicAuthUser, w.Opts.BasicAuthPass)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue