@@ -14,6 +14,7 @@ import (
1414 "github.com/influxdata/telegraf/internal/tls"
1515 "github.com/influxdata/telegraf/plugins/inputs"
1616 "github.com/influxdata/telegraf/plugins/inputs/mysql/v1"
17+ "github.com/influxdata/telegraf/plugins/inputs/mysql/v2"
1718)
1819
1920type Mysql struct {
@@ -37,6 +38,8 @@ type Mysql struct {
3738 GatherPerfEventsStatements bool `toml:"gather_perf_events_statements"`
3839 IntervalSlow string `toml:"interval_slow"`
3940 MetricVersion int `toml:"metric_version"`
41+
42+ Log telegraf.Logger `toml:"-"`
4043 tls.ClientConfig
4144 lastT time.Time
4245 initDone bool
@@ -554,14 +557,20 @@ func (m *Mysql) gatherGlobalVariables(db *sql.DB, serv string, acc telegraf.Accu
554557 return err
555558 }
556559 key = strings .ToLower (key )
560+
557561 // parse mysql version and put into field and tag
558562 if strings .Contains (key , "version" ) {
559563 fields [key ] = string (val )
560564 tags [key ] = string (val )
561565 }
562- if value , ok := m .parseValue (val ); ok {
566+
567+ value , err := m .parseGlobalVariables (key , val )
568+ if err != nil {
569+ m .Log .Debugf ("Error parsing global variable %q: %v" , key , err )
570+ } else {
563571 fields [key ] = value
564572 }
573+
565574 // Send 20 fields at a time
566575 if len (fields ) >= 20 {
567576 acc .AddFields ("mysql_variables" , fields , tags )
@@ -575,6 +584,18 @@ func (m *Mysql) gatherGlobalVariables(db *sql.DB, serv string, acc telegraf.Accu
575584 return nil
576585}
577586
587+ func (m * Mysql ) parseGlobalVariables (key string , value sql.RawBytes ) (interface {}, error ) {
588+ if m .MetricVersion < 2 {
589+ v , ok := v1 .ParseValue (value )
590+ if ok {
591+ return v , nil
592+ }
593+ return v , fmt .Errorf ("could not parse value: %q" , string (value ))
594+ } else {
595+ return v2 .ConvertGlobalVariables (key , value )
596+ }
597+ }
598+
578599// gatherSlaveStatuses can be used to get replication analytics
579600// When the server is slave, then it returns only one row.
580601// If the multi-source replication is set, then everything works differently
@@ -748,7 +769,10 @@ func (m *Mysql) gatherGlobalStatuses(db *sql.DB, serv string, acc telegraf.Accum
748769 }
749770 } else {
750771 key = strings .ToLower (key )
751- if value , ok := m .parseValue (val ); ok {
772+ value , err := v2 .ConvertGlobalStatus (key , val )
773+ if err != nil {
774+ m .Log .Debugf ("Error parsing global status: %v" , err )
775+ } else {
752776 fields [key ] = value
753777 }
754778 }
0 commit comments