summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2016-06-03 20:18:56 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-06-03 20:18:56 (GMT)
commitccfe04cf8c3c903013dcacf5681d0d826b222224 (patch) (side-by-side diff)
tree5d26d8d1d19cc13af7ee52048e6f7c6cfe840e31
parentcca955986efc0a7736ea0240fae2ce0694b16c5e (diff)
downloadmysqlstat-ccfe04cf8c3c903013dcacf5681d0d826b222224.tar.gz
mysqlstat-ccfe04cf8c3c903013dcacf5681d0d826b222224.tar.bz2
Initial commit
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--.gitignore28
-rw-r--r--NEWS0
-rw-r--r--configure.ac7
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am8
-rw-r--r--src/mysqlstat.c89
-rw-r--r--src/mysqlstat_mib.mib2c (renamed from src/mysqlstat-mib.mib2c)21
7 files changed, 111 insertions, 43 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..506e185
--- a/dev/null
+++ b/.gitignore
@@ -0,0 +1,28 @@
+*.a
+*.la
+*.lo
+*.o
+*.tar.*
+*~
+.deps
+.emacs*
+.gdbinit
+.libs
+ABOUT-NLS
+ChangeLog
+INSTALL
+Makefile
+Makefile.in
+TAGS
+aclocal.m4
+autom4te.cache/
+build-aux
+config.h
+config.h.in
+config.log
+config.status
+configure
+core
+libtool
+m4
+stamp-h1
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..e69de29
--- a/dev/null
+++ b/NEWS
diff --git a/configure.ac b/configure.ac
index f386366..fe20beb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@
AC_PREREQ(2.69)
AC_INIT([mysqlstat], 0.0.90, [gray@gnu.org])
-AC_CONFIG_SRCDIR(src/mysqlstat-mib.mib2c)
+AC_CONFIG_SRCDIR(src/mysqlstat_mib.mib2c)
AM_CONFIG_HEADER(config.h)
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
@@ -45,10 +45,11 @@ fi
AC_SUBST(NET_SNMP_CONFIG)
# Check for MySQL
+AC_SUBST(MYSQL_LIBS)
MY_CHECK_LIB(mysqlclient, mysql_real_connect, -lm,
- [MYSQL_LIBS="$pm_cv_lib_mysqlclient"],
+ [MYSQL_LIBS="$my_cv_lib_mysqlclient"],
[AC_MSG_ERROR(required library libmysqlclient not found)],
- [/usr/lib/mysql /usr/local/lib/mysql])
+ [/usr/lib64/mysql /usr/local/lib/mysql])
# Checks for header files.
AC_HEADER_STDC
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..e89552d
--- a/dev/null
+++ b/src/.gitignore
@@ -0,0 +1 @@
+mysqlstat_mib.c
diff --git a/src/Makefile.am b/src/Makefile.am
index f3a2970..6463177 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,12 +20,12 @@ dlmod_LTLIBRARIES = mysqlstat.la
mysqlstat_la_SOURCES = \
mysqlstat.c\
mysqlstat.h\
- mysqlstat-mib.c
+ mysqlstat_mib.c
BUILT_SOURCES = \
- mysqlstat-mib.c
+ mysqlstat_mib.c
-mysqlstat-mib.c: mysqlstat-mib.mib2c MYSQL-STAT-MIB.txt
+mysqlstat_mib.c: mysqlstat_mib.mib2c MYSQL-STAT-MIB.txt
.mib2c.c:
MIBDIRS=${top_srcdir}/src:${NET_SNMP_MIBDIRS} MIBS="+MYSQL-STAT-MIB" \
@@ -56,4 +56,4 @@ mib_DATA = MYSQL-STAT-MIB.txt
#dist_man_MANS = mysqlstat.8
-EXTRA_DIST = MYSQL-STAT-MIB.txt mysqlstat-mib.mib2c
+EXTRA_DIST = MYSQL-STAT-MIB.txt mysqlstat_mib.mib2c
diff --git a/src/mysqlstat.c b/src/mysqlstat.c
index 1ce7014..c50ae65 100644
--- a/src/mysqlstat.c
+++ b/src/mysqlstat.c
@@ -15,14 +15,40 @@
* along with Mysqlstat. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <mysqlstat.c>
-#include <mysql.c>
+#include <mysqlstat.h>
+#include <mysql/mysql.h>
+#undef NDEBUG
+#include <assert.h>
static char *config_file = CONFDIR "/mysqlstat.cnf";
struct mysqlstat_connection {
MYSQL mysql;
};
+
+static void *
+xalloc(size_t s)
+{
+ void *p = malloc(s);
+ assert(p != NULL);
+ return p;
+}
+
+static void *
+xcalloc(size_t nmemb, size_t size)
+{
+ void *p = calloc(nmemb, size);
+ assert(p != NULL);
+ return p;
+}
+
+static char *
+xstrdup(char const *s)
+{
+ char *p = strdup(s);
+ assert(p != NULL);
+ return p;
+}
mysqlstat_connection_t
mysqlstat_connect(void)
@@ -30,7 +56,7 @@ mysqlstat_connect(void)
struct mysqlstat_connection *conn;
my_bool t = 1;
- conn = xcalloc(sizeof(*conn));
+ conn = xcalloc(1, sizeof(*conn));
mysql_init(&conn->mysql);
if (access(config_file, F_OK) == 0)
mysql_options(&conn->mysql, MYSQL_READ_DEFAULT_FILE,
@@ -48,7 +74,7 @@ mysqlstat_connect(void)
}
void
-mysqlstat_disconnect(mysqlstat_connection_t *conn)
+mysqlstat_disconnect(mysqlstat_connection_t conn)
{
if (!conn)
return;
@@ -85,7 +111,7 @@ syment_free(struct syment *ent)
static int
syment_matches(struct syment *ent, char const *name)
{
- if (!syment->name)
+ if (!ent->name)
return 0;
return strcmp(ent->name, name) == 0;
}
@@ -121,16 +147,15 @@ static void
rehash(struct hashtab *ht)
{
struct syment *oldtab = ht->tab;
- struct syment *newtab;
uint32_t i, n;
assert(ht->hc + 1 < max_rehash);
n = hash_size[ht->hc];
++ht->hc;
- newtab = xcalloc(hash_size[ht->hc], sizeof(newtab[0]));
+ ht->tab = xcalloc(hash_size[ht->hc], sizeof(ht->tab[0]));
for (i = 0; i < n; i++) {
- if (ent->name)
- newtab[find_insert_pos(ht, &oldtab[i])] = oldtab[i];
+ if (oldtab[i].name)
+ ht->tab[find_insert_pos(ht, &oldtab[i])] = oldtab[i];
}
free(oldtab);
}
@@ -138,7 +163,7 @@ rehash(struct hashtab *ht)
static void
hashtab_remove(struct hashtab *ht, char const *name)
{
- uint32_t int pos, i, j, r;
+ uint32_t pos, i, j, r;
pos = hash_string(name, hash_size[ht->hc]);
for (i = pos; ht->tab[i].name;) {
@@ -149,32 +174,32 @@ hashtab_remove(struct hashtab *ht, char const *name)
return;// ENOENT
}
- syment_free(ht->tab[i]);
+ syment_free(&ht->tab[i]);
for (;;) {
- st->tab[i] = NULL;
+ ht->tab[i].name = ht->tab[i].value = NULL;
j = i;
do {
i = (i + 1) % hash_size[ht->hc];
- if (!st->tab[i].name)
+ if (!ht->tab[i].name)
return;
r = hash_string(ht->tab[i].name, hash_size[ht->hc]);
} while ((j < r && r <= i)
|| (i < j && j < r) || (r <= i && i < j));
- st->tab[j] = st->tab[i];
+ ht->tab[j] = ht->tab[i];
}
}
static char const *
hashtab_lookup(struct hashtab *ht, char const *name)
{
- uint32_t pos;
+ uint32_t pos, i;
pos = hash_string(name, hash_size[ht->hc]);
for (i = pos; ht->tab[i].name;) {
if (syment_matches(&ht->tab[i], name))
- return ht->tab[i].name;
+ return ht->tab[i].value;
i = (i + 1) % hash_size[ht->hc];
if (i == pos)
break;
@@ -185,14 +210,17 @@ hashtab_lookup(struct hashtab *ht, char const *name)
static void
hashtab_install(struct hashtab *ht, char const *name, char const *value)
{
- uint32_t pos;
+ uint32_t i, pos;
struct syment *ent;
-
+
+ if (!value)
+ value = "";
+ DEBUGMSGTL(("mysqlstat", "%s = %s\n", name, value));
pos = hash_string(name, hash_size[ht->hc]);
for (i = pos; ht->tab[i].name;) {
if (syment_matches(&ht->tab[i], name)) {
free(ht->tab[i].value);
- ht->tab[i].value = xtsrdup(value);
+ ht->tab[i].value = xstrdup(value);
return;
}
i = (i + 1) % hash_size[ht->hc];
@@ -202,8 +230,8 @@ hashtab_install(struct hashtab *ht, char const *name, char const *value)
}
}
- ht->tab[i].name = xtsrdup(name);
- ht->tab[i].value = xtsrdup(value);
+ ht->tab[i].name = xstrdup(name);
+ ht->tab[i].value = xstrdup(value);
}
void
@@ -211,7 +239,7 @@ hashtab_clear(struct hashtab *ht)
{
unsigned i, hs;
- hs = hash_size[st->hash_num];
+ hs = hash_size[ht->hc];
for (i = 0; i < hs; i++) {
syment_free(&ht->tab[i]);
}
@@ -220,15 +248,15 @@ hashtab_clear(struct hashtab *ht)
static struct hashtab *
hashtab_create(void)
{
- struct hashtab *ht = xmalloc(sizeof(*ht));
+ struct hashtab *ht = xalloc(sizeof(*ht));
ht->hc = 0;
- ht->tab = xcalloc(hash_size[ht->hc], sizeof(newtab[0]));
+ ht->tab = xcalloc(hash_size[ht->hc], sizeof(ht->tab[0]));
return ht;
}
struct mysqlstat_cache {
- void (*populate) (struch hashtab *);
- struch hashtab *ht;
+ void (*populate) (struct hashtab *);
+ struct hashtab *ht;
time_t ts;
};
@@ -251,7 +279,7 @@ mysqlstat_cache_get(struct mysqlstat_cache *cache, char const *name)
}
static void
-populate_repl(struch hashtab *ht)
+populate_repl(struct hashtab *ht)
{
mysqlstat_connection_t conn;
MYSQL_RES *res;
@@ -263,6 +291,7 @@ populate_repl(struch hashtab *ht)
if (!conn)
return;
+ DEBUGMSGTL(("mysqlstat", "Getting slave status\n"));
if (mysql_query(&conn->mysql, "SHOW SLAVE STATUS")) {
snmp_log(LOG_ERR, "can't get slave status: %s",
mysql_error(&conn->mysql));
@@ -279,7 +308,8 @@ populate_repl(struch hashtab *ht)
fields = mysql_fetch_fields(res);
row = mysql_fetch_row(res);
for (i = 0; i < num_fields; i++)
- hashtab_install(ht, fields[i].name, row[i] ? row[i] : NULL);
+ if (row[i])
+ hashtab_install(ht, fields[i].name, row[i]);
mysql_free_result(res);
mysqlstat_disconnect(conn);
}
@@ -291,7 +321,8 @@ static struct mysqlstat_cache cache[MYSQLSTAT_MAX_CACHE] = {
char const *
mysqlstat_get(int id, char const *name)
{
- return mysqlstat_cache_get(cache + i, name);
+ assert(id < sizeof(cache) / sizeof(cache[0]));
+ return mysqlstat_cache_get(cache + id, name);
}
diff --git a/src/mysqlstat-mib.mib2c b/src/mysqlstat_mib.mib2c
index fb6e80b..8f9663d 100644
--- a/src/mysqlstat-mib.mib2c
+++ b/src/mysqlstat_mib.mib2c
@@ -57,7 +57,6 @@ $vars{'mysqlstat_translate_table'} = {
$vars{'mysqlstat_translate'} = sub {
my ($name) = @_;
-
my $r = $vars{'mysqlstat_translate_table'}->{$name};
if (!defined($r)) {
print STDERR "no translation for $name!\n";
@@ -102,7 +101,7 @@ handle_$i(netsnmp_mib_handler *handler,
@if $i.settable@
int ret;
@end@
- char const *val = mysqlstat_get($varnish_id, "$varnish_name");
+ char const *val = mysqlstat_get($mysqlstat_id, "$mysqlstat_name");
if (!val)
return SNMP_ERR_NOSUCHNAME;
@@ -123,14 +122,21 @@ handle_$i(netsnmp_mib_handler *handler,
snmp_set_var_typed_value(requests->requestvb, $i.type,
val, strlen(val));
break;
- @elsif $i.type eq 'ASN_COUNTER32'@
+ @elsif $i.type eq 'ASN_COUNTER'@
+ {
+ uint32_t n = strtoul(val, NULL, 10);
+ snmp_set_var_typed_value(requests->requestvb, $i.type,
+ &n,
+ sizeof(n));
+ }
+ @elsif $i.type eq 'ASN_INTEGER'@
{
uint32_t n = strtoul(val, NULL, 10);
snmp_set_var_typed_value(requests->requestvb, $i.type,
&n,
sizeof(n));
}
- @elsif $i.type eq 'ASN_INTEGER32'@
+ @elsif $i.type eq 'ASN_TIMETICKS'@
{
uint32_t n = strtoul(val, NULL, 10);
snmp_set_var_typed_value(requests->requestvb, $i.type,
@@ -170,7 +176,7 @@ handle_$i(netsnmp_mib_handler *handler,
# Free resources allocated in RESERVE1 and/or
# RESERVE2. Something failed somewhere, and the states
# below won't be called.
- $varnish_set_free(reqinfo, requests, vd);
+ $mysqlstat_set_free(reqinfo, requests, vd);
@end@
break;
@@ -217,9 +223,9 @@ init_$modulename(void)
@startperl@
&{$vars{'mysqlstat_translate'}}($vars{'i'});
@endperl@
-$varnish_if
+$mysqlstat_if
const oid ${i}_oid[] = { $i.commaoid };
-$varnish_endif
+$mysqlstat_endif
@end@
DEBUGMSGTL(("$modulename", "Initializing\n"));
@@ -238,6 +244,7 @@ $varnish_endif
HANDLER_CAN_RWRITE
@end@
));
+ @end@
}
void

Return to:

Send suggestions and report system problems to the System administrator.