Skip to content

Commit d028ec3

Browse files
benhymansMathieu Lecarme
authored and
Mathieu Lecarme
committed
Add option to control collecting global variables to mysql input (influxdata#6790)
1 parent f1860fa commit d028ec3

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

plugins/inputs/mysql/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ This plugin gathers the statistic data from MySQL server
6969
## gather metrics from SHOW BINARY LOGS command output
7070
# gather_binary_logs = false
7171

72+
## gather metrics from SHOW GLOBAL VARIABLES command output
73+
# gather_global_variables = true
74+
7275
## gather metrics from PERFORMANCE_SCHEMA.TABLE_IO_WAITS_SUMMARY_BY_TABLE
7376
# gather_table_io_waits = false
7477

plugins/inputs/mysql/mysql.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Mysql struct {
3636
GatherTableSchema bool `toml:"gather_table_schema"`
3737
GatherFileEventsStats bool `toml:"gather_file_events_stats"`
3838
GatherPerfEventsStatements bool `toml:"gather_perf_events_statements"`
39+
GatherGlobalVars bool `toml:"gather_global_variables"`
3940
IntervalSlow string `toml:"interval_slow"`
4041
MetricVersion int `toml:"metric_version"`
4142

@@ -94,6 +95,9 @@ const sampleConfig = `
9495
## gather metrics from SHOW BINARY LOGS command output
9596
# gather_binary_logs = false
9697
98+
## gather metrics from PERFORMANCE_SCHEMA.GLOBAL_VARIABLES
99+
# gather_global_variables = true
100+
97101
## gather metrics from PERFORMANCE_SCHEMA.TABLE_IO_WAITS_SUMMARY_BY_TABLE
98102
# gather_table_io_waits = false
99103
@@ -134,6 +138,7 @@ const (
134138
defaultPerfEventsStatementsDigestTextLimit = 120
135139
defaultPerfEventsStatementsLimit = 250
136140
defaultPerfEventsStatementsTimeLimit = 86400
141+
defaultGatherGlobalVars = true
137142
)
138143

139144
func (m *Mysql) SampleConfig() string {
@@ -431,14 +436,16 @@ func (m *Mysql) gatherServer(serv string, acc telegraf.Accumulator) error {
431436
return err
432437
}
433438

434-
// Global Variables may be gathered less often
435-
if len(m.IntervalSlow) > 0 {
436-
if uint32(time.Since(m.lastT).Seconds()) >= m.scanIntervalSlow {
437-
err = m.gatherGlobalVariables(db, serv, acc)
438-
if err != nil {
439-
return err
439+
if m.GatherGlobalVars {
440+
// Global Variables may be gathered less often
441+
if len(m.IntervalSlow) > 0 {
442+
if uint32(time.Since(m.lastT).Seconds()) >= m.scanIntervalSlow {
443+
err = m.gatherGlobalVariables(db, serv, acc)
444+
if err != nil {
445+
return err
446+
}
447+
m.lastT = time.Now()
440448
}
441-
m.lastT = time.Now()
442449
}
443450
}
444451

@@ -1767,6 +1774,7 @@ func init() {
17671774
PerfEventsStatementsDigestTextLimit: defaultPerfEventsStatementsDigestTextLimit,
17681775
PerfEventsStatementsLimit: defaultPerfEventsStatementsLimit,
17691776
PerfEventsStatementsTimeLimit: defaultPerfEventsStatementsTimeLimit,
1777+
GatherGlobalVars: defaultGatherGlobalVars,
17701778
}
17711779
})
17721780
}

0 commit comments

Comments
 (0)