|
18 | 18 | #include <errno.h> |
19 | 19 | #include <event2/event.h> |
20 | 20 | #include <event2/http.h> |
| 21 | +#include <ctype.h> |
21 | 22 |
|
22 | 23 | #include "nsd.h" |
23 | 24 | #include "xfrd.h" |
@@ -343,6 +344,22 @@ metrics_http_callback(struct evhttp_request *req, void *p) |
343 | 344 | } |
344 | 345 |
|
345 | 346 | #ifdef BIND8_STATS |
| 347 | +/** Change disallowed characters, '.' ':' to underscores '_'. */ |
| 348 | +static void |
| 349 | +change_string_underscores(char* prefix) |
| 350 | +{ |
| 351 | + /* Prometheus does not want '.' in the metric names. But the zone |
| 352 | + * statistics could have then in their name. |
| 353 | + * Also ':' is not allowed. This routine enforeces that it |
| 354 | + * has letters,digits,underscores. */ |
| 355 | + char* s = prefix; |
| 356 | + while(*s) { |
| 357 | + if(!isalnum((unsigned char)*s) && *s != '_') |
| 358 | + *s = '_'; |
| 359 | + s++; |
| 360 | + } |
| 361 | +} |
| 362 | + |
346 | 363 | /** print long number*/ |
347 | 364 | static int |
348 | 365 | print_longnum(struct evbuffer *buf, char* desc, uint64_t x) |
@@ -381,6 +398,7 @@ print_stat_block(struct evbuffer *buf, struct nsdst* st, |
381 | 398 | char prefix[512] = {0}; |
382 | 399 | if (name) { |
383 | 400 | snprintf(prefix, sizeof(prefix), "nsd_zonestats_%s_", name); |
| 401 | + change_string_underscores(prefix); |
384 | 402 | } else { |
385 | 403 | snprintf(prefix, sizeof(prefix), "nsd_"); |
386 | 404 | } |
@@ -504,6 +522,7 @@ metrics_zonestat_print_one(struct evbuffer *buf, char *name, |
504 | 522 | { |
505 | 523 | char prefix[512] = {0}; |
506 | 524 | snprintf(prefix, sizeof(prefix), "nsd_zonestats_%s_", name); |
| 525 | + change_string_underscores(prefix); |
507 | 526 |
|
508 | 527 | print_metric_help_and_type(buf, prefix, "queries_total", |
509 | 528 | "Total number of queries received.", "counter"); |
|
0 commit comments