diff options
author | Damjan Marion <damarion@cisco.com> | 2022-03-01 15:51:18 +0100 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2022-03-09 13:51:31 +0000 |
commit | 8973b07eecbbfe23a5267975f8052a5c6339c756 (patch) | |
tree | fe4d3507ff24c18743d3241cd9ab049ee2add062 /src/vnet/devices | |
parent | 317cace6185ae134d78a38e1a20249baf751035e (diff) |
stats: refactor
Type: refactor
Change-Id: Ifd533a095d979dc55bfbe5fac7e0b7510a4d900c
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vnet/devices')
-rw-r--r-- | src/vnet/devices/devices.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/vnet/devices/devices.c b/src/vnet/devices/devices.c index 5c28cadc03c..1a4f02df6a8 100644 --- a/src/vnet/devices/devices.c +++ b/src/vnet/devices/devices.c @@ -18,6 +18,7 @@ #include <vnet/feature/feature.h> #include <vnet/ip/ip.h> #include <vnet/ethernet/ethernet.h> +#include <vlib/stats/stats.h> vnet_device_main_t vnet_device_main; @@ -101,12 +102,30 @@ VNET_FEATURE_INIT (ethernet_input, static) = { }; /* *INDENT-ON* */ +static void +input_rate_collector_fn (vlib_stats_collector_data_t *d) +{ + vlib_stats_segment_t *sm = vlib_stats_get_segment (); + vlib_stats_entry_t *e2 = sm->directory_vector + d->private_data; + static u64 last_input_packets = 0; + f64 dt, now; + + now = vlib_time_now (vlib_get_main ()); + u64 input_packets = vnet_get_aggregate_rx_packets (); + + dt = now - e2->value; + d->entry->value = (f64) (input_packets - last_input_packets) / dt; + last_input_packets = input_packets; + e2->value = now; +} + static clib_error_t * vnet_device_init (vlib_main_t * vm) { vnet_device_main_t *vdm = &vnet_device_main; vlib_thread_main_t *tm = vlib_get_thread_main (); vlib_thread_registration_t *tr; + vlib_stats_collector_reg_t reg = {}; uword *p; vec_validate_aligned (vdm->workers, tm->n_vlib_mains - 1, @@ -120,6 +139,12 @@ vnet_device_init (vlib_main_t * vm) vdm->next_worker_thread_index = tr->first_index; vdm->last_worker_thread_index = tr->first_index + tr->count - 1; } + + reg.private_data = vlib_stats_add_timestamp ("/sys/last_update"); + reg.entry_index = vlib_stats_add_gauge ("/sys/input_rate"); + reg.collect_fn = input_rate_collector_fn; + vlib_stats_register_collector_fn (®); + return 0; } |