aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-06-09 10:04:55 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2016-06-09 10:04:55 +0300
commit4edb28548c028f788a5c08b0dda415ce4f6a01aa (patch)
tree60b44f00c5b2f6d7cb18cb700e43197b098edf0d /src
parentb1173f33f7d9e1c42371a5df7e21765861c74c4f (diff)
downloadmysqlstat-4edb28548c028f788a5c08b0dda415ce4f6a01aa.tar.gz
mysqlstat-4edb28548c028f788a5c08b0dda415ce4f6a01aa.tar.bz2
Implement master status MIB
Diffstat (limited to 'src')
-rw-r--r--src/MYSQL-STAT-MIB.txt79
-rw-r--r--src/mysqlstat.812
-rw-r--r--src/mysqlstat.c88
-rw-r--r--src/mysqlstat.mib2c47
4 files changed, 172 insertions, 54 deletions
diff --git a/src/MYSQL-STAT-MIB.txt b/src/MYSQL-STAT-MIB.txt
index 33bae3b..9efc19d 100644
--- a/src/MYSQL-STAT-MIB.txt
+++ b/src/MYSQL-STAT-MIB.txt
@@ -18,12 +18,12 @@ IMPORTS
18 FROM INET-ADDRESS-MIB; 18 FROM INET-ADDRESS-MIB;
19 19
20mysql MODULE-IDENTITY 20mysql MODULE-IDENTITY
21 LAST-UPDATED "201606071145Z" 21 LAST-UPDATED "201606090926Z"
22 ORGANIZATION "Gray Software" 22 ORGANIZATION "Gray Software"
23 CONTACT-INFO "Sergey Poznyakoff <gray@gnu.org>" 23 CONTACT-INFO "Sergey Poznyakoff <gray@gnu.org>"
24 DESCRIPTION 24 DESCRIPTION
25 "This MIB module defines objects for MySQL statistics." 25 "This MIB module defines objects for MySQL statistics."
26 REVISION "201606071145Z" 26 REVISION "201606090926Z"
27 DESCRIPTION 27 DESCRIPTION
28 "First revision." 28 "First revision."
29 ::= { enterprises 9163 102 } 29 ::= { enterprises 9163 102 }
@@ -69,7 +69,7 @@ ReplSlaveStatusEntry ::= SEQUENCE {
69 replLastIOErrno Integer32, 69 replLastIOErrno Integer32,
70 replLastIOError SQLErrorString, 70 replLastIOError SQLErrorString,
71 replExecMasterLogPos Counter32, 71 replExecMasterLogPos Counter32,
72 replRelayLogSpace Counter64, 72 replRelayLogSpace Gauge32,
73 replSecondsBehindMaster TimeStamp, 73 replSecondsBehindMaster TimeStamp,
74 replMasterHost DisplayString, 74 replMasterHost DisplayString,
75 replMasterUser DisplayString, 75 replMasterUser DisplayString,
@@ -81,7 +81,7 @@ ReplSlaveStatusEntry ::= SEQUENCE {
81 replReplicateIgnoreTable DisplayString, 81 replReplicateIgnoreTable DisplayString,
82 replReplicateWildDoTable DisplayString, 82 replReplicateWildDoTable DisplayString,
83 replReplicateWildIgnoreTable DisplayString, 83 replReplicateWildIgnoreTable DisplayString,
84 replSkipCounter Counter32, 84 replSkipCounter Gauge32,
85 replUntilCondition DisplayString, 85 replUntilCondition DisplayString,
86 replUntilLogFile DisplayString, 86 replUntilLogFile DisplayString,
87 replUntilLogPos DisplayString, 87 replUntilLogPos DisplayString,
@@ -461,6 +461,77 @@ replMasterSSLVerifyServerCert OBJECT-TYPE
461 ::= { replSlaveStatusEntry 38 } 461 ::= { replSlaveStatusEntry 38 }
462 462
463-- 463--
464-- Replication master status
465--
466
467replMasterStatusTable OBJECT-TYPE
468 SYNTAX SEQUENCE OF ReplMasterStatusEntry
469 MAX-ACCESS not-accessible
470 STATUS current
471 DESCRIPTION
472 "A table of replication master status. On replication master,
473 it contains a single row, describing the current
474 status."
475 ::= { replication 2 }
476
477replMasterStatusEntry OBJECT-TYPE
478 SYNTAX ReplMasterStatusEntry
479 MAX-ACCESS not-accessible
480 STATUS current
481 DESCRIPTION
482 "An entry describing master status."
483 INDEX { replMasterIndex }
484 ::= { replMasterStatusTable 1 }
485
486ReplMasterStatusEntry ::= SEQUENCE {
487 replMasterIndex Integer32,
488 replMasterCurrentLogFile DisplayString,
489 replMasterCurrentLogPos Counter32,
490 replMasterBinlogDoDB DisplayString,
491 replMasterBinlogIgnoreDB DisplayString
492}
493
494replMasterIndex OBJECT-TYPE
495 SYNTAX Integer32 (0..65535)
496 MAX-ACCESS not-accessible
497 STATUS current
498 DESCRIPTION
499 "A number uniquely identifying master status row."
500 ::= { replMasterStatusEntry 1 }
501
502replMasterCurrentLogFile OBJECT-TYPE
503 SYNTAX DisplayString
504 MAX-ACCESS read-only
505 STATUS current
506 DESCRIPTION
507 "The name of the master binary log file."
508 ::= { replMasterStatusEntry 2 }
509
510replMasterCurrentLogPos OBJECT-TYPE
511 SYNTAX Counter32
512 MAX-ACCESS read-only
513 STATUS current
514 DESCRIPTION
515 "The position in the current master binary log file."
516 ::= { replMasterStatusEntry 3 }
517
518replMasterBinlogDoDB OBJECT-TYPE
519 SYNTAX DisplayString
520 MAX-ACCESS read-only
521 STATUS current
522 DESCRIPTION
523 "The list of database names to include in the binlog."
524 ::= { replMasterStatusEntry 4 }
525
526replMasterBinlogIgnoreDB OBJECT-TYPE
527 SYNTAX DisplayString
528 MAX-ACCESS read-only
529 STATUS current
530 DESCRIPTION
531 "The list of database names to exclude from the binlog."
532 ::= { replMasterStatusEntry 5 }
533
534--
464-- Process List 535-- Process List
465-- 536--
466 537
diff --git a/src/mysqlstat.8 b/src/mysqlstat.8
index f79e9cf..e0bcb7f 100644
--- a/src/mysqlstat.8
+++ b/src/mysqlstat.8
@@ -48,6 +48,18 @@ privileges.
48To configure the module, it is recommended to use the 48To configure the module, it is recommended to use the
49.BR mysqlstat\-setup (1) 49.BR mysqlstat\-setup (1)
50utility. 50utility.
51.SS Caching
52In order to minimize its impact on MySQL server, the
53.B mysqlstat
54module caches the data obtained from the server. Default caching
55interval is 10 seconds for tabular information. Additionally, results
56of each
57.B SHOW PROCESSLIST
58are cached for 10 seconds. This means that updates of
59.B processListTable
60entries may delay for up to 20 seconds.
61.PP
62As of version 1.0, these delays are not configurable.
51.SH CONFIGURATION 63.SH CONFIGURATION
52MySQL credentials are read from file 64MySQL credentials are read from file
53.BR /etc/snmp/mysqlstat.cnf . 65.BR /etc/snmp/mysqlstat.cnf .
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,
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
@@ -366,6 +369,88 @@ replSlaveStatusTable_entry_free(void *data)
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