From 57164e9952118e81768f2ae1366bb1ceba490618 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 28 Nov 2009 21:33:28 +0100 Subject: [PATCH] routeros plugin: Add registration table statistics. --- src/routeros.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++- src/types.db | 1 + 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/routeros.c b/src/routeros.c index 3e5e6680..93c28127 100644 --- a/src/routeros.c +++ b/src/routeros.c @@ -81,6 +81,69 @@ static int handle_interface (__attribute__((unused)) ros_connection_t *c, /* {{{ return (0); } /* }}} int handle_interface */ +static void cr_submit_gauge (const char *type, /* {{{ */ + const char *type_instance, gauge_t value) +{ + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].gauge = value; + + vl.values = values; + vl.values_len = STATIC_ARRAY_SIZE (values); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "routeros", sizeof (vl.plugin)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + + plugin_dispatch_values (&vl); +} /* }}} void cr_submit_gauge */ + +static void submit_regtable (const ros_registration_table_t *r) /* {{{ */ +{ + char type_instance[DATA_MAX_NAME_LEN]; + + if (r == NULL) + return; + + /*** RX ***/ + ssnprintf (type_instance, sizeof (type_instance), "%s-%s-rx", + r->interface, r->radio_name); + cr_submit_gauge ("bitrate", type_instance, + (gauge_t) (1000000.0 * r->rx_rate)); + cr_submit_gauge ("signal_power", type_instance, + (gauge_t) r->rx_signal_strength); + cr_submit_gauge ("signal_quality", type_instance, + (gauge_t) r->rx_ccq); + + /*** TX ***/ + ssnprintf (type_instance, sizeof (type_instance), "%s-%s-tx", + r->interface, r->radio_name); + cr_submit_gauge ("bitrate", type_instance, + (gauge_t) (1000000.0 * r->tx_rate)); + cr_submit_gauge ("signal_power", type_instance, + (gauge_t) r->tx_signal_strength); + cr_submit_gauge ("signal_quality", type_instance, + (gauge_t) r->tx_ccq); + + /*** RX / TX ***/ + ssnprintf (type_instance, sizeof (type_instance), "%s-%s", + r->interface, r->radio_name); + cr_submit_io ("if_octets", type_instance, + (counter_t) r->rx_bytes, (counter_t) r->tx_bytes); + cr_submit_gauge ("snr", type_instance, (gauge_t) r->signal_to_noise); + + submit_regtable (r->next); +} /* }}} void submit_regtable */ + +static int handle_regtable (__attribute__((unused)) ros_connection_t *c, /* {{{ */ + const ros_registration_table_t *r, + __attribute__((unused)) void *user_data) +{ + submit_regtable (r); + return (0); +} /* }}} int handle_regtable */ + static int cr_read (void) /* {{{ */ { int status; @@ -99,7 +162,8 @@ static int cr_read (void) /* {{{ */ } assert (connection != NULL); - status = ros_interface (connection, handle_interface, /* user data = */ NULL); + status = ros_interface (connection, handle_interface, + /* user data = */ NULL); if (status != 0) { char errbuf[128]; @@ -110,6 +174,18 @@ static int cr_read (void) /* {{{ */ return (-1); } + status = ros_registration_table (connection, handle_regtable, + /* user data = */ NULL); + if (status != 0) + { + char errbuf[128]; + ERROR ("routeros plugin: ros_registration_table failed: %s", + sstrerror (status, errbuf, sizeof (errbuf))); + ros_disconnect (connection); + connection = NULL; + return (-1); + } + return (0); } /* }}} int cr_read */ diff --git a/src/types.db b/src/types.db index c8c6b98a..d8a39d64 100644 --- a/src/types.db +++ b/src/types.db @@ -139,6 +139,7 @@ serial_octets rx:COUNTER:0:4294967295, tx:COUNTER:0:4294967295 signal_noise value:GAUGE:U:0 signal_power value:GAUGE:U:0 signal_quality value:GAUGE:0:U +snr value:GAUGE:0:U spam_check value:GAUGE:0:U spam_score value:GAUGE:U:U swap_io value:DERIVE:0:1099511627776 -- 2.30.2