Skip to content

Commit d10615a

Browse files
authored
Add mariadb support (#669)
2 parents 002dda4 + da97955 commit d10615a

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

pkg/snapshot/mysql.go

+18-10
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ type MySQLProcesses []*MySQLProcess
3030

3131
// MySQLProcess represents the data returned from SHOW PROCESS LIST.
3232
type MySQLProcess struct {
33-
ID int64 `json:"id"`
34-
User string `json:"user"`
35-
Host string `json:"host"`
36-
DB NullString `json:"db"`
37-
Cmd string `json:"command"`
38-
Time int64 `json:"time"`
39-
State string `json:"state"`
40-
Info NullString `json:"info"`
33+
ID int64 `json:"id"`
34+
User string `json:"user"`
35+
Host string `json:"host"`
36+
DB NullString `json:"db"`
37+
Cmd string `json:"command"`
38+
Time int64 `json:"time"`
39+
State string `json:"state"`
40+
Info NullString `json:"info"`
41+
Progress float64 `json:"progress"` // mariadb
4142
}
4243

4344
type NullString struct {
@@ -137,8 +138,15 @@ func scanMySQLProcessList(ctx context.Context, dbase *sql.DB) (MySQLProcesses, e
137138

138139
for rows.Next() {
139140
var pid MySQLProcess
140-
// for each row, scan the result into our tag composite object
141-
err := rows.Scan(&pid.ID, &pid.User, &pid.Host, &pid.DB, &pid.Cmd, &pid.Time, &pid.State, &pid.Info)
141+
// for each row, scan the result into our tag composite object.
142+
if cols, _ := rows.Columns(); len(cols) == 8 {
143+
// mysql only has 8 columns
144+
err = rows.Scan(&pid.ID, &pid.User, &pid.Host, &pid.DB, &pid.Cmd, &pid.Time, &pid.State, &pid.Info)
145+
} else {
146+
// mariadb returns 9 columns (adds progress).
147+
err = rows.Scan(&pid.ID, &pid.User, &pid.Host, &pid.DB, &pid.Cmd, &pid.Time, &pid.State, &pid.Info, &pid.Progress)
148+
}
149+
142150
if err != nil {
143151
mnd.Apps.Add("MySQL&&Errors", 1)
144152
return nil, fmt.Errorf("scanning process rows: %w", err)

0 commit comments

Comments
 (0)