Skip to content

Commit

Permalink
Add standard SSL options to mysql input (#2933)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Shilin authored and danielnelson committed Jun 19, 2017
1 parent 193e8fa commit cb5a12d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions etc/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,11 @@
# ## Some queries we may want to run less often (such as SHOW GLOBAL VARIABLES)
# interval_slow = "30m"

# ## Optional SSL Config (will be used if tls=custom parameter specified in server uri)
# ssl_ca = "/etc/telegraf/ca.pem"
# ssl_cert = "/etc/telegraf/cert.pem"
# ssl_key = "/etc/telegraf/key.pem"


# # Read metrics about network interface usage
# [[inputs.net]]
Expand Down
5 changes: 5 additions & 0 deletions plugins/inputs/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ This plugin gathers the statistic data from MySQL server
#
## Some queries we may want to run less often (such as SHOW GLOBAL VARIABLES)
interval_slow = "30m"
## Optional SSL Config (will be used if tls=custom parameter specified in server uri)
ssl_ca = "/etc/telegraf/ca.pem"
ssl_cert = "/etc/telegraf/cert.pem"
ssl_key = "/etc/telegraf/key.pem"
```

## Measurements & Fields
Expand Down
21 changes: 20 additions & 1 deletion plugins/inputs/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/inputs"

"github.com/go-sql-driver/mysql"
Expand All @@ -36,11 +37,14 @@ type Mysql struct {
GatherFileEventsStats bool `toml:"gather_file_events_stats"`
GatherPerfEventsStatements bool `toml:"gather_perf_events_statements"`
IntervalSlow string `toml:"interval_slow"`
SSLCA string `toml:"ssl_ca"`
SSLCert string `toml:"ssl_cert"`
SSLKey string `toml:"ssl_key"`
}

var sampleConfig = `
## specify servers via a url matching:
## [username[:password]@][protocol[(address)]]/[?tls=[true|false|skip-verify]]
## [username[:password]@][protocol[(address)]]/[?tls=[true|false|skip-verify|custom]]
## see https://github.com/go-sql-driver/mysql#dsn-data-source-name
## e.g.
## servers = ["user:passwd@tcp(127.0.0.1:3306)/?tls=false"]
Expand Down Expand Up @@ -97,6 +101,11 @@ var sampleConfig = `
#
## Some queries we may want to run less often (such as SHOW GLOBAL VARIABLES)
interval_slow = "30m"
## Optional SSL Config (will be used if tls=custom parameter specified in server uri)
ssl_ca = "/etc/telegraf/ca.pem"
ssl_cert = "/etc/telegraf/cert.pem"
ssl_key = "/etc/telegraf/key.pem"
`

var defaultTimeout = time.Second * time.Duration(5)
Expand Down Expand Up @@ -135,6 +144,16 @@ func (m *Mysql) Gather(acc telegraf.Accumulator) error {
if !initDone {
m.InitMysql()
}

tlsConfig, err := internal.GetTLSConfig(m.SSLCert, m.SSLKey, m.SSLCA, false)
if err != nil {
log.Printf("E! MySQL Error registering TLS config: %s", err)
}

if tlsConfig != nil {
mysql.RegisterTLSConfig("custom", tlsConfig)
}

var wg sync.WaitGroup

// Loop through each server and collect metrics
Expand Down

0 comments on commit cb5a12d

Please sign in to comment.