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 | |
parent | b1173f33f7d9e1c42371a5df7e21765861c74c4f (diff) | |
download | mysqlstat-4edb28548c028f788a5c08b0dda415ce4f6a01aa.tar.gz mysqlstat-4edb28548c028f788a5c08b0dda415ce4f6a01aa.tar.bz2 |
Implement master status MIB
-rw-r--r-- | src/MYSQL-STAT-MIB.txt | 79 | ||||
-rw-r--r-- | src/mysqlstat.8 | 12 | ||||
-rw-r--r-- | src/mysqlstat.c | 88 | ||||
-rw-r--r-- | src/mysqlstat.mib2c | 47 |
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 | |||
@@ -20,3 +20,3 @@ IMPORTS | |||
20 | mysql MODULE-IDENTITY | 20 | mysql MODULE-IDENTITY |
21 | LAST-UPDATED "201606071145Z" | 21 | LAST-UPDATED "201606090926Z" |
22 | ORGANIZATION "Gray Software" | 22 | ORGANIZATION "Gray Software" |
@@ -25,3 +25,3 @@ mysql MODULE-IDENTITY | |||
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 |
@@ -71,3 +71,3 @@ ReplSlaveStatusEntry ::= SEQUENCE { | |||
71 | replExecMasterLogPos Counter32, | 71 | replExecMasterLogPos Counter32, |
72 | replRelayLogSpace Counter64, | 72 | replRelayLogSpace Gauge32, |
73 | replSecondsBehindMaster TimeStamp, | 73 | replSecondsBehindMaster TimeStamp, |
@@ -83,3 +83,3 @@ ReplSlaveStatusEntry ::= SEQUENCE { | |||
83 | replReplicateWildIgnoreTable DisplayString, | 83 | replReplicateWildIgnoreTable DisplayString, |
84 | replSkipCounter Counter32, | 84 | replSkipCounter Gauge32, |
85 | replUntilCondition DisplayString, | 85 | replUntilCondition DisplayString, |
@@ -463,2 +463,73 @@ replMasterSSLVerifyServerCert OBJECT-TYPE | |||
463 | -- | 463 | -- |
464 | -- Replication master status | ||
465 | -- | ||
466 | |||
467 | replMasterStatusTable 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 | |||
477 | replMasterStatusEntry 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 | |||
486 | ReplMasterStatusEntry ::= SEQUENCE { | ||
487 | replMasterIndex Integer32, | ||
488 | replMasterCurrentLogFile DisplayString, | ||
489 | replMasterCurrentLogPos Counter32, | ||
490 | replMasterBinlogDoDB DisplayString, | ||
491 | replMasterBinlogIgnoreDB DisplayString | ||
492 | } | ||
493 | |||
494 | replMasterIndex 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 | |||
502 | replMasterCurrentLogFile 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 | |||
510 | replMasterCurrentLogPos 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 | |||
518 | replMasterBinlogDoDB 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 | |||
526 | replMasterBinlogIgnoreDB 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 |
diff --git a/src/mysqlstat.8 b/src/mysqlstat.8 index f79e9cf..e0bcb7f 100644 --- a/src/mysqlstat.8 +++ b/src/mysqlstat.8 | |||
@@ -50,2 +50,14 @@ To configure the module, it is recommended to use the | |||
50 | utility. | 50 | utility. |
51 | .SS Caching | ||
52 | In order to minimize its impact on MySQL server, the | ||
53 | .B mysqlstat | ||
54 | module caches the data obtained from the server. Default caching | ||
55 | interval is 10 seconds for tabular information. Additionally, results | ||
56 | of each | ||
57 | .B SHOW PROCESSLIST | ||
58 | are cached for 10 seconds. This means that updates of | ||
59 | .B processListTable | ||
60 | entries may delay for up to 20 seconds. | ||
61 | .PP | ||
62 | As of version 1.0, these delays are not configurable. | ||
51 | .SH CONFIGURATION | 63 | .SH CONFIGURATION |
diff --git a/src/mysqlstat.c b/src/mysqlstat.c index 9d9975e..4eb5a18 100644 --- a/src/mysqlstat.c +++ b/src/mysqlstat.c | |||
@@ -277,2 +277,5 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent, | |||
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 | } |
@@ -368,2 +371,84 @@ replSlaveStatusTable_entry_free(void *data) | |||
368 | static void | 371 | static void |
372 | store_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 | |||
389 | int | ||
390 | replMasterStatusTable_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 | |||
444 | void | ||
445 | replMasterStatusTable_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 | |||
453 | static void | ||
369 | process_list_add(netsnmp_tdata *table_data, long idx, MYSQL_ROW mysql_row) | 454 | process_list_add(netsnmp_tdata *table_data, long idx, MYSQL_ROW mysql_row) |
@@ -463,5 +548,2 @@ process_slave_count(void) | |||
463 | 548 | ||
464 | |||
465 | |||
466 | |||
467 | 549 | ||
diff --git a/src/mysqlstat.mib2c b/src/mysqlstat.mib2c deleted file mode 100644 index c38ffc9..0000000 --- a/src/mysqlstat.mib2c +++ /dev/null | |||
@@ -1,47 +0,0 @@ | |||
1 | # This file is part of Mysqlstat -*- autoconf -*- | ||
2 | # Copyright (C) 2016 Sergey Poznyakoff | ||
3 | # | ||
4 | # Mysqlstat is free software; you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU General Public License as published by | ||
6 | # the Free Software Foundation; either version 3, or (at your option) | ||
7 | # any later version. | ||
8 | # | ||
9 | # Mysqlstat is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |