stats: allow configuring poller delay 71/9671/14
authorKlement Sekera <ksekera@cisco.com>
Thu, 30 Nov 2017 06:00:31 +0000 (07:00 +0100)
committerDave Wallace <dwallacelf@gmail.com>
Fri, 16 Mar 2018 19:16:02 +0000 (19:16 +0000)
This introduces a startup config option for configuring stats poller delay.

Use `stats { interval <seconds> }` to configure the delay at startup.

The default value remains unchanged - 10 seconds.

Change-Id: If12cb1f7f6f1f8ecfa461561bc77847cdf260388
Signed-off-by: Klement Sekera <ksekera@cisco.com>
src/vnet/api_errno.h
src/vnet/bfd/bfd_cli.c
src/vpp/stats/stats.api
src/vpp/stats/stats.c

index 8c509d7..f928e0d 100644 (file)
 #ifndef included_vnet_api_errno_h
 #define included_vnet_api_errno_h
 
+#include <stdarg.h>
+#include <vppinfra/types.h>
+#include <vppinfra/format.h>
+
 #define foreach_vnet_api_error                                         \
 _(UNSPECIFIED, -1, "Unspecified Error")                                 \
 _(INVALID_SW_IF_INDEX, -2, "Invalid sw_if_index")                       \
@@ -147,6 +151,30 @@ typedef enum
     VNET_API_N_ERROR,
 } vnet_api_error_t;
 
+/* *INDENT-OFF* */
+static inline u8 *
+format_vnet_api_errno (u8 * s, va_list * args)
+{
+  vnet_api_error_t api_error = va_arg (*args, vnet_api_error_t);
+#ifdef _
+#undef _
+#endif
+#define _(a, b, c)           \
+  case b:                    \
+    s = format (s, "%s", c); \
+    break;
+  switch (api_error)
+    {
+      foreach_vnet_api_error
+      default:
+               s = format (s, "UNKNOWN");
+        break;
+    }
+  return s;
+#undef _
+}
+/* *INDENT-ON* */
+
 #endif /* included_vnet_api_errno_h */
 
 /*
index 33492ca..cab20a6 100644 (file)
@@ -218,22 +218,6 @@ VLIB_CLI_COMMAND (show_bfd_command, static) = {
 };
 /* *INDENT-ON* */
 
-static u8 *
-format_vnet_api_errno (u8 * s, va_list * args)
-{
-  vnet_api_error_t api_error = va_arg (*args, vnet_api_error_t);
-#define _(a, b, c)           \
-  case b:                    \
-    s = format (s, "%s", c); \
-    break;
-  switch (api_error)
-    {
-      foreach_vnet_api_error default:s = format (s, "UNKNOWN");
-      break;
-    }
-  return s;
-}
-
 static clib_error_t *
 bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
                 CLIB_UNUSED (vlib_cli_command_t * lmd))
index 2913d24..79816db 100644 (file)
@@ -414,6 +414,28 @@ define vnet_get_summary_stats_reply
   f64 vector_rate;
 };
 
+/** \brief Get delay between polling statistics
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+*/
+define stats_get_poller_delay
+{
+  u32 client_index;
+  u32 context;
+};
+
+/** \brief Get delay between polling statistics reply
+    @param context - sender context, to match reply w/ request
+    @param retval - return code for request
+    @param delay - poller delay
+*/
+define stats_get_poller_delay_reply
+{
+  u32 context;
+  i32 retval;
+  u32 delay;
+};
+
 /*
  * Local Variables:
  * eval: (c-set-style "gnu")
index ef9f61b..05950b6 100644 (file)
@@ -62,7 +62,8 @@ _(VNET_IP4_NBR_COUNTERS, vnet_ip4_nbr_counters)                               \
 _(WANT_IP4_NBR_STATS, want_ip4_nbr_stats)            \
 _(VNET_IP6_NBR_COUNTERS, vnet_ip6_nbr_counters) \
 _(WANT_IP6_NBR_STATS, want_ip6_nbr_stats) \
-_(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats)
+_(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
+_(STATS_GET_POLLER_DELAY, stats_get_poller_delay)
 
 
 #define vl_msg_name_crc_list
@@ -2068,6 +2069,78 @@ again:
     vl_msg_api_free (mp);
 }
 
+int
+stats_set_poller_delay (u32 poller_delay_sec)
+{
+  stats_main_t *sm = &stats_main;
+  if (!poller_delay_sec)
+    {
+      return VNET_API_ERROR_INVALID_ARGUMENT;
+    }
+  else
+    {
+      sm->stats_poll_interval_in_seconds = poller_delay_sec;
+      return 0;
+    }
+}
+
+static clib_error_t *
+stats_config (vlib_main_t * vm, unformat_input_t * input)
+{
+  u32 sec;
+
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (input, "interval %u", &sec))
+       {
+         int rv = stats_set_poller_delay (sec);
+         if (rv)
+           {
+             return clib_error_return (0,
+                                       "`stats_set_poller_delay' API call failed, rv=%d:%U",
+                                       (int) rv, format_vnet_api_errno, rv);
+           }
+         return 0;
+       }
+      else
+       {
+         return clib_error_return (0, "unknown input '%U'",
+                                   format_unformat_error, input);
+       }
+    }
+  return 0;
+}
+
+/* stats { ... } configuration. */
+/*?
+ *
+ * @cfgcmd{interval, &lt;seconds&gt;}
+ * Configure stats poller delay to be @c seconds.
+ *
+?*/
+VLIB_CONFIG_FUNCTION (stats_config, "stats");
+
+static void
+  vl_api_stats_get_poller_delay_t_handler
+  (vl_api_stats_get_poller_delay_t * mp)
+{
+  stats_main_t *sm = &stats_main;
+  vl_api_registration_t *reg;
+  reg = vl_api_client_index_to_registration (mp->client_index);
+  if (!reg)
+    return;
+  vl_api_stats_get_poller_delay_reply_t *rmp;
+
+  rmp = vl_msg_api_alloc (sizeof (*rmp));
+  rmp->_vl_msg_id = ntohs (VL_API_WANT_PER_INTERFACE_SIMPLE_STATS_REPLY);
+  rmp->context = mp->context;
+  rmp->retval = 0;
+  rmp->delay = clib_host_to_net_u32 (sm->stats_poll_interval_in_seconds);
+
+  vl_api_send_msg (reg, (u8 *) rmp);
+
+}
+
 static void
 stats_thread_fn (void *arg)
 {
@@ -2090,8 +2163,8 @@ stats_thread_fn (void *arg)
 
   while (1)
     {
-      /* 10 second poll interval */
-      ip46_fib_stats_delay (sm, 10 /* secs */ , 0 /* nsec */ );
+      ip46_fib_stats_delay (sm, sm->stats_poll_interval_in_seconds,
+                           0 /* nsec */ );
 
       if (!(sm->enable_poller))
        {