diff --git a/include/haproxy/stats-t.h b/include/haproxy/stats-t.h index e87743237..312013364 100644 --- a/include/haproxy/stats-t.h +++ b/include/haproxy/stats-t.h @@ -469,7 +469,7 @@ enum counters_type { COUNTERS_BE, COUNTERS_SV, COUNTERS_LI, - COUNTERS_DNS, + COUNTERS_RSLV, COUNTERS_OFF_END }; @@ -501,7 +501,7 @@ struct extra_counters { /* stats_domain is used in a flag as a 1 byte field */ enum stats_domain { STATS_DOMAIN_PROXY = 0, - STATS_DOMAIN_DNS, + STATS_DOMAIN_RESOLVERS, STATS_DOMAIN_COUNT, STATS_DOMAIN_MASK = 0xff diff --git a/src/resolvers.c b/src/resolvers.c index 9b45e8e7c..852c3d538 100644 --- a/src/resolvers.c +++ b/src/resolvers.c @@ -71,82 +71,82 @@ static void enter_resolver_code(); static void leave_resolver_code(); enum { - DNS_STAT_ID, - DNS_STAT_PID, - DNS_STAT_SENT, - DNS_STAT_SND_ERROR, - DNS_STAT_VALID, - DNS_STAT_UPDATE, - DNS_STAT_CNAME, - DNS_STAT_CNAME_ERROR, - DNS_STAT_ANY_ERR, - DNS_STAT_NX, - DNS_STAT_TIMEOUT, - DNS_STAT_REFUSED, - DNS_STAT_OTHER, - DNS_STAT_INVALID, - DNS_STAT_TOO_BIG, - DNS_STAT_TRUNCATED, - DNS_STAT_OUTDATED, - DNS_STAT_END, + RSLV_STAT_ID, + RSLV_STAT_PID, + RSLV_STAT_SENT, + RSLV_STAT_SND_ERROR, + RSLV_STAT_VALID, + RSLV_STAT_UPDATE, + RSLV_STAT_CNAME, + RSLV_STAT_CNAME_ERROR, + RSLV_STAT_ANY_ERR, + RSLV_STAT_NX, + RSLV_STAT_TIMEOUT, + RSLV_STAT_REFUSED, + RSLV_STAT_OTHER, + RSLV_STAT_INVALID, + RSLV_STAT_TOO_BIG, + RSLV_STAT_TRUNCATED, + RSLV_STAT_OUTDATED, + RSLV_STAT_END, }; -static struct name_desc dns_stats[] = { - [DNS_STAT_ID] = { .name = "id", .desc = "ID" }, - [DNS_STAT_PID] = { .name = "pid", .desc = "Parent ID" }, - [DNS_STAT_SENT] = { .name = "sent", .desc = "Sent" }, - [DNS_STAT_SND_ERROR] = { .name = "send_error", .desc = "Send error" }, - [DNS_STAT_VALID] = { .name = "valid", .desc = "Valid" }, - [DNS_STAT_UPDATE] = { .name = "update", .desc = "Update" }, - [DNS_STAT_CNAME] = { .name = "cname", .desc = "CNAME" }, - [DNS_STAT_CNAME_ERROR] = { .name = "cname_error", .desc = "CNAME error" }, - [DNS_STAT_ANY_ERR] = { .name = "any_err", .desc = "Any errors" }, - [DNS_STAT_NX] = { .name = "nx", .desc = "NX" }, - [DNS_STAT_TIMEOUT] = { .name = "timeout", .desc = "Timeout" }, - [DNS_STAT_REFUSED] = { .name = "refused", .desc = "Refused" }, - [DNS_STAT_OTHER] = { .name = "other", .desc = "Other" }, - [DNS_STAT_INVALID] = { .name = "invalid", .desc = "Invalid" }, - [DNS_STAT_TOO_BIG] = { .name = "too_big", .desc = "Too big" }, - [DNS_STAT_TRUNCATED] = { .name = "truncated", .desc = "Truncated" }, - [DNS_STAT_OUTDATED] = { .name = "outdated", .desc = "Outdated" }, +static struct name_desc resolv_stats[] = { + [RSLV_STAT_ID] = { .name = "id", .desc = "ID" }, + [RSLV_STAT_PID] = { .name = "pid", .desc = "Parent ID" }, + [RSLV_STAT_SENT] = { .name = "sent", .desc = "Sent" }, + [RSLV_STAT_SND_ERROR] = { .name = "send_error", .desc = "Send error" }, + [RSLV_STAT_VALID] = { .name = "valid", .desc = "Valid" }, + [RSLV_STAT_UPDATE] = { .name = "update", .desc = "Update" }, + [RSLV_STAT_CNAME] = { .name = "cname", .desc = "CNAME" }, + [RSLV_STAT_CNAME_ERROR] = { .name = "cname_error", .desc = "CNAME error" }, + [RSLV_STAT_ANY_ERR] = { .name = "any_err", .desc = "Any errors" }, + [RSLV_STAT_NX] = { .name = "nx", .desc = "NX" }, + [RSLV_STAT_TIMEOUT] = { .name = "timeout", .desc = "Timeout" }, + [RSLV_STAT_REFUSED] = { .name = "refused", .desc = "Refused" }, + [RSLV_STAT_OTHER] = { .name = "other", .desc = "Other" }, + [RSLV_STAT_INVALID] = { .name = "invalid", .desc = "Invalid" }, + [RSLV_STAT_TOO_BIG] = { .name = "too_big", .desc = "Too big" }, + [RSLV_STAT_TRUNCATED] = { .name = "truncated", .desc = "Truncated" }, + [RSLV_STAT_OUTDATED] = { .name = "outdated", .desc = "Outdated" }, }; static struct dns_counters dns_counters; -static void dns_fill_stats(void *d, struct field *stats) +static void resolv_fill_stats(void *d, struct field *stats) { struct dns_counters *counters = d; - stats[DNS_STAT_ID] = mkf_str(FO_CONFIG, counters->id); - stats[DNS_STAT_PID] = mkf_str(FO_CONFIG, counters->pid); - stats[DNS_STAT_SENT] = mkf_u64(FN_GAUGE, counters->sent); - stats[DNS_STAT_SND_ERROR] = mkf_u64(FN_GAUGE, counters->snd_error); - stats[DNS_STAT_VALID] = mkf_u64(FN_GAUGE, counters->app.resolver.valid); - stats[DNS_STAT_UPDATE] = mkf_u64(FN_GAUGE, counters->app.resolver.update); - stats[DNS_STAT_CNAME] = mkf_u64(FN_GAUGE, counters->app.resolver.cname); - stats[DNS_STAT_CNAME_ERROR] = mkf_u64(FN_GAUGE, counters->app.resolver.cname_error); - stats[DNS_STAT_ANY_ERR] = mkf_u64(FN_GAUGE, counters->app.resolver.any_err); - stats[DNS_STAT_NX] = mkf_u64(FN_GAUGE, counters->app.resolver.nx); - stats[DNS_STAT_TIMEOUT] = mkf_u64(FN_GAUGE, counters->app.resolver.timeout); - stats[DNS_STAT_REFUSED] = mkf_u64(FN_GAUGE, counters->app.resolver.refused); - stats[DNS_STAT_OTHER] = mkf_u64(FN_GAUGE, counters->app.resolver.other); - stats[DNS_STAT_INVALID] = mkf_u64(FN_GAUGE, counters->app.resolver.invalid); - stats[DNS_STAT_TOO_BIG] = mkf_u64(FN_GAUGE, counters->app.resolver.too_big); - stats[DNS_STAT_TRUNCATED] = mkf_u64(FN_GAUGE, counters->app.resolver.truncated); - stats[DNS_STAT_OUTDATED] = mkf_u64(FN_GAUGE, counters->app.resolver.outdated); + stats[RSLV_STAT_ID] = mkf_str(FO_CONFIG, counters->id); + stats[RSLV_STAT_PID] = mkf_str(FO_CONFIG, counters->pid); + stats[RSLV_STAT_SENT] = mkf_u64(FN_GAUGE, counters->sent); + stats[RSLV_STAT_SND_ERROR] = mkf_u64(FN_GAUGE, counters->snd_error); + stats[RSLV_STAT_VALID] = mkf_u64(FN_GAUGE, counters->app.resolver.valid); + stats[RSLV_STAT_UPDATE] = mkf_u64(FN_GAUGE, counters->app.resolver.update); + stats[RSLV_STAT_CNAME] = mkf_u64(FN_GAUGE, counters->app.resolver.cname); + stats[RSLV_STAT_CNAME_ERROR] = mkf_u64(FN_GAUGE, counters->app.resolver.cname_error); + stats[RSLV_STAT_ANY_ERR] = mkf_u64(FN_GAUGE, counters->app.resolver.any_err); + stats[RSLV_STAT_NX] = mkf_u64(FN_GAUGE, counters->app.resolver.nx); + stats[RSLV_STAT_TIMEOUT] = mkf_u64(FN_GAUGE, counters->app.resolver.timeout); + stats[RSLV_STAT_REFUSED] = mkf_u64(FN_GAUGE, counters->app.resolver.refused); + stats[RSLV_STAT_OTHER] = mkf_u64(FN_GAUGE, counters->app.resolver.other); + stats[RSLV_STAT_INVALID] = mkf_u64(FN_GAUGE, counters->app.resolver.invalid); + stats[RSLV_STAT_TOO_BIG] = mkf_u64(FN_GAUGE, counters->app.resolver.too_big); + stats[RSLV_STAT_TRUNCATED] = mkf_u64(FN_GAUGE, counters->app.resolver.truncated); + stats[RSLV_STAT_OUTDATED] = mkf_u64(FN_GAUGE, counters->app.resolver.outdated); } -static struct stats_module dns_stats_module = { - .name = "dns", - .domain_flags = STATS_DOMAIN_DNS << STATS_DOMAIN, - .fill_stats = dns_fill_stats, - .stats = dns_stats, - .stats_count = DNS_STAT_END, +static struct stats_module rslv_stats_module = { + .name = "resolvers", + .domain_flags = STATS_DOMAIN_RESOLVERS << STATS_DOMAIN, + .fill_stats = resolv_fill_stats, + .stats = resolv_stats, + .stats_count = RSLV_STAT_END, .counters = &dns_counters, .counters_size = sizeof(dns_counters), .clearable = 0, }; -INITCALL1(STG_REGISTER, stats_register_module, &dns_stats_module); +INITCALL1(STG_REGISTER, stats_register_module, &rslv_stats_module); /* Returns a pointer to the resolvers matching the id . NULL is returned if * no match is found. @@ -2730,7 +2730,7 @@ int resolv_allocate_counters(struct list *stat_modules) list_for_each_entry(resolvers, &sec_resolvers, list) { list_for_each_entry(ns, &resolvers->nameservers, list) { - EXTRA_COUNTERS_REGISTER(&ns->extra_counters, COUNTERS_DNS, + EXTRA_COUNTERS_REGISTER(&ns->extra_counters, COUNTERS_RSLV, alloc_failed); list_for_each_entry(mod, stat_modules, list) { @@ -2747,8 +2747,8 @@ int resolv_allocate_counters(struct list *stat_modules) mod->counters, mod->counters_size); /* Store the ns counters pointer */ - if (strcmp(mod->name, "dns") == 0) { - ns->counters = (struct dns_counters *)ns->extra_counters->data + mod->counters_off[COUNTERS_DNS]; + if (strcmp(mod->name, "resolvers") == 0) { + ns->counters = (struct dns_counters *)ns->extra_counters->data + mod->counters_off[COUNTERS_RSLV]; ns->counters->id = ns->id; ns->counters->pid = resolvers->id; } diff --git a/src/stats.c b/src/stats.c index 2705a17e3..d7f6be077 100644 --- a/src/stats.c +++ b/src/stats.c @@ -274,7 +274,7 @@ THREAD_LOCAL struct field *stat_l[STATS_DOMAIN_COUNT]; /* list of all registered stats module */ static struct list stats_module_list[STATS_DOMAIN_COUNT] = { LIST_HEAD_INIT(stats_module_list[STATS_DOMAIN_PROXY]), - LIST_HEAD_INIT(stats_module_list[STATS_DOMAIN_DNS]), + LIST_HEAD_INIT(stats_module_list[STATS_DOMAIN_RESOLVERS]), }; THREAD_LOCAL void *trash_counters; @@ -625,8 +625,8 @@ static int stats_dump_fields_typed(struct buffer *out, stats[ST_F_PID].u.u32); break; - case STATS_DOMAIN_DNS: - chunk_appendf(out, "D.%d.%s:", field, + case STATS_DOMAIN_RESOLVERS: + chunk_appendf(out, "N.%d.%s:", field, stat_f[domain][field].name); break; @@ -727,10 +727,10 @@ static void stats_print_proxy_field_json(struct buffer *out, obj_type, iid, sid, pos, name, pid); } -static void stats_print_dns_field_json(struct buffer *out, - const struct field *stat, - const char *name, - int pos) +static void stats_print_rslv_field_json(struct buffer *out, + const struct field *stat, + const char *name, + int pos) { chunk_appendf(out, "{" @@ -772,10 +772,10 @@ static int stats_dump_fields_json(struct buffer *out, stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32, stats[ST_F_PID].u.u32); - } else if (domain == STATS_DOMAIN_DNS) { - stats_print_dns_field_json(out, &stats[field], - stat_f[domain][field].name, - field); + } else if (domain == STATS_DOMAIN_RESOLVERS) { + stats_print_rslv_field_json(out, &stats[field], + stat_f[domain][field].name, + field); } if (old_len == out->data) @@ -3752,7 +3752,7 @@ static int stats_dump_stat_to_buffer(struct stream_interface *si, struct htx *ht case STAT_ST_LIST: switch (domain) { - case STATS_DOMAIN_DNS: + case STATS_DOMAIN_RESOLVERS: if (!stats_dump_resolvers(si, stat_l[domain], stat_count[domain], &stats_module_list[domain])) { @@ -4869,7 +4869,7 @@ static int cli_parse_clear_counters(char **args, char *payload, struct appctx *a } } - resolv_stats_clear_counters(clrall, &stats_module_list[STATS_DOMAIN_DNS]); + resolv_stats_clear_counters(clrall, &stats_module_list[STATS_DOMAIN_RESOLVERS]); memset(activity, 0, sizeof(activity)); return 1; @@ -4917,8 +4917,8 @@ static int cli_parse_show_stat(char **args, char *payload, struct appctx *appctx if (strcmp(args[arg], "proxy") == 0) { ++args; - } else if (strcmp(args[arg], "dns") == 0) { - appctx->ctx.stats.domain = STATS_DOMAIN_DNS; + } else if (strcmp(args[arg], "resolvers") == 0) { + appctx->ctx.stats.domain = STATS_DOMAIN_RESOLVERS; ++args; } else { return cli_err(appctx, "Invalid statistics domain.\n"); @@ -5100,28 +5100,28 @@ static int allocate_stats_px_postcheck(void) REGISTER_CONFIG_POSTPARSER("allocate-stats-px", allocate_stats_px_postcheck); -static int allocate_stats_dns_postcheck(void) +static int allocate_stats_rslv_postcheck(void) { struct stats_module *mod; size_t i = 0; int err_code = 0; - stat_f[STATS_DOMAIN_DNS] = malloc(stat_count[STATS_DOMAIN_DNS] * sizeof(struct name_desc)); - if (!stat_f[STATS_DOMAIN_DNS]) { - ha_alert("stats: cannot allocate all fields for dns statistics\n"); + stat_f[STATS_DOMAIN_RESOLVERS] = malloc(stat_count[STATS_DOMAIN_RESOLVERS] * sizeof(struct name_desc)); + if (!stat_f[STATS_DOMAIN_RESOLVERS]) { + ha_alert("stats: cannot allocate all fields for resolver statistics\n"); err_code |= ERR_ALERT | ERR_FATAL; return err_code; } - list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_DNS], list) { - memcpy(stat_f[STATS_DOMAIN_DNS] + i, + list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_RESOLVERS], list) { + memcpy(stat_f[STATS_DOMAIN_RESOLVERS] + i, mod->stats, mod->stats_count * sizeof(struct name_desc)); i += mod->stats_count; } - if (!resolv_allocate_counters(&stats_module_list[STATS_DOMAIN_DNS])) { - ha_alert("stats: cannot allocate all counters for dns statistics\n"); + if (!resolv_allocate_counters(&stats_module_list[STATS_DOMAIN_RESOLVERS])) { + ha_alert("stats: cannot allocate all counters for resolver statistics\n"); err_code |= ERR_ALERT | ERR_FATAL; return err_code; } @@ -5131,11 +5131,11 @@ static int allocate_stats_dns_postcheck(void) return err_code; } -REGISTER_CONFIG_POSTPARSER("allocate-stats-dns", allocate_stats_dns_postcheck); +REGISTER_CONFIG_POSTPARSER("allocate-stats-resolver", allocate_stats_rslv_postcheck); static int allocate_stat_lines_per_thread(void) { - int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_DNS }, i; + int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { const int domain = domains[i]; @@ -5152,7 +5152,7 @@ REGISTER_PER_THREAD_ALLOC(allocate_stat_lines_per_thread); static int allocate_trash_counters(void) { struct stats_module *mod; - int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_DNS }, i; + int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; size_t max_counters_size = 0; /* calculate the greatest counters used by any stats modules */ @@ -5179,7 +5179,7 @@ REGISTER_PER_THREAD_ALLOC(allocate_trash_counters); static void deinit_stat_lines_per_thread(void) { - int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_DNS }, i; + int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { const int domain = domains[i]; @@ -5193,7 +5193,7 @@ REGISTER_PER_THREAD_FREE(deinit_stat_lines_per_thread); static void deinit_stats(void) { - int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_DNS }, i; + int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { const int domain = domains[i];