summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2016-06-09 07:04:55 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-06-09 07:04:55 (GMT)
commit4edb28548c028f788a5c08b0dda415ce4f6a01aa (patch) (unidiff)
tree60b44f00c5b2f6d7cb18cb700e43197b098edf0d
parentb1173f33f7d9e1c42371a5df7e21765861c74c4f (diff)
downloadmysqlstat-4edb28548c028f788a5c08b0dda415ce4f6a01aa.tar.gz
mysqlstat-4edb28548c028f788a5c08b0dda415ce4f6a01aa.tar.bz2
Implement master status MIB
Diffstat (more/less context) (ignore whitespace changes)
-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
@@ -20,3 +20,3 @@ IMPORTS
20mysql MODULE-IDENTITY 20mysql 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 replExecMasterLogPosCounter32, 71 replExecMasterLogPosCounter32,
72 replRelayLogSpaceCounter64, 72 replRelayLogSpaceGauge32,
73 replSecondsBehindMasterTimeStamp, 73 replSecondsBehindMasterTimeStamp,
@@ -83,3 +83,3 @@ ReplSlaveStatusEntry ::= SEQUENCE {
83 replReplicateWildIgnoreTableDisplayString, 83 replReplicateWildIgnoreTableDisplayString,
84 replSkipCounter Counter32, 84 replSkipCounter Gauge32,
85 replUntilConditionDisplayString, 85 replUntilConditionDisplayString,
@@ -463,2 +463,73 @@ replMasterSSLVerifyServerCert OBJECT-TYPE
463-- 463--
464-- Replication master status
465--
466
467 replMasterStatusTableOBJECT-TYPE
468 SYNTAXSEQUENCE OF ReplMasterStatusEntry
469 MAX-ACCESSnot-accessible
470 STATUScurrent
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 replMasterStatusEntryOBJECT-TYPE
478 SYNTAXReplMasterStatusEntry
479 MAX-ACCESSnot-accessible
480 STATUScurrent
481 DESCRIPTION
482 "An entry describing master status."
483 INDEX { replMasterIndex }
484 ::= { replMasterStatusTable 1 }
485
486 ReplMasterStatusEntry::= SEQUENCE {
487 replMasterIndex Integer32,
488 replMasterCurrentLogFileDisplayString,
489 replMasterCurrentLogPos Counter32,
490 replMasterBinlogDoDB DisplayString,
491 replMasterBinlogIgnoreDBDisplayString
492}
493
494 replMasterIndexOBJECT-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 replMasterCurrentLogFileOBJECT-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 replMasterBinlogDoDBOBJECT-TYPE
519 SYNTAXDisplayString
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 replMasterBinlogIgnoreDBOBJECT-TYPE
527 SYNTAXDisplayString
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
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
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)
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)
@@ -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
+++ b/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
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Mysqlstat. If not, see <http://www.gnu.org/licenses/>.
16
17@define ROCOM@
18/* Local variables:
19 buffer-read-only: t
20 End:
21 vi: set ro:
22*/
23@enddefine@
24@startperl@
25// FIXME: translation table
26
27$vars{'modulename'} = $vars{'name'};
28$vars{'modulename'} =~ s#.*/##;
29$vars{'modulename'} =~ s/\.c$//;
30#print "$vars{'modulename'}\n";
31
320;
33@endperl@
34@open ${modulename}.h@
35/* THIS FILE IS GENERATED AUTOMATICALLY. PLEASE DO NOT EDIT. */
36#include <config.h>
37#include <stddef.h>
38#include <stdlib.h>
39#include <stdint.h>
40#include <limits.h>
41
42// FIXME
43@open ${name}@
44/* THIS FILE IS GENERATED AUTOMATICALLY. PLEASE DO NOT EDIT. */
45
46#include "mysqlstat.h"
47

Return to:

Send suggestions and report system problems to the System administrator.