Add ability to handle 'binary logs' mySQL query with 3 columns, in case 3 columns are sent (MySQL 8 and greater) (#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
This commit is contained in:
parent
ef2def20dc
commit
14f428d2fd
|
|
@ -13,8 +13,8 @@ import (
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/common/tls"
|
"github.com/influxdata/telegraf/plugins/common/tls"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/mysql/v1"
|
v1 "github.com/influxdata/telegraf/plugins/inputs/mysql/v1"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/mysql/v2"
|
v2 "github.com/influxdata/telegraf/plugins/inputs/mysql/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Mysql struct {
|
type Mysql struct {
|
||||||
|
|
@ -711,17 +711,31 @@ func (m *Mysql) gatherBinaryLogs(db *sql.DB, serv string, acc telegraf.Accumulat
|
||||||
servtag := getDSNTag(serv)
|
servtag := getDSNTag(serv)
|
||||||
tags := map[string]string{"server": servtag}
|
tags := map[string]string{"server": servtag}
|
||||||
var (
|
var (
|
||||||
size uint64
|
size uint64
|
||||||
count uint64
|
count uint64
|
||||||
fileSize uint64
|
fileSize uint64
|
||||||
fileName string
|
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
|
// iterate over rows and count the size and count of files
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
if err := rows.Scan(&fileName, &fileSize); err != nil {
|
if numColumns == 3 {
|
||||||
return err
|
if err := rows.Scan(&fileName, &fileSize, &encrypted); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := rows.Scan(&fileName, &fileSize); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size += fileSize
|
size += fileSize
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
|
|
@ -729,6 +743,7 @@ func (m *Mysql) gatherBinaryLogs(db *sql.DB, serv string, acc telegraf.Accumulat
|
||||||
"binary_size_bytes": size,
|
"binary_size_bytes": size,
|
||||||
"binary_files_count": count,
|
"binary_files_count": count,
|
||||||
}
|
}
|
||||||
|
|
||||||
acc.AddFields("mysql", fields, tags)
|
acc.AddFields("mysql", fields, tags)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue