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 /src | |
parent | b1173f33f7d9e1c42371a5df7e21765861c74c4f (diff) | |
download | mysqlstat-4edb28548c028f788a5c08b0dda415ce4f6a01aa.tar.gz mysqlstat-4edb28548c028f788a5c08b0dda415ce4f6a01aa.tar.bz2 |
Implement master status MIB
Diffstat (limited to 'src')
-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 mysql MODULE-IDENTITY - LAST-UPDATED "201606071145Z" + LAST-UPDATED "201606090926Z" ORGANIZATION "Gray Software" @@ -25,3 +25,3 @@ mysql MODULE-IDENTITY "This MIB module defines objects for MySQL statistics." - REVISION "201606071145Z" + REVISION "201606090926Z" DESCRIPTION @@ -71,3 +71,3 @@ ReplSlaveStatusEntry ::= SEQUENCE { replExecMasterLogPos Counter32, - replRelayLogSpace Counter64, + replRelayLogSpace Gauge32, replSecondsBehindMaster TimeStamp, @@ -83,3 +83,3 @@ ReplSlaveStatusEntry ::= SEQUENCE { replReplicateWildIgnoreTable DisplayString, - replSkipCounter Counter32, + replSkipCounter Gauge32, replUntilCondition DisplayString, @@ -463,2 +463,73 @@ replMasterSSLVerifyServerCert OBJECT-TYPE -- +-- Replication master status +-- + +replMasterStatusTable OBJECT-TYPE + SYNTAX SEQUENCE OF ReplMasterStatusEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A table of replication master status. On replication master, + it contains a single row, describing the current + status." + ::= { replication 2 } + +replMasterStatusEntry OBJECT-TYPE + SYNTAX ReplMasterStatusEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "An entry describing master status." + INDEX { replMasterIndex } + ::= { replMasterStatusTable 1 } + +ReplMasterStatusEntry ::= SEQUENCE { + replMasterIndex Integer32, + replMasterCurrentLogFile DisplayString, + replMasterCurrentLogPos Counter32, + replMasterBinlogDoDB DisplayString, + replMasterBinlogIgnoreDB DisplayString +} + +replMasterIndex OBJECT-TYPE + SYNTAX Integer32 (0..65535) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A number uniquely identifying master status row." + ::= { replMasterStatusEntry 1 } + +replMasterCurrentLogFile OBJECT-TYPE + SYNTAX DisplayString + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The name of the master binary log file." + ::= { replMasterStatusEntry 2 } + +replMasterCurrentLogPos OBJECT-TYPE + SYNTAX Counter32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The position in the current master binary log file." + ::= { replMasterStatusEntry 3 } + +replMasterBinlogDoDB OBJECT-TYPE + SYNTAX DisplayString + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The list of database names to include in the binlog." + ::= { replMasterStatusEntry 4 } + +replMasterBinlogIgnoreDB OBJECT-TYPE + SYNTAX DisplayString + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The list of database names to exclude from the binlog." + ::= { replMasterStatusEntry 5 } + +-- -- 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 utility. +.SS Caching +In order to minimize its impact on MySQL server, the +.B mysqlstat +module caches the data obtained from the server. Default caching +interval is 10 seconds for tabular information. Additionally, results +of each +.B SHOW PROCESSLIST +are cached for 10 seconds. This means that updates of +.B processListTable +entries may delay for up to 20 seconds. +.PP +As of version 1.0, these delays are not configurable. .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, ent->replMasterSSLVerifyServerCert = val_bool(value); + } else { + snmp_log(LOG_ERR, "unrecognized slave status column: %s\n", + name); } @@ -368,2 +371,84 @@ 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) @@ -463,5 +548,2 @@ process_slave_count(void) - - - 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 @@ -# This file is part of Mysqlstat -*- autoconf -*- -# Copyright (C) 2016 Sergey Poznyakoff -# -# Mysqlstat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# Mysqlstat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Mysqlstat. If not, see <http://www.gnu.org/licenses/>. - -@define ROCOM@ -/* Local variables: - buffer-read-only: t - End: - vi: set ro: -*/ -@enddefine@ -@startperl@ -// FIXME: translation table - -$vars{'modulename'} = $vars{'name'}; -$vars{'modulename'} =~ s#.*/##; -$vars{'modulename'} =~ s/\.c$//; -#print "$vars{'modulename'}\n"; - -0; -@endperl@ -@open ${modulename}.h@ -/* THIS FILE IS GENERATED AUTOMATICALLY. PLEASE DO NOT EDIT. */ -#include <config.h> -#include <stddef.h> -#include <stdlib.h> -#include <stdint.h> -#include <limits.h> - -// FIXME -@open ${name}@ -/* THIS FILE IS GENERATED AUTOMATICALLY. PLEASE DO NOT EDIT. */ - -#include "mysqlstat.h" - |