aboutsummaryrefslogtreecommitdiff
path: root/src/mysqlstat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mysqlstat.c')
-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
@@ -272,12 +272,15 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent,
272 } else if (STREQ(Master_SSL_Key, name)) { 272 } else if (STREQ(Master_SSL_Key, name)) {
273 ASSIGN_STRING(ent, replMasterSSLKey, value); 273 ASSIGN_STRING(ent, replMasterSSLKey, value);
274 } else if (STREQ(Seconds_Behind_Master, name)) { 274 } else if (STREQ(Seconds_Behind_Master, name)) {
275 ent->replSecondsBehindMaster = strtoul(value, NULL, 10) * 100; 275 ent->replSecondsBehindMaster = strtoul(value, NULL, 10) * 100;
276 } else if (STREQ(Master_SSL_Verify_Server_Cert, name)) { 276 } else if (STREQ(Master_SSL_Verify_Server_Cert, name)) {
277 ent->replMasterSSLVerifyServerCert = val_bool(value); 277 ent->replMasterSSLVerifyServerCert = val_bool(value);
278 } else {
279 snmp_log(LOG_ERR, "unrecognized slave status column: %s\n",
280 name);
278 } 281 }
279} 282}
280 283
281int 284int
282replSlaveStatusTable_load(netsnmp_cache *cache, void *vmagic) 285replSlaveStatusTable_load(netsnmp_cache *cache, void *vmagic)
283{ 286{
@@ -363,12 +366,94 @@ replSlaveStatusTable_entry_free(void *data)
363 free(ent->replMasterSSLCert); 366 free(ent->replMasterSSLCert);
364 free(ent->replMasterSSLCipher); 367 free(ent->replMasterSSLCipher);
365 free(ent->replMasterSSLKey); 368 free(ent->replMasterSSLKey);
366} 369}
367 370
368static void 371static void
372store_master_status_row(struct replMasterStatusTable_entry *ent,
373 char const *name, char const *value)
374{
375 if (STREQ(File, name)) {
376 ASSIGN_STRING(ent, replMasterCurrentLogFile, value);
377 } else if (STREQ(Position, name)) {
378 ent->replMasterCurrentLogPos = strtoul(value, NULL, 10);
379 } else if (STREQ(Binlog_Do_DB, name)) {
380 ASSIGN_STRING(ent, replMasterBinlogDoDB, value);
381 } else if (STREQ(Binlog_Ignore_DB, name)) {
382 ASSIGN_STRING(ent, replMasterBinlogIgnoreDB, value);
383 } else {
384 snmp_log(LOG_ERR, "unrecognized master status column: %s\n",
385 name);
386 }
387}
388
389int
390replMasterStatusTable_load(netsnmp_cache *cache, void *vmagic)
391{
392 mysqlstat_connection_t conn;
393 MYSQL_RES *res;
394 MYSQL_ROW row;
395 MYSQL_FIELD *fields;
396 unsigned int num_fields, i;
397 netsnmp_tdata *table = (netsnmp_tdata *) vmagic;
398 struct replMasterStatusTable_entry *ent;
399 netsnmp_tdata_row *data_row;
400
401 conn = mysqlstat_connect();
402 if (!conn)
403 return SNMP_ERR_NOSUCHNAME;
404
405 DEBUGMSGTL(("mysqlstat:sql", "Getting master status\n"));
406 if (mysql_query(&conn->mysql, "SHOW MASTER STATUS")) {
407 snmp_log(LOG_ERR, "can't get master status: %s\n",
408 mysql_error(&conn->mysql));
409 return SNMP_ERR_NOSUCHNAME;
410 }
411
412 res = mysql_store_result(&conn->mysql);
413 if (mysql_num_rows(res) < 1)
414 return 0;
415
416 num_fields = mysql_num_fields(res);
417 fields = mysql_fetch_fields(res);
418 row = mysql_fetch_row(res);
419
420 ent = SNMP_MALLOC_TYPEDEF(struct replMasterStatusTable_entry);
421 if (!ent)
422 return SNMP_ERR_GENERR;
423
424 data_row = netsnmp_tdata_create_row();
425 if (!data_row) {
426 SNMP_FREE(ent);
427 return SNMP_ERR_GENERR;
428 }
429 data_row->data = ent;
430 ent->replMasterIndex = 0;
431 netsnmp_tdata_row_add_index(data_row, ASN_INTEGER,
432 &ent->replMasterIndex,
433 sizeof(ent->replMasterIndex));
434
435 netsnmp_tdata_add_row(table, data_row);
436
437 for (i = 0; i < num_fields; i++)
438 store_master_status_row(ent, fields[i].name, row[i]);
439
440 mysql_free_result(res);
441 return 0;
442}
443
444void
445replMasterStatusTable_entry_free(void *data)
446{
447 struct replMasterStatusTable_entry *ent = data;
448 free(ent->replMasterCurrentLogFile);
449 free(ent->replMasterBinlogDoDB);
450 free(ent->replMasterBinlogIgnoreDB);
451}
452
453static void
369process_list_add(netsnmp_tdata *table_data, long idx, MYSQL_ROW mysql_row) 454process_list_add(netsnmp_tdata *table_data, long idx, MYSQL_ROW mysql_row)
370{ 455{
371 struct processListTable_entry *ent; 456 struct processListTable_entry *ent;
372 netsnmp_tdata_row *data_row; 457 netsnmp_tdata_row *data_row;
373 458
374 ent = SNMP_MALLOC_TYPEDEF(struct processListTable_entry); 459 ent = SNMP_MALLOC_TYPEDEF(struct processListTable_entry);
@@ -458,10 +543,7 @@ process_slave_count(void)
458 return p->slaves; 543 return p->slaves;
459} 544}
460 545
461 546
462 547
463 548
464
465
466
467 549

Return to:

Send suggestions and report system problems to the System administrator.