add proxy (#8915)
This commit is contained in:
parent
956350db94
commit
accf91305f
|
|
@ -41,6 +41,9 @@ API endpoint. In the following order the plugin will attempt to authenticate.
|
||||||
## ex: endpoint_url = "http://localhost:8000"
|
## ex: endpoint_url = "http://localhost:8000"
|
||||||
# endpoint_url = ""
|
# endpoint_url = ""
|
||||||
|
|
||||||
|
## Set http_proxy (telegraf uses the system wide proxy settings if it's is not set)
|
||||||
|
# http_proxy_url = "http://localhost:8888"
|
||||||
|
|
||||||
# The minimum period for Cloudwatch metrics is 1 minute (60s). However not all
|
# The minimum period for Cloudwatch metrics is 1 minute (60s). However not all
|
||||||
# metrics are made available to the 1 minute period. Some are collected at
|
# metrics are made available to the 1 minute period. Some are collected at
|
||||||
# 3 minute, 5 minute, or larger intervals. See https://aws.amazon.com/cloudwatch/faqs/#monitoring.
|
# 3 minute, 5 minute, or larger intervals. See https://aws.amazon.com/cloudwatch/faqs/#monitoring.
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
"github.com/influxdata/telegraf/internal/limiter"
|
"github.com/influxdata/telegraf/internal/limiter"
|
||||||
"github.com/influxdata/telegraf/metric"
|
"github.com/influxdata/telegraf/metric"
|
||||||
|
"github.com/influxdata/telegraf/plugins/common/proxy"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -35,6 +36,8 @@ type CloudWatch struct {
|
||||||
StatisticInclude []string `toml:"statistic_include"`
|
StatisticInclude []string `toml:"statistic_include"`
|
||||||
Timeout config.Duration `toml:"timeout"`
|
Timeout config.Duration `toml:"timeout"`
|
||||||
|
|
||||||
|
proxy.HTTPProxy
|
||||||
|
|
||||||
Period config.Duration `toml:"period"`
|
Period config.Duration `toml:"period"`
|
||||||
Delay config.Duration `toml:"delay"`
|
Delay config.Duration `toml:"delay"`
|
||||||
Namespace string `toml:"namespace"`
|
Namespace string `toml:"namespace"`
|
||||||
|
|
@ -107,6 +110,9 @@ func (c *CloudWatch) SampleConfig() string {
|
||||||
## ex: endpoint_url = "http://localhost:8000"
|
## ex: endpoint_url = "http://localhost:8000"
|
||||||
# endpoint_url = ""
|
# endpoint_url = ""
|
||||||
|
|
||||||
|
## Set http_proxy (telegraf uses the system wide proxy settings if it's is not set)
|
||||||
|
# http_proxy_url = "http://localhost:8888"
|
||||||
|
|
||||||
# The minimum period for Cloudwatch metrics is 1 minute (60s). However not all
|
# The minimum period for Cloudwatch metrics is 1 minute (60s). However not all
|
||||||
# metrics are made available to the 1 minute period. Some are collected at
|
# metrics are made available to the 1 minute period. Some are collected at
|
||||||
# 3 minute, 5 minute, or larger intervals. See https://aws.amazon.com/cloudwatch/faqs/#monitoring.
|
# 3 minute, 5 minute, or larger intervals. See https://aws.amazon.com/cloudwatch/faqs/#monitoring.
|
||||||
|
|
@ -188,7 +194,10 @@ func (c *CloudWatch) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.client == nil {
|
if c.client == nil {
|
||||||
c.initializeCloudWatch()
|
err := c.initializeCloudWatch()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filteredMetrics, err := getFilteredMetrics(c)
|
filteredMetrics, err := getFilteredMetrics(c)
|
||||||
|
|
@ -249,7 +258,7 @@ func (c *CloudWatch) Gather(acc telegraf.Accumulator) error {
|
||||||
return c.aggregateMetrics(acc, results)
|
return c.aggregateMetrics(acc, results)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CloudWatch) initializeCloudWatch() {
|
func (c *CloudWatch) initializeCloudWatch() error {
|
||||||
credentialConfig := &internalaws.CredentialConfig{
|
credentialConfig := &internalaws.CredentialConfig{
|
||||||
Region: c.Region,
|
Region: c.Region,
|
||||||
AccessKey: c.AccessKey,
|
AccessKey: c.AccessKey,
|
||||||
|
|
@ -262,11 +271,16 @@ func (c *CloudWatch) initializeCloudWatch() {
|
||||||
}
|
}
|
||||||
configProvider := credentialConfig.Credentials()
|
configProvider := credentialConfig.Credentials()
|
||||||
|
|
||||||
|
proxy, err := c.HTTPProxy.Proxy()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
cfg := &aws.Config{
|
cfg := &aws.Config{
|
||||||
HTTPClient: &http.Client{
|
HTTPClient: &http.Client{
|
||||||
// use values from DefaultTransport
|
// use values from DefaultTransport
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
Proxy: http.ProxyFromEnvironment,
|
Proxy: proxy,
|
||||||
DialContext: (&net.Dialer{
|
DialContext: (&net.Dialer{
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
KeepAlive: 30 * time.Second,
|
KeepAlive: 30 * time.Second,
|
||||||
|
|
@ -283,6 +297,8 @@ func (c *CloudWatch) initializeCloudWatch() {
|
||||||
|
|
||||||
loglevel := aws.LogOff
|
loglevel := aws.LogOff
|
||||||
c.client = cloudwatch.New(configProvider, cfg.WithLogLevel(loglevel))
|
c.client = cloudwatch.New(configProvider, cfg.WithLogLevel(loglevel))
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type filteredMetric struct {
|
type filteredMetric struct {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package cloudwatch
|
package cloudwatch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -11,6 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
"github.com/influxdata/telegraf/filter"
|
"github.com/influxdata/telegraf/filter"
|
||||||
|
"github.com/influxdata/telegraf/plugins/common/proxy"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -333,3 +335,16 @@ func TestUpdateWindow(t *testing.T) {
|
||||||
assert.EqualValues(t, c.windowEnd, now.Add(-time.Duration(c.Delay)))
|
assert.EqualValues(t, c.windowEnd, now.Add(-time.Duration(c.Delay)))
|
||||||
assert.EqualValues(t, c.windowStart, newStartTime)
|
assert.EqualValues(t, c.windowStart, newStartTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProxyFunction(t *testing.T) {
|
||||||
|
c := &CloudWatch{
|
||||||
|
HTTPProxy: proxy.HTTPProxy{HTTPProxyURL: "http://www.penguins.com"},
|
||||||
|
}
|
||||||
|
|
||||||
|
proxyFunction, err := c.HTTPProxy.Proxy()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
proxyResult, err := proxyFunction(&http.Request{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, "www.penguins.com", proxyResult.Host)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue