Created
March 29, 2014 17:34
-
-
Save jordanorelli/9858644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(DEV) user@host [database]> show slave status \G | |
*************************** 1. row *************************** | |
Slave_IO_State: Waiting for master to send event | |
Master_Host: host | |
Master_User: user | |
Master_Port: 3315 | |
Connect_Retry: 60 | |
Master_Log_File: filename-bin.000001 | |
Read_Master_Log_Pos: 1 | |
Relay_Log_File: filename-relay-bin.000004 | |
Relay_Log_Pos: 1 | |
Relay_Master_Log_File: source-bin.000002 | |
Slave_IO_Running: Yes | |
Slave_SQL_Running: Yes | |
Replicate_Do_DB: | |
Replicate_Ignore_DB: | |
Replicate_Do_Table: | |
Replicate_Ignore_Table: | |
Replicate_Wild_Do_Table: | |
Replicate_Wild_Ignore_Table: | |
Last_Errno: 0 | |
Last_Error: | |
Skip_Counter: 0 | |
Exec_Master_Log_Pos: 1 | |
Relay_Log_Space: 1 | |
Until_Condition: None | |
Until_Log_File: | |
Until_Log_Pos: 0 | |
Master_SSL_Allowed: No | |
Master_SSL_CA_File: | |
Master_SSL_CA_Path: | |
Master_SSL_Cert: | |
Master_SSL_Cipher: | |
Master_SSL_Key: | |
Seconds_Behind_Master: 0 | |
Master_SSL_Verify_Server_Cert: No | |
Last_IO_Errno: 0 | |
Last_IO_Error: | |
Last_SQL_Errno: 0 | |
Last_SQL_Error: | |
Replicate_Ignore_Server_Ids: | |
Master_Server_Id: 1 | |
1 row in set (0.00 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type SlaveStatus struct { | |
IOState string `sql:Slave_IO_State` | |
MasterHost string `sql:Master_Host` | |
SlaveIORunning string `sql:Slave_IO_Running` | |
SlaveSQLRunning string `sql:Slave_SQL_Running` | |
} | |
func read_slave_status(db *sql.DB) (*SlaveStatus, error) { | |
rows, err := db.Query("SHOW SLAVE STATUS") | |
if err != nil { | |
return nil, fmt.Errorf("unable to show slave status: %v", err) | |
} | |
defer rows.Close() | |
var s SlaveStatus | |
for rows.Next() { | |
if err := rows.Scan(&s); err != nil { | |
return nil, fmt.Errorf("unable to scan row: %v", err) | |
} | |
} | |
if err := rows.Err(); err != nil { | |
return nil, fmt.Errorf("error reading rows: %v", err) | |
} | |
return &s, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment