diff options
author | Ole Troan <ot@cisco.com> | 2020-10-07 18:05:37 +0200 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2020-10-13 11:42:58 +0000 |
commit | 148c7b768721231325a349fa82db693190513b53 (patch) | |
tree | 94e0a9768eda3bc4923b1b3cc727dc637d877381 /src/vlib | |
parent | e7c8396982607634b4c747870499671ffa53868e (diff) |
stats: counters data model
This adds a new data model for counters.
Specifying the errors severity and unit.
A later patch will update vpp_get_stats to take advantage of this.
Only the map plugin is updates as an example.
New .api language:
A new "counters" keyword to define counter sets.
counters map {
none {
severity info;
type counter64;
units "packets";
description "valid MAP packets";
};
bad_protocol {
severity error;
type counter64;
units "packets";
description "bad protocol";
};
};
Each counter has 4 keywords. severity, which is one of error, info or warn.
A type, which is one of counter64 or gauge64.
units, which is a text field using units from YANG.
paths {
"/err/ip4-map" "map";
"/err/ip6-map" "map";
"/err/ip4-t-map" "map";
"/err/ip6-t-map" "map";
};
A new paths keyword that maps the counter-set to a path in the stats segment KV store.
Updated VPP CLI to include severity so user can see error counter severity.
DBGvpp# show errors
Count Node Reason Severity
13 ethernet-input no error error
Type: feature
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: Ib2177543f49d4c3aef4d7fa72476cff2068f7771
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vlib')
-rw-r--r-- | src/vlib/drop.c | 2 | ||||
-rw-r--r-- | src/vlib/error.c | 72 | ||||
-rw-r--r-- | src/vlib/error.h | 21 | ||||
-rw-r--r-- | src/vlib/node.c | 3 | ||||
-rw-r--r-- | src/vlib/node.h | 5 |
5 files changed, 76 insertions, 27 deletions
diff --git a/src/vlib/drop.c b/src/vlib/drop.c index e29195ad15d..3971123839d 100644 --- a/src/vlib/drop.c +++ b/src/vlib/drop.c @@ -93,7 +93,7 @@ format_error_trace (u8 * s, va_list * va) error_node = vlib_get_node (vm, vlib_error_get_node (&vm->node_main, e[0])); i = counter_index (vm, vlib_error_get_code (&vm->node_main, e[0])) + error_node->error_heap_index; - s = format (s, "%v: %s", error_node->name, em->error_strings_heap[i]); + s = format (s, "%v: %s", error_node->name, em->counters_heap[i].name); return s; } diff --git a/src/vlib/error.c b/src/vlib/error.c index 7357f17c278..1b3f3786371 100644 --- a/src/vlib/error.c +++ b/src/vlib/error.c @@ -115,7 +115,8 @@ vlib_error_drop_buffers (vlib_main_t * vm, /* Reserves given number of error codes for given node. */ void vlib_register_errors (vlib_main_t * vm, - u32 node_index, u32 n_errors, char *error_strings[]) + u32 node_index, u32 n_errors, char *error_strings[], + vl_counter_t counters[]) { vlib_error_main_t *em = &vm->error_main; vlib_node_main_t *nm = &vm->node_main; @@ -128,21 +129,33 @@ vlib_register_errors (vlib_main_t * vm, /* Free up any previous error strings. */ if (n->n_errors > 0) - heap_dealloc (em->error_strings_heap, n->error_heap_handle); - - n->n_errors = n_errors; - n->error_strings = error_strings; + heap_dealloc (em->counters_heap, n->error_heap_handle); if (n_errors == 0) return; - n->error_heap_index = - heap_alloc (em->error_strings_heap, n_errors, n->error_heap_handle); + n->n_errors = n_errors; - l = vec_len (em->error_strings_heap); + /* Legacy node */ + if (!counters) + { + counters = clib_mem_alloc (sizeof (counters[0]) * n_errors); + int i; + for (i = 0; i < n_errors; i++) + { + counters[i].name = error_strings[i]; // XXX Make name saner + counters[i].desc = error_strings[i]; + counters[i].severity = VL_COUNTER_SEVERITY_ERROR; + } + } - clib_memcpy (vec_elt_at_index (em->error_strings_heap, n->error_heap_index), - error_strings, n_errors * sizeof (error_strings[0])); + n->error_counters = counters; + + n->error_heap_index = + heap_alloc (em->counters_heap, n_errors, n->error_heap_handle); + l = vec_len (em->counters_heap); + clib_memcpy (vec_elt_at_index (em->counters_heap, n->error_heap_index), + counters, n_errors * sizeof (counters[0])); vec_validate (vm->error_elog_event_types, l - 1); @@ -170,7 +183,7 @@ vlib_register_errors (vlib_main_t * vm, { vec_reset_length (error_name); error_name = - format (error_name, "/err/%v/%s%c", n->name, error_strings[i], 0); + format (error_name, "/err/%v/%s%c", n->name, counters[i].name, 0); vlib_stats_register_error_index (oldheap, error_name, em->counters, n->error_heap_index + i); } @@ -191,13 +204,29 @@ vlib_register_errors (vlib_main_t * vm, for (i = 0; i < n_errors; i++) { t.format = (char *) format (0, "%v %s: %%d", - n->name, error_strings[i]); + n->name, counters[i].name); vm->error_elog_event_types[n->error_heap_index + i] = t; nm->node_by_error[n->error_heap_index + i] = n->index; } } } +static char * +sev2str (enum vl_counter_severity_e s) +{ + switch (s) + { + case VL_COUNTER_SEVERITY_ERROR: + return "error"; + case VL_COUNTER_SEVERITY_WARN: + return "warn"; + case VL_COUNTER_SEVERITY_INFO: + return "info"; + default: + return "unknown"; + } +} + static clib_error_t * show_errors (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) @@ -218,10 +247,11 @@ show_errors (vlib_main_t * vm, vec_validate (sums, vec_len (em->counters)); if (verbose) - vlib_cli_output (vm, "%=10s%=40s%=20s%=6s", "Count", "Node", "Reason", - "Index"); + vlib_cli_output (vm, "%=10s%=30s%=20s%=10s%=6s", "Count", "Node", + "Reason", "Severity", "Index"); else - vlib_cli_output (vm, "%=10s%=40s%=6s", "Count", "Node", "Reason"); + vlib_cli_output (vm, "%=10s%=30s%=20s%=10s", "Count", "Node", "Reason", + "Severity"); /* *INDENT-OFF* */ @@ -247,11 +277,13 @@ show_errors (vlib_main_t * vm, continue; if (verbose) - vlib_cli_output (vm, "%10lu%=40v%=20s%=6d", c, n->name, - em->error_strings_heap[i], i); + vlib_cli_output (vm, "%10lu%=30v%=20s%=10s%=6d", c, n->name, + em->counters_heap[i].name, + sev2str(em->counters_heap[i].severity), i); else - vlib_cli_output (vm, "%10lu%=40v%s", c, n->name, - em->error_strings_heap[i]); + vlib_cli_output (vm, "%10lu%=30v%=20s%=10s", c, n->name, + em->counters_heap[i].name, + sev2str(em->counters_heap[i].severity)); } } index++; @@ -271,7 +303,7 @@ show_errors (vlib_main_t * vm, { if (verbose) vlib_cli_output (vm, "%10lu%=40v%=20s%=10d", sums[i], n->name, - em->error_strings_heap[i], i); + em->counters_heap[i].name, i); } } } diff --git a/src/vlib/error.h b/src/vlib/error.h index 0da3a18d85d..11757e05f67 100644 --- a/src/vlib/error.h +++ b/src/vlib/error.h @@ -42,6 +42,20 @@ typedef u16 vlib_error_t; +enum vl_counter_severity_e +{ + VL_COUNTER_SEVERITY_ERROR, + VL_COUNTER_SEVERITY_WARN, + VL_COUNTER_SEVERITY_INFO, +}; + +typedef struct +{ + char *name; + char *desc; + enum vl_counter_severity_e severity; +} vl_counter_t; + typedef struct { /* Error counters. */ @@ -50,15 +64,16 @@ typedef struct /* Counter values as of last counter clear. */ u64 *counters_last_clear; - /* Error name strings in heap. Heap index + /* Counter structures in heap. Heap index indexes counter vector. */ - char **error_strings_heap; + vl_counter_t *counters_heap; } vlib_error_main_t; /* Per node error registration. */ void vlib_register_errors (struct vlib_main_t *vm, u32 node_index, - u32 n_errors, char *error_strings[]); + u32 n_errors, char *error_strings[], + vl_counter_t counters[]); #endif /* included_vlib_error_h */ diff --git a/src/vlib/node.c b/src/vlib/node.c index 00660373607..2c486433ff8 100644 --- a/src/vlib/node.c +++ b/src/vlib/node.c @@ -380,7 +380,8 @@ register_node (vlib_main_t * vm, vlib_node_registration_t * r) _(validate_frame); /* Register error counters. */ - vlib_register_errors (vm, n->index, r->n_errors, r->error_strings); + vlib_register_errors (vm, n->index, r->n_errors, r->error_strings, + r->error_counters); node_elog_init (vm, n->index); _(runtime_data_bytes); diff --git a/src/vlib/node.h b/src/vlib/node.h index f7155aeda86..6b9a2df95d3 100644 --- a/src/vlib/node.h +++ b/src/vlib/node.h @@ -116,6 +116,7 @@ typedef struct _vlib_node_registration /* Error strings indexed by error code for this node. */ char **error_strings; + vl_counter_t *error_counters; /* Buffer format/unformat for this node. */ format_function_t *format_buffer; @@ -323,8 +324,8 @@ typedef struct vlib_node_t u32 error_heap_handle; u32 error_heap_index; - /* Error strings indexed by error code for this node. */ - char **error_strings; + /* Counter structures indexed by counter code for this node. */ + vl_counter_t *error_counters; /* Vector of next node names. Only used before next_nodes array is initialized. */ |