Skip to content

Commit

Permalink
Add ability to handle 'binary logs' mySQL query with 3 columns, in ca…
Browse files Browse the repository at this point in the history
…se 3 columns are sent (MySQL 8 and greater) (influxdata#9082)

* Add ability to handle 'binary logs' mySQL query with 3 columns, in case 3 columns are sent (MySQL 8 and greater)

* Update mysql.go

* Update mysql.go
  • Loading branch information
ivorybilled authored Apr 6, 2021
1 parent ef2def2 commit 14f428d
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions plugins/inputs/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/common/tls"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/telegraf/plugins/inputs/mysql/v1"
"github.com/influxdata/telegraf/plugins/inputs/mysql/v2"
v1 "github.com/influxdata/telegraf/plugins/inputs/mysql/v1"
v2 "github.com/influxdata/telegraf/plugins/inputs/mysql/v2"
)

type Mysql struct {
Expand Down Expand Up @@ -711,24 +711,39 @@ func (m *Mysql) gatherBinaryLogs(db *sql.DB, serv string, acc telegraf.Accumulat
servtag := getDSNTag(serv)
tags := map[string]string{"server": servtag}
var (
size uint64
count uint64
fileSize uint64
fileName string
size uint64
count uint64
fileSize uint64
fileName string
encrypted string
)

columns, err := rows.Columns()
if err != nil {
return err
}
numColumns := len(columns)

// iterate over rows and count the size and count of files
for rows.Next() {
if err := rows.Scan(&fileName, &fileSize); err != nil {
return err
if numColumns == 3 {
if err := rows.Scan(&fileName, &fileSize, &encrypted); err != nil {
return err
}
} else {
if err := rows.Scan(&fileName, &fileSize); err != nil {
return err
}
}

size += fileSize
count++
}
fields := map[string]interface{}{
"binary_size_bytes": size,
"binary_files_count": count,
}

acc.AddFields("mysql", fields, tags)
return nil
}
Expand Down

0 comments on commit 14f428d

Please sign in to comment.