This diff adds the required bits to export the bgpctl show metrics output
as openmetrics. For this /metrics needs to answer with a different
content-type. Apart from that adding this is trivial.
--
:wq Claudio
Index: bgplgd.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgplgd/bgplgd.c,v
retrieving revision 1.1
diff -u -p -r1.1 bgplgd.c
--- bgplgd.c 28 Jun 2022 16:11:30 -0000 1.1
+++ bgplgd.c 28 Sep 2022 12:34:23 -0000
@@ -26,12 +26,15 @@
#include "bgplgd.h"
#define NCMDARGS 4
+#define OMETRIC_TYPE \
+ "application/openmetrics-text; version=1.0.0; charset=utf-8"
const struct cmd {
const char *path;
char *args[NCMDARGS];
unsigned int qs_mask;
int barenbr;
+ const char *content_type;
} cmds[] = {
{ "/interfaces", { "show", "interfaces", NULL }, 0 },
{ "/memory", { "show", "rib", "memory", NULL }, 0 },
@@ -41,6 +44,7 @@ const struct cmd {
{ "/rtr", { "show", "rtr", NULL }, 0 },
{ "/sets", { "show", "sets", NULL }, 0 },
{ "/summary", { "show", NULL }, 0 },
+ { "/metrics", { "show", "metric", NULL }, 0, 0, OMETRIC_TYPE },
{ NULL }
};
@@ -107,7 +111,10 @@ bgpctl_call(struct lg_ctx *ctx)
signal(SIGPIPE, SIG_DFL);
/* Write server header first */
- printf("Content-type: application/json\r\n\r\n");
+ if (ctx->command->content_type == NULL)
+ printf("Content-type: application/json\r\n\r\n");
+ else
+ printf("Content-type: %s\r\n\r\n", ctx->command->content_type);
fflush(stdout);
execvp(bgpctlpath, argv);