summaryrefslogtreecommitdiffabout
path: root/src/mysqlstat.c
Side-by-side diff
Diffstat (limited to 'src/mysqlstat.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/mysqlstat.c88
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
@@ -275,6 +275,9 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent,
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);
}
}
@@ -366,6 +369,88 @@ replSlaveStatusTable_entry_free(void *data)
}
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;
@@ -461,7 +546,4 @@ process_slave_count(void)
-
-
-

Return to:

Send suggestions and report system problems to the System administrator.