diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-06-09 10:04:55 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-06-09 10:04:55 +0300 |
commit | 4edb28548c028f788a5c08b0dda415ce4f6a01aa (patch) | |
tree | 60b44f00c5b2f6d7cb18cb700e43197b098edf0d /src/mysqlstat.c | |
parent | b1173f33f7d9e1c42371a5df7e21765861c74c4f (diff) | |
download | mysqlstat-4edb28548c028f788a5c08b0dda415ce4f6a01aa.tar.gz mysqlstat-4edb28548c028f788a5c08b0dda415ce4f6a01aa.tar.bz2 |
Implement master status MIB
Diffstat (limited to 'src/mysqlstat.c')
-rw-r--r-- | src/mysqlstat.c | 88 |
1 files changed, 85 insertions, 3 deletions
diff --git a/src/mysqlstat.c b/src/mysqlstat.c index 9d9975e..4eb5a18 100644 --- a/src/mysqlstat.c +++ b/src/mysqlstat.c @@ -272,12 +272,15 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent, } else if (STREQ(Master_SSL_Key, name)) { ASSIGN_STRING(ent, replMasterSSLKey, value); } else if (STREQ(Seconds_Behind_Master, name)) { ent->replSecondsBehindMaster = strtoul(value, NULL, 10) * 100; } else if (STREQ(Master_SSL_Verify_Server_Cert, name)) { ent->replMasterSSLVerifyServerCert = val_bool(value); + } else { + snmp_log(LOG_ERR, "unrecognized slave status column: %s\n", + name); } } int replSlaveStatusTable_load(netsnmp_cache *cache, void *vmagic) { @@ -363,12 +366,94 @@ replSlaveStatusTable_entry_free(void *data) free(ent->replMasterSSLCert); free(ent->replMasterSSLCipher); free(ent->replMasterSSLKey); } static void +store_master_status_row(struct replMasterStatusTable_entry *ent, + char const *name, char const *value) +{ + if (STREQ(File, name)) { + ASSIGN_STRING(ent, replMasterCurrentLogFile, value); + } else if (STREQ(Position, name)) { + ent->replMasterCurrentLogPos = strtoul(value, NULL, 10); + } else if (STREQ(Binlog_Do_DB, name)) { + ASSIGN_STRING(ent, replMasterBinlogDoDB, value); + } else if (STREQ(Binlog_Ignore_DB, name)) { + ASSIGN_STRING(ent, replMasterBinlogIgnoreDB, value); + } else { + snmp_log(LOG_ERR, "unrecognized master status column: %s\n", + name); + } +} + +int +replMasterStatusTable_load(netsnmp_cache *cache, void *vmagic) +{ + mysqlstat_connection_t conn; + MYSQL_RES *res; + MYSQL_ROW row; + MYSQL_FIELD *fields; + unsigned int num_fields, i; + netsnmp_tdata *table = (netsnmp_tdata *) vmagic; + struct replMasterStatusTable_entry *ent; + netsnmp_tdata_row *data_row; + + conn = mysqlstat_connect(); + if (!conn) + return SNMP_ERR_NOSUCHNAME; + + DEBUGMSGTL(("mysqlstat:sql", "Getting master status\n")); + if (mysql_query(&conn->mysql, "SHOW MASTER STATUS")) { + snmp_log(LOG_ERR, "can't get master status: %s\n", + mysql_error(&conn->mysql)); + return SNMP_ERR_NOSUCHNAME; + } + + res = mysql_store_result(&conn->mysql); + if (mysql_num_rows(res) < 1) + return 0; + + num_fields = mysql_num_fields(res); + fields = mysql_fetch_fields(res); + row = mysql_fetch_row(res); + + ent = SNMP_MALLOC_TYPEDEF(struct replMasterStatusTable_entry); + if (!ent) + return SNMP_ERR_GENERR; + + data_row = netsnmp_tdata_create_row(); + if (!data_row) { + SNMP_FREE(ent); + return SNMP_ERR_GENERR; + } + data_row->data = ent; + ent->replMasterIndex = 0; + netsnmp_tdata_row_add_index(data_row, ASN_INTEGER, + &ent->replMasterIndex, + sizeof(ent->replMasterIndex)); + + netsnmp_tdata_add_row(table, data_row); + + for (i = 0; i < num_fields; i++) + store_master_status_row(ent, fields[i].name, row[i]); + + mysql_free_result(res); + return 0; +} + +void +replMasterStatusTable_entry_free(void *data) +{ + struct replMasterStatusTable_entry *ent = data; + free(ent->replMasterCurrentLogFile); + free(ent->replMasterBinlogDoDB); + free(ent->replMasterBinlogIgnoreDB); +} + +static void process_list_add(netsnmp_tdata *table_data, long idx, MYSQL_ROW mysql_row) { struct processListTable_entry *ent; netsnmp_tdata_row *data_row; ent = SNMP_MALLOC_TYPEDEF(struct processListTable_entry); @@ -458,10 +543,7 @@ process_slave_count(void) return p->slaves; } - - - |