in plugins/inputs/mysql/mysql.go [1301:1427]
func (m *Mysql) gatherPerfTableLockWaits(db *sql.DB, serv string, acc telegraf.Accumulator) error {
// check if table exists,
// if performance_schema is not enabled, tables do not exist
// then there is no need to scan them
var tableName string
err := db.QueryRow(perfSchemaTablesQuery, "table_lock_waits_summary_by_table").Scan(&tableName)
switch {
case err == sql.ErrNoRows:
return nil
case err != nil:
return err
}
rows, err := db.Query(perfTableLockWaitsQuery)
if err != nil {
return err
}
defer rows.Close()
servtag := getDSNTag(serv)
var (
objectSchema string
objectName string
countReadNormal float64
countReadWithSharedLocks float64
countReadHighPriority float64
countReadNoInsert float64
countReadExternal float64
countWriteAllowWrite float64
countWriteConcurrentInsert float64
countWriteLowPriority float64
countWriteNormal float64
countWriteExternal float64
timeReadNormal float64
timeReadWithSharedLocks float64
timeReadHighPriority float64
timeReadNoInsert float64
timeReadExternal float64
timeWriteAllowWrite float64
timeWriteConcurrentInsert float64
timeWriteLowPriority float64
timeWriteNormal float64
timeWriteExternal float64
)
for rows.Next() {
err = rows.Scan(
&objectSchema,
&objectName,
&countReadNormal,
&countReadWithSharedLocks,
&countReadHighPriority,
&countReadNoInsert,
&countReadExternal,
&countWriteAllowWrite,
&countWriteConcurrentInsert,
&countWriteLowPriority,
&countWriteNormal,
&countWriteExternal,
&timeReadNormal,
&timeReadWithSharedLocks,
&timeReadHighPriority,
&timeReadNoInsert,
&timeReadExternal,
&timeWriteAllowWrite,
&timeWriteConcurrentInsert,
&timeWriteLowPriority,
&timeWriteNormal,
&timeWriteExternal,
)
if err != nil {
return err
}
tags := map[string]string{
"server": servtag,
"schema": objectSchema,
"table": objectName,
}
sqlLWTags := copyTags(tags)
sqlLWTags["perf_query"] = "sql_lock_waits_total"
sqlLWFields := map[string]interface{}{
"read_normal": countReadNormal,
"read_with_shared_locks": countReadWithSharedLocks,
"read_high_priority": countReadHighPriority,
"read_no_insert": countReadNoInsert,
"write_normal": countWriteNormal,
"write_allow_write": countWriteAllowWrite,
"write_concurrent_insert": countWriteConcurrentInsert,
"write_low_priority": countWriteLowPriority,
}
acc.AddFields("mysql_perf_schema", sqlLWFields, sqlLWTags)
externalLWTags := copyTags(tags)
externalLWTags["perf_query"] = "external_lock_waits_total"
externalLWFields := map[string]interface{}{
"read": countReadExternal,
"write": countWriteExternal,
}
acc.AddFields("mysql_perf_schema", externalLWFields, externalLWTags)
sqlLWSecTotalTags := copyTags(tags)
sqlLWSecTotalTags["perf_query"] = "sql_lock_waits_seconds_total"
sqlLWSecTotalFields := map[string]interface{}{
"read_normal": timeReadNormal / picoSeconds,
"read_with_shared_locks": timeReadWithSharedLocks / picoSeconds,
"read_high_priority": timeReadHighPriority / picoSeconds,
"read_no_insert": timeReadNoInsert / picoSeconds,
"write_normal": timeWriteNormal / picoSeconds,
"write_allow_write": timeWriteAllowWrite / picoSeconds,
"write_concurrent_insert": timeWriteConcurrentInsert / picoSeconds,
"write_low_priority": timeWriteLowPriority / picoSeconds,
}
acc.AddFields("mysql_perf_schema", sqlLWSecTotalFields, sqlLWSecTotalTags)
externalLWSecTotalTags := copyTags(tags)
externalLWSecTotalTags["perf_query"] = "external_lock_waits_seconds_total"
externalLWSecTotalFields := map[string]interface{}{
"read": timeReadExternal / picoSeconds,
"write": timeWriteExternal / picoSeconds,
}
acc.AddFields("mysql_perf_schema", externalLWSecTotalFields, externalLWSecTotalTags)
}
return nil
}