Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
fix(mysql): add a dimensions per Galera cluster state/status (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Aug 22, 2022
1 parent faa01a2 commit 861be1e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 29 deletions.
11 changes: 9 additions & 2 deletions modules/mysql/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,9 @@ var (
Ctx: "mysql.galera_cluster_status",
Priority: prioGaleraClusterStatus,
Dims: module.Dims{
{ID: "wsrep_cluster_status", Name: "status"},
{ID: "wsrep_cluster_status_primary", Name: "primary"},
{ID: "wsrep_cluster_status_non_primary", Name: "non_primary"},
{ID: "wsrep_cluster_status_disconnected", Name: "disconnected"},
},
}
chartGaleraClusterState = module.Chart{
Expand All @@ -767,7 +769,12 @@ var (
Ctx: "mysql.galera_cluster_state",
Priority: prioGaleraClusterState,
Dims: module.Dims{
{ID: "wsrep_local_state", Name: "state"},
{ID: "wsrep_local_state_undefined", Name: "undefined"},
{ID: "wsrep_local_state_joiner", Name: "joining"},
{ID: "wsrep_local_state_donor", Name: "donor"},
{ID: "wsrep_local_state_joined", Name: "joined"},
{ID: "wsrep_local_state_synced", Name: "synced"},
{ID: "wsrep_local_state_error", Name: "error"},
},
}
chartGaleraClusterSize = module.Chart{
Expand Down
43 changes: 22 additions & 21 deletions modules/mysql/collect_global_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,26 @@ func (m *MySQL) collectGlobalStatus(mx map[string]int64) error {
}
switch name {
case "wsrep_connected":
mx[strings.ToLower(name)] = parseInt(convertWsrepConnected(value))
mx[name] = parseInt(convertWsrepConnected(value))
case "wsrep_ready":
mx[strings.ToLower(name)] = parseInt(convertWsrepReady(value))
mx[name] = parseInt(convertWsrepReady(value))
case "wsrep_local_state":
// https://mariadb.com/kb/en/galera-cluster-status-variables/#wsrep_local_state
// https://github.com/codership/wsrep-API/blob/eab2d5d5a31672c0b7d116ef1629ff18392fd7d0/wsrep_api.h#L256
mx[name+"_undefined"] = boolToInt(value == "0")
mx[name+"_joiner"] = boolToInt(value == "1")
mx[name+"_donor"] = boolToInt(value == "2")
mx[name+"_joined"] = boolToInt(value == "3")
mx[name+"_synced"] = boolToInt(value == "4")
mx[name+"_error"] = boolToInt(value == "5")
case "wsrep_cluster_status":
mx[strings.ToLower(name)] = parseInt(convertWsrepClusterStatus(value))
// https://www.percona.com/doc/percona-xtradb-cluster/LATEST/wsrep-status-index.html#wsrep_cluster_status
// https://github.com/codership/wsrep-API/blob/eab2d5d5a31672c0b7d116ef1629ff18392fd7d0/wsrep_api.h
// https://github.com/codership/wsrep-API/blob/f71cd270414ee70dde839cfc59c1731eea4230ea/examples/node/wsrep.c#L80
value = strings.ToUpper(value)
mx[name+"_primary"] = boolToInt(value == "PRIMARY")
mx[name+"_non_primary"] = boolToInt(value == "NON-PRIMARY")
mx[name+"_disconnected"] = boolToInt(value == "DISCONNECTED")
default:
mx[strings.ToLower(name)] = parseInt(value)
}
Expand Down Expand Up @@ -62,25 +77,11 @@ func convertWsrepReady(val string) string {
}
}

func convertWsrepClusterStatus(val string) string {
// https://www.percona.com/doc/percona-xtradb-cluster/LATEST/wsrep-status-index.html#wsrep_cluster_status
// https://github.com/codership/wsrep-API/blob/eab2d5d5a31672c0b7d116ef1629ff18392fd7d0/wsrep_api.h
// typedef enum wsrep_view_status {
// WSREP_VIEW_PRIMARY, //!< primary group configuration (quorum present)
// WSREP_VIEW_NON_PRIMARY, //!< non-primary group configuration (quorum lost)
// WSREP_VIEW_DISCONNECTED, //!< not connected to group, retrying.
// WSREP_VIEW_MAX
// } wsrep_view_status_t;
switch strings.ToUpper(val) {
case "PRIMARY":
return "0"
case "NON-PRIMARY":
return "1"
case "DISCONNECTED":
return "2"
default:
return "-1"
func boolToInt(v bool) int64 {
if v {
return 1
}
return 0
}

var globalStatusKeys = map[string]bool{
Expand Down
27 changes: 21 additions & 6 deletions modules/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,9 @@ func TestMySQL_Collect(t *testing.T) {
"userstats_root_total_connections": 1,
"userstats_root_update_commands": 0,
"wsrep_cluster_size": 0,
"wsrep_cluster_status": 2,
"wsrep_cluster_status_disconnected": 1,
"wsrep_cluster_status_non_primary": 0,
"wsrep_cluster_status_primary": 0,
"wsrep_connected": 0,
"wsrep_local_bf_aborts": 0,
"wsrep_ready": 0,
Expand Down Expand Up @@ -726,7 +728,9 @@ func TestMySQL_Collect(t *testing.T) {
"userstats_root_total_connections": 1,
"userstats_root_update_commands": 0,
"wsrep_cluster_size": 0,
"wsrep_cluster_status": 2,
"wsrep_cluster_status_disconnected": 1,
"wsrep_cluster_status_non_primary": 0,
"wsrep_cluster_status_primary": 0,
"wsrep_connected": 0,
"wsrep_local_bf_aborts": 0,
"wsrep_ready": 0,
Expand Down Expand Up @@ -907,7 +911,9 @@ func TestMySQL_Collect(t *testing.T) {
"userstats_root_total_connections": 1,
"userstats_root_update_commands": 0,
"wsrep_cluster_size": 0,
"wsrep_cluster_status": 2,
"wsrep_cluster_status_disconnected": 1,
"wsrep_cluster_status_non_primary": 0,
"wsrep_cluster_status_primary": 0,
"wsrep_connected": 0,
"wsrep_local_bf_aborts": 0,
"wsrep_ready": 0,
Expand Down Expand Up @@ -1082,7 +1088,9 @@ func TestMySQL_Collect(t *testing.T) {
"userstats_root_total_connections": 1,
"userstats_root_update_commands": 0,
"wsrep_cluster_size": 0,
"wsrep_cluster_status": 2,
"wsrep_cluster_status_disconnected": 1,
"wsrep_cluster_status_non_primary": 0,
"wsrep_cluster_status_primary": 0,
"wsrep_connected": 0,
"wsrep_local_bf_aborts": 0,
"wsrep_ready": 0,
Expand Down Expand Up @@ -1257,15 +1265,22 @@ func TestMySQL_Collect(t *testing.T) {
"userstats_root_total_connections": 1,
"userstats_root_update_commands": 0,
"wsrep_cluster_size": 3,
"wsrep_cluster_status": 0,
"wsrep_cluster_status_disconnected": 0,
"wsrep_cluster_status_non_primary": 0,
"wsrep_cluster_status_primary": 1,
"wsrep_cluster_weight": 3,
"wsrep_connected": 1,
"wsrep_flow_control_paused_ns": 0,
"wsrep_local_bf_aborts": 0,
"wsrep_local_cert_failures": 0,
"wsrep_local_recv_queue": 0,
"wsrep_local_send_queue": 0,
"wsrep_local_state": 4,
"wsrep_local_state_donor": 0,
"wsrep_local_state_error": 0,
"wsrep_local_state_joined": 0,
"wsrep_local_state_joiner": 0,
"wsrep_local_state_synced": 1,
"wsrep_local_state_undefined": 0,
"wsrep_open_transactions": 0,
"wsrep_ready": 1,
"wsrep_received": 11,
Expand Down

0 comments on commit 861be1e

Please sign in to comment.