struct mysql_database_s /* {{{ */
{
- /* instance == NULL => legacy mode */
char *instance;
char *host;
char *user;
int err;
if ((err = mysql_ping (db->con)) != 0)
{
- WARNING ("mysql_ping failed for %s: %s",
- (db->instance != NULL)
- ? db->instance
- : "<legacy>",
+ /* Assured by "mysql_config_database" */
+ assert (db->instance != NULL);
+ WARNING ("mysql_ping failed for instance \"%s\": %s",
+ db->instance,
mysql_error (db->con));
db->state = 0;
}
static void set_host (mysql_database_t *db, char *buf, size_t buflen)
{
- /* XXX legacy mode - use hostname_g */
- if (db->instance == NULL)
+ if ((db->host == NULL)
+ || (strcmp ("", db->host) == 0)
+ || (strcmp ("localhost", db->host) == 0))
sstrncpy (buf, hostname_g, buflen);
else
- {
- if ((db->host == NULL)
- || (strcmp ("", db->host) == 0)
- || (strcmp ("localhost", db->host) == 0))
- sstrncpy (buf, hostname_g, buflen);
- else
- sstrncpy (buf, db->host, buflen);
- }
-}
-
-static void set_plugin_instance (mysql_database_t *db,
- char *buf, size_t buflen)
-{
- /* XXX legacy mode - no plugin_instance */
- if (db->instance == NULL)
- sstrncpy (buf, "", buflen);
- else
- sstrncpy (buf, db->instance, buflen);
-}
+ sstrncpy (buf, db->host, buflen);
+} /* void set_host */
static void submit (const char *type, const char *type_instance,
value_t *values, size_t values_len, mysql_database_t *db)
set_host (db, vl.host, sizeof (vl.host));
sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
- set_plugin_instance (db, vl.plugin_instance, sizeof (vl.plugin_instance));
+
+ /* Assured by "mysql_config_database" */
+ assert (db->instance != NULL);
+ sstrncpy (vl.plugin_instance, db->instance, sizeof (vl.plugin_instance));
sstrncpy (vl.type, type, sizeof (vl.type));
if (type_instance != NULL)
submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db);
} /* void derive_submit */
-static void threads_submit (gauge_t running, gauge_t connected, gauge_t cached,
- counter_t created, mysql_database_t *db)
-{
- value_t values[4];
-
- values[0].gauge = running;
- values[1].gauge = connected;
- values[2].gauge = cached;
- values[3].counter = created;
-
- submit ("mysql_threads", NULL, values, STATIC_ARRAY_SIZE (values), db);
-} /* void threads_submit */
-
static void traffic_submit (counter_t rx, counter_t tx, mysql_database_t *db)
{
value_t values[2];
if (db->slave_notif)
{
- notification_t n = { 0, time (NULL), "", "",
+ notification_t n = { 0, cdtime (), "", "",
"mysql", "", "time_offset", "", NULL };
char *io, *sql;
sql = row[SLAVE_SQL_RUNNING_IDX];
set_host (db, n.host, sizeof (n.host));
- set_plugin_instance (db,
- n.plugin_instance, sizeof (n.plugin_instance));
+
+ /* Assured by "mysql_config_database" */
+ assert (db->instance != NULL);
+ sstrncpy (n.plugin_instance, db->instance, sizeof (n.plugin_instance));
if (((io == NULL) || (strcasecmp (io, "yes") != 0))
&& (db->slave_io_running))
derive_t qcache_lowmem_prunes = 0;
gauge_t qcache_queries_in_cache = NAN;
- int threads_running = -1;
- int threads_connected = -1;
- int threads_cached = -1;
- unsigned long long threads_created = 0ULL;
+ gauge_t threads_running = NAN;
+ gauge_t threads_connected = NAN;
+ gauge_t threads_cached = NAN;
+ derive_t threads_created = 0;
unsigned long long traffic_incoming = 0ULL;
unsigned long long traffic_outgoing = 0ULL;
strlen ("Threads_")) == 0)
{
if (strcmp (key, "Threads_running") == 0)
- threads_running = (int) val;
+ threads_running = (gauge_t) val;
else if (strcmp (key, "Threads_connected") == 0)
- threads_connected = (int) val;
+ threads_connected = (gauge_t) val;
else if (strcmp (key, "Threads_cached") == 0)
- threads_cached = (int) val;
+ threads_cached = (gauge_t) val;
else if (strcmp (key, "Threads_created") == 0)
- threads_created = val;
+ threads_created = (derive_t) val;
}
else if (strncmp (key, "Table_locks_",
strlen ("Table_locks_")) == 0)
qcache_queries_in_cache, db);
}
- if (threads_created != 0ULL)
- threads_submit (threads_running, threads_connected,
- threads_cached, threads_created, db);
+ if (threads_created != 0)
+ {
+ gauge_submit ("threads", "running",
+ threads_running, db);
+ gauge_submit ("threads", "connected",
+ threads_connected, db);
+ gauge_submit ("threads", "cached",
+ threads_cached, db);
+
+ derive_submit ("total_threads", "created",
+ threads_created, db);
+ }
traffic_submit (traffic_incoming, traffic_outgoing, db);