Skip to content

Commit

Permalink
feat(outputs.graphite): Allow to set the local address to bind
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan committed Jan 25, 2024
1 parent f58472d commit 46f3282
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/outputs/graphite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
## If multiple endpoints are configured, the output will be load balanced.
## Only one of the endpoints will be written to with each iteration.
servers = ["localhost:2003"]

## Local address to bind when connecting to the server
## If empty or not set, the local address is automatically chosen.
# local_address = ""

## Prefix metrics name
prefix = ""

## Graphite output template
## see https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
template = "host.tags.measurement.field"
Expand Down
8 changes: 8 additions & 0 deletions plugins/outputs/graphite/graphite.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Graphite struct {
GraphiteStrictRegex string `toml:"graphite_strict_sanitize_regex"`
// URL is only for backwards compatibility
Servers []string `toml:"servers"`
LocalAddr string `toml:"local_address"`
Prefix string `toml:"prefix"`
Template string `toml:"template"`
Templates []string `toml:"templates"`
Expand Down Expand Up @@ -104,6 +105,13 @@ func (g *Graphite) Connect() error {

// Dialer with timeout
d := net.Dialer{Timeout: time.Duration(g.Timeout)}
if g.LocalAddr != "" {
local, err := net.ResolveIPAddr("tcp", g.LocalAddr)
if err != nil {
return fmt.Errorf("cannot resolve local address: %w", err)
}
d.LocalAddr = local
}

// Get secure connection if tls config is set
var conn net.Conn
Expand Down
6 changes: 6 additions & 0 deletions plugins/outputs/graphite/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
## If multiple endpoints are configured, the output will be load balanced.
## Only one of the endpoints will be written to with each iteration.
servers = ["localhost:2003"]

## Local address to bind when connecting to the server
## If empty or not set, the local address is automatically chosen.
# local_address = ""

## Prefix metrics name
prefix = ""

## Graphite output template
## see https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
template = "host.tags.measurement.field"
Expand Down

0 comments on commit 46f3282

Please sign in to comment.