Code

routeros plugin: Add registration table statistics.
authorFlorian Forster <octo@huhu.verplant.org>
Sat, 28 Nov 2009 20:33:28 +0000 (21:33 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Sat, 28 Nov 2009 20:33:28 +0000 (21:33 +0100)
src/routeros.c
src/types.db

index 3e5e6680e6031df93d22d90aa7c0e97b90f1a971..93c281272570b14435bea7ce42d2b3b4a1ad6c87 100644 (file)
@@ -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 */
 
index c8c6b98aa7a73337a68252e73c0c33feb4727498..d8a39d64a53ee2ccd9ad2b7926cae887bdc6c32b 100644 (file)
@@ -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