Stats: vpp_prometheus_export fixes.
- Crash on /sys/nodes if per-node-counters off
- Require patterns parameters.
Change-Id: If4fddefb17504a92ba462c7af91e373601b66a5c
Signed-off-by: Ole Troan <ot@cisco.com>
diff --git a/src/vpp-api/client/stat_client.c b/src/vpp-api/client/stat_client.c
index b5aab74..a539fba 100644
--- a/src/vpp-api/client/stat_client.c
+++ b/src/vpp-api/client/stat_client.c
@@ -177,6 +177,8 @@
break;
case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
+ if (ep->offset == 0)
+ return result;
simple_c = stat_segment_pointer (sm->shared_header, ep->offset);
result.simple_counter_vec = vec_dup (simple_c);
offset_vector =
@@ -190,6 +192,8 @@
break;
case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
+ if (ep->offset == 0)
+ return result;
combined_c = stat_segment_pointer (sm->shared_header, ep->offset);
result.combined_counter_vec = vec_dup (combined_c);
offset_vector =
diff --git a/src/vpp/app/vpp_get_stats.c b/src/vpp/app/vpp_get_stats.c
index 1852b77..d500f8f 100644
--- a/src/vpp/app/vpp_get_stats.c
+++ b/src/vpp/app/vpp_get_stats.c
@@ -192,6 +192,8 @@
switch (res[i].type)
{
case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
+ if (res[i].simple_counter_vec == 0)
+ continue;
for (k = 0; k < vec_len (res[i].simple_counter_vec) - 1; k++)
for (j = 0; j < vec_len (res[i].simple_counter_vec[k]); j++)
fformat (stdout, "[%d @ %d]: %llu packets %s\n",
@@ -200,6 +202,8 @@
break;
case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
+ if (res[i].simple_counter_vec == 0)
+ continue;
for (k = 0; k < vec_len (res[i].combined_counter_vec); k++)
for (j = 0; j < vec_len (res[i].combined_counter_vec[k]); j++)
fformat (stdout, "[%d @ %d]: %llu packets, %llu bytes %s\n",
diff --git a/src/vpp/app/vpp_prometheus_export.c b/src/vpp/app/vpp_prometheus_export.c
index 65e0147..8d09bc2 100644
--- a/src/vpp/app/vpp_prometheus_export.c
+++ b/src/vpp/app/vpp_prometheus_export.c
@@ -257,6 +257,13 @@
}
}
+ if (vec_len (patterns) == 0)
+ {
+ fformat (stderr,
+ "%s: usage [socket-name <name>] <patterns> ...\n", argv[0]);
+ exit (1);
+ }
+
rv = stat_segment_connect ((char *) stat_segment_name);
if (rv)
{
@@ -280,7 +287,7 @@
}
else
{
- struct sockaddr_in6 clientaddr;
+ struct sockaddr_in6 clientaddr = { 0 };
char address[INET6_ADDRSTRLEN];
socklen_t addrlen;
getpeername (conn_sock, (struct sockaddr *) &clientaddr, &addrlen);