# define CAN_USE_SYSCTL 0
#endif
-#define CPU_STATE_USER 0
-#define CPU_STATE_SYSTEM 1
-#define CPU_STATE_WAIT 2
-#define CPU_STATE_NICE 3
-#define CPU_STATE_SWAP 4
-#define CPU_STATE_INTERRUPT 5
-#define CPU_STATE_SOFTIRQ 6
-#define CPU_STATE_STEAL 7
-#define CPU_STATE_IDLE 8
-#define CPU_STATE_COLLECTD_ACTIVE 9 /* sum of (!idle) */
-#define CPU_STATE_COLLECTD_MAX 10 /* #states */
+#define COLLECTD_CPU_STATE_USER 0
+#define COLLECTD_CPU_STATE_SYSTEM 1
+#define COLLECTD_CPU_STATE_WAIT 2
+#define COLLECTD_CPU_STATE_NICE 3
+#define COLLECTD_CPU_STATE_SWAP 4
+#define COLLECTD_CPU_STATE_INTERRUPT 5
+#define COLLECTD_CPU_STATE_SOFTIRQ 6
+#define COLLECTD_CPU_STATE_STEAL 7
+#define COLLECTD_CPU_STATE_IDLE 8
+#define COLLECTD_CPU_STATE_ACTIVE 9 /* sum of (!idle) */
+#define COLLECTD_CPU_STATE_MAX 10 /* #states */
#if HAVE_STATGRAB_H
# include <statgrab.h>
cpu_state_t *tmp;
size_t sz;
- sz = (((size_t) cpu_num) + 1) * CPU_STATE_COLLECTD_MAX;
+ sz = (((size_t) cpu_num) + 1) * COLLECTD_CPU_STATE_MAX;
assert (sz > 0);
/* We already have enough space. */
static cpu_state_t *get_cpu_state (size_t cpu_num, size_t state) /* {{{ */
{
- size_t index = ((cpu_num * CPU_STATE_COLLECTD_MAX) + state);
+ size_t index = ((cpu_num * COLLECTD_CPU_STATE_MAX) + state);
if (index >= cpu_states_num)
return (NULL);
return (&cpu_states[index]);
} /* }}} cpu_state_t *get_cpu_state */
-/* Populates the per-CPU CPU_STATE_COLLECTD_ACTIVE rate and the global rate_by_state
+/* Populates the per-CPU COLLECTD_CPU_STATE_ACTIVE rate and the global rate_by_state
* array. */
static void aggregate (gauge_t *sum_by_state) /* {{{ */
{
size_t cpu_num;
size_t state;
- for (state = 0; state < CPU_STATE_COLLECTD_MAX; state++)
+ for (state = 0; state < COLLECTD_CPU_STATE_MAX; state++)
sum_by_state[state] = NAN;
for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
{
cpu_state_t *this_cpu_states = get_cpu_state (cpu_num, 0);
- this_cpu_states[CPU_STATE_COLLECTD_ACTIVE].rate = NAN;
+ this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate = NAN;
- for (state = 0; state < CPU_STATE_COLLECTD_ACTIVE; state++)
+ for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
{
if (!this_cpu_states[state].has_value)
continue;
RATE_ADD (sum_by_state[state], this_cpu_states[state].rate);
- if (state != CPU_STATE_IDLE)
- RATE_ADD (this_cpu_states[CPU_STATE_COLLECTD_ACTIVE].rate, this_cpu_states[state].rate);
+ if (state != COLLECTD_CPU_STATE_IDLE)
+ RATE_ADD (this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate, this_cpu_states[state].rate);
}
- RATE_ADD (sum_by_state[CPU_STATE_COLLECTD_ACTIVE], this_cpu_states[CPU_STATE_COLLECTD_ACTIVE].rate);
+ if (!isnan (this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate))
+ this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].has_value = 1;
+
+ RATE_ADD (sum_by_state[COLLECTD_CPU_STATE_ACTIVE], this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate);
}
} /* }}} void aggregate */
/* Commits (dispatches) the values for one CPU or the global aggregation.
* cpu_num is the index of the CPU to be committed or -1 in case of the global
- * aggregation. rates is a pointer to CPU_STATE_COLLECTD_MAX gauge_t values holding the
+ * aggregation. rates is a pointer to COLLECTD_CPU_STATE_MAX gauge_t values holding the
* current rate; each rate may be NAN. Calculates the percentage of each state
* and dispatches the metric. */
static void cpu_commit_one (int cpu_num, /* {{{ */
- gauge_t rates[static CPU_STATE_COLLECTD_MAX])
+ gauge_t rates[static COLLECTD_CPU_STATE_MAX])
{
size_t state;
gauge_t sum;
- sum = rates[CPU_STATE_COLLECTD_ACTIVE];
- RATE_ADD (sum, rates[CPU_STATE_IDLE]);
+ sum = rates[COLLECTD_CPU_STATE_ACTIVE];
+ RATE_ADD (sum, rates[COLLECTD_CPU_STATE_IDLE]);
if (!report_by_state)
{
- gauge_t percent = 100.0 * rates[CPU_STATE_COLLECTD_ACTIVE] / sum;
- submit_percent (cpu_num, CPU_STATE_COLLECTD_ACTIVE, percent);
+ gauge_t percent = 100.0 * rates[COLLECTD_CPU_STATE_ACTIVE] / sum;
+ submit_percent (cpu_num, COLLECTD_CPU_STATE_ACTIVE, percent);
return;
}
- for (state = 0; state < CPU_STATE_COLLECTD_ACTIVE; state++)
+ for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
{
gauge_t percent = 100.0 * rates[state] / sum;
submit_percent (cpu_num, state, percent);
{
int state;
- for (state = 0; state < CPU_STATE_COLLECTD_ACTIVE; state++)
+ for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
{
size_t cpu_num;
- if (report_by_cpu) {
- for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
- {
- cpu_state_t *s = get_cpu_state (cpu_num, state);
-
- if (!s->has_value)
- continue;
-
- submit_derive ((int) cpu_num, (int) state, s->conv.last_value.derive);
- }
- } else {
- derive_t derive_total = 0;
- for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
- {
- cpu_state_t *s = get_cpu_state (cpu_num, state);
- if (!s->has_value)
- continue;
+ for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
+ {
+ cpu_state_t *s = get_cpu_state (cpu_num, state);
- derive_total += s->conv.last_value.derive;
+ if (!s->has_value)
+ continue;
- }
- submit_derive (-1, (int) state, derive_total);
+ submit_derive ((int) cpu_num, (int) state, s->conv.last_value.derive);
}
}
} /* }}} void cpu_commit_without_aggregation */
/* Aggregates the internal state and dispatches the metrics. */
static void cpu_commit (void) /* {{{ */
{
- gauge_t global_rates[CPU_STATE_COLLECTD_MAX] = {
- NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN
+ gauge_t global_rates[COLLECTD_CPU_STATE_MAX] = {
+ NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN /* Batman! */
};
size_t cpu_num;
- if (report_by_state && !report_percent)
+ if (report_by_state && report_by_cpu && !report_percent)
{
cpu_commit_without_aggregation ();
return;
for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
{
cpu_state_t *this_cpu_states = get_cpu_state (cpu_num, 0);
- gauge_t local_rates[CPU_STATE_COLLECTD_MAX] = {
+ gauge_t local_rates[COLLECTD_CPU_STATE_MAX] = {
NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN
};
size_t state;
- for (state = 0; state < CPU_STATE_COLLECTD_ACTIVE; state++)
+ for (state = 0; state < COLLECTD_CPU_STATE_MAX; state++)
if (this_cpu_states[state].has_value)
local_rates[state] = this_cpu_states[state].rate;
cpu_state_t *s;
value_t v;
- if (state >= CPU_STATE_COLLECTD_ACTIVE)
+ if (state >= COLLECTD_CPU_STATE_ACTIVE)
return (EINVAL);
status = cpu_states_alloc (cpu_num);
continue;
}
- if (cpu_info_len < CPU_STATE_COLLECTD_MAX)
+ if (cpu_info_len < COLLECTD_CPU_STATE_MAX)
{
ERROR ("cpu plugin: processor_info returned only %i elements..", cpu_info_len);
continue;
}
- cpu_stage (cpu, CPU_STATE_USER, (derive_t) cpu_info.cpu_ticks[CPU_STATE_USER], now);
- cpu_stage (cpu, CPU_STATE_NICE, (derive_t) cpu_info.cpu_ticks[CPU_STATE_NICE], now);
- cpu_stage (cpu, CPU_STATE_SYSTEM, (derive_t) cpu_info.cpu_ticks[CPU_STATE_SYSTEM], now);
- cpu_stage (cpu, CPU_STATE_IDLE, (derive_t) cpu_info.cpu_ticks[CPU_STATE_IDLE], now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_USER, (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_USER], now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_NICE, (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_NICE], now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_SYSTEM], now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_IDLE, (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_IDLE], now);
}
/* }}} #endif PROCESSOR_CPU_LOAD_INFO */
cpu = atoi (fields[0] + 3);
- cpu_stage (cpu, CPU_STATE_USER, (derive_t) atoll(fields[1]), now);
- cpu_stage (cpu, CPU_STATE_NICE, (derive_t) atoll(fields[2]), now);
- cpu_stage (cpu, CPU_STATE_SYSTEM, (derive_t) atoll(fields[3]), now);
- cpu_stage (cpu, CPU_STATE_IDLE, (derive_t) atoll(fields[4]), now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_USER, (derive_t) atoll(fields[1]), now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_NICE, (derive_t) atoll(fields[2]), now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_SYSTEM, (derive_t) atoll(fields[3]), now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_IDLE, (derive_t) atoll(fields[4]), now);
if (numfields >= 8)
{
- cpu_stage (cpu, CPU_STATE_WAIT, (derive_t) atoll(fields[5]), now);
- cpu_stage (cpu, CPU_STATE_INTERRUPT, (derive_t) atoll(fields[6]), now);
- cpu_stage (cpu, CPU_STATE_SOFTIRQ, (derive_t) atoll(fields[7]), now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_WAIT, (derive_t) atoll(fields[5]), now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_INTERRUPT, (derive_t) atoll(fields[6]), now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_SOFTIRQ, (derive_t) atoll(fields[7]), now);
if (numfields >= 9)
- cpu_stage (cpu, CPU_STATE_STEAL, (derive_t) atoll(fields[8]), now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_STEAL, (derive_t) atoll(fields[8]), now);
}
}
fclose (fh);
if (kstat_read (kc, ksp[cpu], &cs) == -1)
continue; /* error message? */
- cpu_stage (ksp[cpu]->ks_instance, CPU_STATE_IDLE, (derive_t) cs.cpu_sysinfo.cpu[CPU_IDLE], now);
- cpu_stage (ksp[cpu]->ks_instance, CPU_STATE_USER, (derive_t) cs.cpu_sysinfo.cpu[CPU_USER], now);
- cpu_stage (ksp[cpu]->ks_instance, CPU_STATE_SYSTEM, (derive_t) cs.cpu_sysinfo.cpu[CPU_KERNEL], now);
- cpu_stage (ksp[cpu]->ks_instance, CPU_STATE_WAIT, (derive_t) cs.cpu_sysinfo.cpu[CPU_WAIT], now);
+ cpu_stage (ksp[cpu]->ks_instance, COLLECTD_CPU_STATE_IDLE, (derive_t) cs.cpu_sysinfo.cpu[CPU_IDLE], now);
+ cpu_stage (ksp[cpu]->ks_instance, COLLECTD_CPU_STATE_USER, (derive_t) cs.cpu_sysinfo.cpu[CPU_USER], now);
+ cpu_stage (ksp[cpu]->ks_instance, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cs.cpu_sysinfo.cpu[CPU_KERNEL], now);
+ cpu_stage (ksp[cpu]->ks_instance, COLLECTD_CPU_STATE_WAIT, (derive_t) cs.cpu_sysinfo.cpu[CPU_WAIT], now);
}
/* }}} #endif defined(HAVE_LIBKSTAT) */
}
for (i = 0; i < numcpu; i++) {
- cpu_stage (i, CPU_STATE_USER, (derive_t) cpuinfo[i][CP_USER], now);
- cpu_stage (i, CPU_STATE_NICE, (derive_t) cpuinfo[i][CP_NICE], now);
- cpu_stage (i, CPU_STATE_SYSTEM, (derive_t) cpuinfo[i][CP_SYS], now);
- cpu_stage (i, CPU_STATE_IDLE, (derive_t) cpuinfo[i][CP_IDLE], now);
- cpu_stage (i, CPU_STATE_INTERRUPT, (derive_t) cpuinfo[i][CP_INTR], now);
+ cpu_stage (i, COLLECTD_CPU_STATE_USER, (derive_t) cpuinfo[i][CP_USER], now);
+ cpu_stage (i, COLLECTD_CPU_STATE_NICE, (derive_t) cpuinfo[i][CP_NICE], now);
+ cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpuinfo[i][CP_SYS], now);
+ cpu_stage (i, COLLECTD_CPU_STATE_IDLE, (derive_t) cpuinfo[i][CP_IDLE], now);
+ cpu_stage (i, COLLECTD_CPU_STATE_INTERRUPT, (derive_t) cpuinfo[i][CP_INTR], now);
}
/* }}} #endif CAN_USE_SYSCTL */
}
for (i = 0; i < numcpu; i++) {
- cpu_stage (i, CPU_STATE_USER, (derive_t) cpuinfo[i][CP_USER], now);
- cpu_stage (i, CPU_STATE_NICE, (derive_t) cpuinfo[i][CP_NICE], now);
- cpu_stage (i, CPU_STATE_SYSTEM, (derive_t) cpuinfo[i][CP_SYS], now);
- cpu_stage (i, CPU_STATE_IDLE, (derive_t) cpuinfo[i][CP_IDLE], now);
- cpu_stage (i, CPU_STATE_INTERRUPT, (derive_t) cpuinfo[i][CP_INTR], now);
+ cpu_stage (i, COLLECTD_CPU_STATE_USER, (derive_t) cpuinfo[i][CP_USER], now);
+ cpu_stage (i, COLLECTD_CPU_STATE_NICE, (derive_t) cpuinfo[i][CP_NICE], now);
+ cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpuinfo[i][CP_SYS], now);
+ cpu_stage (i, COLLECTD_CPU_STATE_IDLE, (derive_t) cpuinfo[i][CP_IDLE], now);
+ cpu_stage (i, COLLECTD_CPU_STATE_INTERRUPT, (derive_t) cpuinfo[i][CP_INTR], now);
}
/* }}} #endif HAVE_SYSCTL_KERN_CP_TIMES */
return (-1);
}
- cpu_stage (0, CPU_STATE_USER, (derive_t) cpuinfo[CP_USER], now);
- cpu_stage (0, CPU_STATE_NICE, (derive_t) cpuinfo[CP_NICE], now);
- cpu_stage (0, CPU_STATE_SYSTEM, (derive_t) cpuinfo[CP_SYS], now);
- cpu_stage (0, CPU_STATE_IDLE, (derive_t) cpuinfo[CP_IDLE], now);
- cpu_stage (0, CPU_STATE_INTERRUPT, (derive_t) cpuinfo[CP_INTR], now);
+ cpu_stage (0, COLLECTD_CPU_STATE_USER, (derive_t) cpuinfo[CP_USER], now);
+ cpu_stage (0, COLLECTD_CPU_STATE_NICE, (derive_t) cpuinfo[CP_NICE], now);
+ cpu_stage (0, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpuinfo[CP_SYS], now);
+ cpu_stage (0, COLLECTD_CPU_STATE_IDLE, (derive_t) cpuinfo[CP_IDLE], now);
+ cpu_stage (0, COLLECTD_CPU_STATE_INTERRUPT, (derive_t) cpuinfo[CP_INTR], now);
/* }}} #endif HAVE_SYSCTLBYNAME */
#elif defined(HAVE_LIBSTATGRAB) /* {{{ */
return (-1);
}
- cpu_state (0, CPU_STATE_IDLE, (derive_t) cs->idle);
- cpu_state (0, CPU_STATE_NICE, (derive_t) cs->nice);
- cpu_state (0, CPU_STATE_SWAP, (derive_t) cs->swap);
- cpu_state (0, CPU_STATE_SYSTEM, (derive_t) cs->kernel);
- cpu_state (0, CPU_STATE_USER, (derive_t) cs->user);
- cpu_state (0, CPU_STATE_WAIT, (derive_t) cs->iowait);
+ cpu_state (0, COLLECTD_CPU_STATE_IDLE, (derive_t) cs->idle);
+ cpu_state (0, COLLECTD_CPU_STATE_NICE, (derive_t) cs->nice);
+ cpu_state (0, COLLECTD_CPU_STATE_SWAP, (derive_t) cs->swap);
+ cpu_state (0, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cs->kernel);
+ cpu_state (0, COLLECTD_CPU_STATE_USER, (derive_t) cs->user);
+ cpu_state (0, COLLECTD_CPU_STATE_WAIT, (derive_t) cs->iowait);
/* }}} #endif HAVE_LIBSTATGRAB */
#elif defined(HAVE_PERFSTAT) /* {{{ */
for (i = 0; i < cpus; i++)
{
- cpu_stage (i, CPU_STATE_IDLE, (derive_t) perfcpu[i].idle, now);
- cpu_stage (i, CPU_STATE_SYSTEM, (derive_t) perfcpu[i].sys, now);
- cpu_stage (i, CPU_STATE_USER, (derive_t) perfcpu[i].user, now);
- cpu_stage (i, CPU_STATE_WAIT, (derive_t) perfcpu[i].wait, now);
+ cpu_stage (i, COLLECTD_CPU_STATE_IDLE, (derive_t) perfcpu[i].idle, now);
+ cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM, (derive_t) perfcpu[i].sys, now);
+ cpu_stage (i, COLLECTD_CPU_STATE_USER, (derive_t) perfcpu[i].user, now);
+ cpu_stage (i, COLLECTD_CPU_STATE_WAIT, (derive_t) perfcpu[i].wait, now);
}
#endif /* }}} HAVE_PERFSTAT */
return (0);
} /* mysql_read_slave_stats */
+static int mysql_read_innodb_stats (mysql_database_t *db, MYSQL *con)
+{
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+
+ char *query;
+ struct {
+ char *key;
+ char *type;
+ int ds_type;
+ } metrics[] = {
+ { "metadata_mem_pool_size", "bytes", DS_TYPE_GAUGE },
+ { "lock_deadlocks", "mysql_locks", DS_TYPE_DERIVE },
+ { "lock_timeouts", "mysql_locks", DS_TYPE_DERIVE },
+ { "lock_row_lock_current_waits", "mysql_locks", DS_TYPE_DERIVE },
+ { "buffer_pool_size", "bytes", DS_TYPE_GAUGE },
+
+ { "buffer_pool_reads", "operations", DS_TYPE_DERIVE },
+ { "buffer_pool_read_requests", "operations", DS_TYPE_DERIVE },
+ { "buffer_pool_write_requests", "operations", DS_TYPE_DERIVE },
+ { "buffer_pool_wait_free", "operations", DS_TYPE_DERIVE },
+ { "buffer_pool_read_ahead", "operations", DS_TYPE_DERIVE },
+ { "buffer_pool_read_ahead_evicted", "operations", DS_TYPE_DERIVE },
+
+ { "buffer_pool_pages_total", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_pages_misc", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_pages_data", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_bytes_data", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_pages_dirty", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_bytes_dirty", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_pages_free", "gauge", DS_TYPE_GAUGE },
+
+ { "buffer_pages_created", "operations", DS_TYPE_DERIVE },
+ { "buffer_pages_written", "operations", DS_TYPE_DERIVE },
+ { "buffer_pages_read", "operations", DS_TYPE_DERIVE },
+ { "buffer_data_reads", "operations", DS_TYPE_DERIVE },
+ { "buffer_data_written", "operations", DS_TYPE_DERIVE },
+
+ { "os_data_reads", "operations", DS_TYPE_DERIVE },
+ { "os_data_writes", "operations", DS_TYPE_DERIVE },
+ { "os_data_fsyncs", "operations", DS_TYPE_DERIVE },
+ { "os_log_bytes_written", "operations", DS_TYPE_DERIVE },
+ { "os_log_fsyncs", "operations", DS_TYPE_DERIVE },
+ { "os_log_pending_fsyncs", "operations", DS_TYPE_DERIVE },
+ { "os_log_pending_writes", "operations", DS_TYPE_DERIVE },
+
+ { "trx_rseg_history_len", "gauge", DS_TYPE_GAUGE },
+
+ { "log_waits", "operations", DS_TYPE_DERIVE },
+ { "log_write_requests", "operations", DS_TYPE_DERIVE },
+ { "log_writes", "operations", DS_TYPE_DERIVE },
+ { "adaptive_hash_searches", "operations", DS_TYPE_DERIVE },
+
+ { "file_num_open_files", "gauge", DS_TYPE_GAUGE },
+
+ { "ibuf_merges_insert", "operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_delete_mark", "operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_delete", "operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_discard_insert", "operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_discard_delete_mark","operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_discard_delete", "operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_discard_merges", "operations", DS_TYPE_DERIVE },
+ { "ibuf_size", "bytes", DS_TYPE_GAUGE },
+
+ { "innodb_activity_count", "gauge", DS_TYPE_GAUGE },
+ { "innodb_dblwr_writes", "operations", DS_TYPE_DERIVE },
+ { "innodb_dblwr_pages_written", "operations", DS_TYPE_DERIVE },
+ { "innodb_dblwr_page_size", "gauge", DS_TYPE_GAUGE },
+
+ { "innodb_rwlock_s_spin_waits", "operations", DS_TYPE_DERIVE },
+ { "innodb_rwlock_x_spin_waits", "operations", DS_TYPE_DERIVE },
+ { "innodb_rwlock_s_spin_rounds", "operations", DS_TYPE_DERIVE },
+ { "innodb_rwlock_x_spin_rounds", "operations", DS_TYPE_DERIVE },
+ { "innodb_rwlock_s_os_waits", "operations", DS_TYPE_DERIVE },
+ { "innodb_rwlock_x_os_waits", "operations", DS_TYPE_DERIVE },
+
+ { "dml_reads", "operations", DS_TYPE_DERIVE },
+ { "dml_inserts", "operations", DS_TYPE_DERIVE },
+ { "dml_deletes", "operations", DS_TYPE_DERIVE },
+ { "dml_updates", "operations", DS_TYPE_DERIVE },
+
+ { NULL, NULL, 0}
+ };
+
+ query = "SELECT name, count, type FROM information_schema.innodb_metrics WHERE status = 'enabled'";
+
+ res = exec_query (con, query);
+ if (res == NULL)
+ return (-1);
+
+ while ((row = mysql_fetch_row (res)))
+ {
+ int i;
+ char *key;
+ unsigned long long val;
+
+ key = row[0];
+ val = atoll (row[1]);
+
+ for (i = 0;
+ metrics[i].key != NULL && strcmp(metrics[i].key, key) != 0;
+ i++)
+ ;
+
+ if (metrics[i].key == NULL)
+ continue;
+
+ switch (metrics[i].ds_type) {
+ case DS_TYPE_COUNTER:
+ counter_submit(metrics[i].type, key, (counter_t)val, db);
+ break;
+ case DS_TYPE_GAUGE:
+ gauge_submit(metrics[i].type, key, (gauge_t)val, db);
+ break;
+ case DS_TYPE_DERIVE:
+ derive_submit(metrics[i].type, key, (derive_t)val, db);
+ break;
+ }
+ }
+
+ mysql_free_result(res);
+ return (0);
+}
+
static int mysql_read (user_data_t *ud)
{
mysql_database_t *db;
unsigned long long traffic_incoming = 0ULL;
unsigned long long traffic_outgoing = 0ULL;
+ unsigned long mysql_version = 0ULL;
if ((ud == NULL) || (ud->data == NULL))
{
if ((con = getconnection (db)) == NULL)
return (-1);
+ mysql_version = mysql_get_server_version(con);
+
query = "SHOW STATUS";
- if (mysql_get_server_version (con) >= 50002)
+ if (mysql_version >= 50002)
query = "SHOW GLOBAL STATUS";
res = exec_query (con, query);
traffic_submit (traffic_incoming, traffic_outgoing, db);
+ if (mysql_version >= 50600 && db->innodb_stats)
+ mysql_read_innodb_stats (db, con);
+
if (db->master_stats)
mysql_read_master_stats (db, con);