aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/MYSQL-STAT-MIB.txt127
-rw-r--r--src/mysqlstat.c220
-rw-r--r--src/mysqlstat.h27
-rw-r--r--src/mysqlstat_mib.mib2c114
4 files changed, 204 insertions, 284 deletions
diff --git a/src/MYSQL-STAT-MIB.txt b/src/MYSQL-STAT-MIB.txt
index 8fbc0e6..3c05db2 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 "201606061638Z" 21 LAST-UPDATED "201606070800Z"
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 "201606061638Z" 26 REVISION "201606070800Z"
27 DESCRIPTION 27 DESCRIPTION
@@ -463,98 +463,2 @@ replMasterSSLVerifyServerCert OBJECT-TYPE
463-- 463--
464-- Table of Replication Slave Servers
465--
466
467-- replSlaveCount OBJECT-TYPE
468-- SYNTAX Counter32
469-- MAX-ACCESS read-only
470-- STATUS current
471-- DESCRIPTION
472-- "Number of active replication slaves."
473-- ::= { replSlave 1 }
474
475-- replSlaveTable OBJECT-TYPE
476-- SYNTAX SEQUENCE OF ReplSlaveEntry
477-- MAX-ACCESS not-accessible
478-- STATUS current
479-- DESCRIPTION
480-- "A table of active replication slaves."
481-- ::= { replSlave 2 }
482
483-- replSlaveEntry OBJECT-TYPE
484-- SYNTAX ReplSlaveEntry
485-- MAX-ACCESS not-accessible
486-- STATUS current
487-- DESCRIPTION
488-- "An entry (conceptual row) describing a replication
489-- slave server."
490-- INDEX { replSlaveIndex }
491-- ::= { replSlaveTable 1 }
492
493-- ReplSlaveEntry ::= SEQUENCE {
494-- replSlaveIndex Integer32,
495-- replSlaveHost DisplayString,
496-- replSlaveUser DisplayString,
497-- replSlaveCommand DisplayString,
498-- replSlaveState DisplayString,
499-- replSlaveTime TimeStamp,
500-- replSlaveInfo DisplayString
501-- }
502
503-- replSlaveIndex OBJECT-TYPE
504-- SYNTAX Integer32 (0..65535)
505-- MAX-ACCESS not-accessible
506-- STATUS current
507-- DESCRIPTION
508-- "A number uniquely identifying each slave server."
509-- ::= { replSlaveEntry 1 }
510
511-- replSlaveHost OBJECT-TYPE
512-- SYNTAX DisplayString
513-- MAX-ACCESS read-only
514-- STATUS current
515-- DESCRIPTION
516-- "Hostname of the server."
517-- ::= { replSlaveEntry 2 }
518
519-- replSlaveUser OBJECT-TYPE
520-- SYNTAX DisplayString
521-- MAX-ACCESS read-only
522-- STATUS current
523-- DESCRIPTION
524-- "User name used by that server."
525-- ::= { replSlaveEntry 3 }
526
527-- replSlaveCommand OBJECT-TYPE
528-- SYNTAX DisplayString
529-- MAX-ACCESS read-only
530-- STATUS current
531-- DESCRIPTION
532-- "Command being run."
533-- ::= { replSlaveEntry 4 }
534
535-- replSlaveState OBJECT-TYPE
536-- SYNTAX DisplayString
537-- MAX-ACCESS read-only
538-- STATUS current
539-- DESCRIPTION
540-- "State of the connection."
541-- ::= { replSlaveEntry 5 }
542
543-- replSlaveTime OBJECT-TYPE
544-- SYNTAX TimeStamp
545-- MAX-ACCESS read-only
546-- STATUS current
547-- DESCRIPTION
548-- "Timestamp of the last status change."
549-- ::= { replSlaveEntry 6 }
550
551-- replSlaveInfo OBJECT-TYPE
552-- SYNTAX DisplayString
553-- MAX-ACCESS read-only
554-- STATUS current
555-- DESCRIPTION
556-- "Additional info about the connection."
557-- ::= { replSlaveEntry 7 }
558
559--
560-- Process List 464-- Process List
@@ -568,3 +472,3 @@ processListTable OBJECT-TYPE
568 "A table of active threads." 472 "A table of active threads."
569 ::= { processList 2 } 473 ::= { processList 1 }
570 474
@@ -662,2 +566,27 @@ processInfo OBJECT-TYPE
662 ::= { processListEntry 9 } 566 ::= { processListEntry 9 }
567
568processTotalCount OBJECT-TYPE
569 SYNTAX Counter32
570 MAX-ACCESS read-only
571 STATUS current
572 DESCRIPTION
573 "Total number of processes (threads)."
574 ::= { processList 2 }
575
576processActiveCount OBJECT-TYPE
577 SYNTAX Counter32
578 MAX-ACCESS read-only
579 STATUS current
580 DESCRIPTION
581 "Number of active processes (threads)."
582 ::= { processList 3 }
583
584processSlaveCount OBJECT-TYPE
585 SYNTAX Counter32
586 MAX-ACCESS read-only
587 STATUS current
588 DESCRIPTION
589 "Number of replication slaves"
590 ::= { processList 4 }
591
663END 592END
diff --git a/src/mysqlstat.c b/src/mysqlstat.c
index 938439a..2ffd0dd 100644
--- a/src/mysqlstat.c
+++ b/src/mysqlstat.c
@@ -56,18 +56,22 @@ mysqlstat_connect(void)
56{ 56{
57 struct mysqlstat_connection *conn; 57 static struct mysqlstat_connection *conn;
58 my_bool t = 1; 58 my_bool t = 1;
59 59
60 conn = xcalloc(1, sizeof(*conn)); 60 if (!conn) {
61 mysql_init(&conn->mysql); 61 conn = xcalloc(1, sizeof(*conn));
62 if (access(config_file, F_OK) == 0) 62 mysql_init(&conn->mysql);
63 mysql_options(&conn->mysql, MYSQL_READ_DEFAULT_FILE, 63 if (access(config_file, F_OK) == 0)
64 config_file); 64 mysql_options(&conn->mysql, MYSQL_READ_DEFAULT_FILE,
65 mysql_options(&conn->mysql, MYSQL_READ_DEFAULT_GROUP, "mysqlstat"); 65 config_file);
66 mysql_options(&conn->mysql, MYSQL_OPT_RECONNECT, &t); 66 mysql_options(&conn->mysql,
67 if (!mysql_real_connect(&conn->mysql, NULL, NULL, NULL, NULL, 0, 67 MYSQL_READ_DEFAULT_GROUP, "mysqlstat");
68 NULL, 0)) { 68 mysql_options(&conn->mysql, MYSQL_OPT_RECONNECT, &t);
69 snmp_log(LOG_ERR, "can't connect to MySQL: %s\n", 69 if (!mysql_real_connect(&conn->mysql,
70 mysql_error(&conn->mysql)); 70 NULL, NULL, NULL, NULL, 0,
71 free(conn); 71 NULL, 0)) {
72 conn = NULL; 72 snmp_log(LOG_ERR, "can't connect to MySQL: %s\n",
73 mysql_error(&conn->mysql));
74 free(conn);
75 conn = NULL;
76 }
73 } 77 }
@@ -75,11 +79,2 @@ mysqlstat_connect(void)
75} 79}
76
77void
78mysqlstat_disconnect(mysqlstat_connection_t conn)
79{
80 if (!conn)
81 return;
82 mysql_close(&conn->mysql);
83 free(conn);
84}
85 80
@@ -103,3 +98,94 @@ unsigned mysqlstat_cache_timeout = CACHE_TIMEOUT;
103#define STREQ(pat,str) (strcmp(#pat, str) == 0) 98#define STREQ(pat,str) (strcmp(#pat, str) == 0)
99
100struct process_list {
101 time_t ts;
102 MYSQL_RES *res;
103 uint32_t total;
104 uint32_t active;
105 uint32_t slaves;
106 uint32_t itr;
107};
108
109enum {
110 FI_processID,
111 FI_processUser,
112 FI_processHost,
113 FI_processDatabase,
114 FI_processCommand,
115 FI_processTime,
116 FI_processState,
117 FI_processInfo
118};
104 119
120static int
121get_process_list(struct process_list **p)
122{
123 static struct process_list plist;
124 time_t now;
125
126 now = time(NULL);
127 if (!plist.res || now - plist.ts >= mysqlstat_cache_timeout) {
128 mysqlstat_connection_t conn;
129 unsigned i;
130
131 if (plist.res) {
132 mysql_free_result(plist.res);
133 plist.res = NULL;
134 plist.total = plist.active = plist.slaves = 0;
135 }
136 DEBUGMSGTL(("mysqlstat", "Getting process list\n"));
137
138 conn = mysqlstat_connect();
139 if (!conn)
140