Skip to content

Commit

Permalink
Fix inconsistent metric types in mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
fxedel committed Jun 21, 2021
1 parent 1ba865f commit e7bea1b
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions plugins/inputs/mysql/v2/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func ParseInt(value sql.RawBytes) (interface{}, error) {
return v, err
}

func ParseUint(value sql.RawBytes) (interface{}, error) {
return strconv.ParseUint(string(value), 10, 64)
}

func ParseBoolAsInteger(value sql.RawBytes) (interface{}, error) {
if bytes.EqualFold(value, []byte("YES")) || bytes.EqualFold(value, []byte("ON")) {
return int64(1), nil
Expand All @@ -29,6 +33,10 @@ func ParseBoolAsInteger(value sql.RawBytes) (interface{}, error) {
return int64(0), nil
}

func ParseString(value sql.RawBytes) (interface{}, error) {
return string(value), nil
}

func ParseGTIDMode(value sql.RawBytes) (interface{}, error) {
// https://dev.mysql.com/doc/refman/8.0/en/replication-mode-change-online-concepts.html
v := string(value)
Expand Down Expand Up @@ -70,12 +78,27 @@ func ParseValue(value sql.RawBytes) (interface{}, error) {
}

var GlobalStatusConversions = map[string]ConversionFunc{
"ssl_ctx_verify_depth": ParseInt,
"ssl_verify_depth": ParseInt,
"innodb_available_undo_logs": ParseUint,
"innodb_buffer_pool_pages_misc": ParseUint,
"innodb_data_pending_fsyncs": ParseUint,
"ssl_ctx_verify_depth": ParseUint,
"ssl_verify_depth": ParseUint,
}

var GlobalVariableConversions = map[string]ConversionFunc{
"gtid_mode": ParseGTIDMode,
"delay_key_write": ParseString, // ON, OFF, ALL
"enforce_gtid_consistency": ParseString, // ON, OFF, WARN
"event_scheduler": ParseBoolAsInteger, // YES, NO, DISABLED
"gtid_mode": ParseGTIDMode,
"have_openssl": ParseBoolAsInteger, // alias for have_ssl
"have_ssl": ParseBoolAsInteger, // YES, DISABLED
"have_symlink": ParseBoolAsInteger, // YES, NO, DISABLED
"session_track_gtids": ParseString,
"session_track_transaction_info": ParseString,
"slave_skip_errors": ParseString,
"ssl_fips_mode": ParseString,
"transaction_write_set_extraction": ParseString,
"use_secondary_engine": ParseString,
}

func ConvertGlobalStatus(key string, value sql.RawBytes) (interface{}, error) {
Expand Down

0 comments on commit e7bea1b

Please sign in to comment.