- Fix contrib/metrics.awk for FreeBSD awk compatibility.

This commit is contained in:
W.C.A. Wijngaards 2020-11-27 15:08:31 +01:00
parent b2894e23a9
commit 56a80fbbf4
2 changed files with 8 additions and 15 deletions

View file

@ -7,7 +7,7 @@
# remote-control: control-enable: yes # remote-control: control-enable: yes
# Can use it like unbound-control stats | awk -f "metrics.awk" # Can use it like unbound-control stats | awk -f "metrics.awk"
BEGINFILE { BEGIN {
FS="="; FS="=";
} }
# everything like total.num.queries=value is put in val["total.num.queries"] # everything like total.num.queries=value is put in val["total.num.queries"]
@ -15,10 +15,7 @@ BEGINFILE {
val[$1]=$2; val[$1]=$2;
} }
# print the output metrics # print the output metrics
ENDFILE { END {
# sort array by index
asorti(val, sorted);
print "# HELP unbound_hits_queries Unbound DNS traffic and cache hits" print "# HELP unbound_hits_queries Unbound DNS traffic and cache hits"
print "# TYPE unbound_hits_queries gauge" print "# TYPE unbound_hits_queries gauge"
print "unbound_hits_queries{type=\"total.num.queries\"} " val["total.num.queries"]; print "unbound_hits_queries{type=\"total.num.queries\"} " val["total.num.queries"];
@ -73,8 +70,7 @@ ENDFILE {
print "# HELP unbound_by_type_queries Unbound DNS queries by type" print "# HELP unbound_by_type_queries Unbound DNS queries by type"
print "# TYPE unbound_by_type_queries gauge" print "# TYPE unbound_by_type_queries gauge"
for(s in sorted) { for(x in val) {
x = sorted[s];
if(x ~ /^num.query.type./) { if(x ~ /^num.query.type./) {
if(val[x] != "") { if(val[x] != "") {
split(x, a, "."); split(x, a, ".");
@ -86,8 +82,7 @@ ENDFILE {
print "# HELP unbound_by_class_queries Unbound DNS queries by class" print "# HELP unbound_by_class_queries Unbound DNS queries by class"
print "# TYPE unbound_by_class_queries gauge" print "# TYPE unbound_by_class_queries gauge"
for(s in sorted) { for(x in val) {
x = sorted[s];
if(x ~ /^num.query.class./) { if(x ~ /^num.query.class./) {
if(val[x] != "") { if(val[x] != "") {
split(x, a, "."); split(x, a, ".");
@ -99,8 +94,7 @@ ENDFILE {
print "# HELP unbound_by_opcode_queries Unbound DNS queries by opcode" print "# HELP unbound_by_opcode_queries Unbound DNS queries by opcode"
print "# TYPE unbound_by_opcode_queries gauge" print "# TYPE unbound_by_opcode_queries gauge"
for(s in sorted) { for(x in val) {
x = sorted[s];
if(x ~ /^num.query.opcode./) { if(x ~ /^num.query.opcode./) {
if(val[x] != "") { if(val[x] != "") {
split(x, a, "."); split(x, a, ".");
@ -112,8 +106,7 @@ ENDFILE {
print "# HELP unbound_by_rcode_queries Unbound DNS answers by rcode" print "# HELP unbound_by_rcode_queries Unbound DNS answers by rcode"
print "# TYPE unbound_by_rcode_queries gauge" print "# TYPE unbound_by_rcode_queries gauge"
for(s in sorted) { for(x in val) {
x = sorted[s];
if(x ~ /^num.answer.rcode./) { if(x ~ /^num.answer.rcode./) {
if(val[x] != "") { if(val[x] != "") {
split(x, a, "."); split(x, a, ".");
@ -125,8 +118,7 @@ ENDFILE {
print "# HELP unbound_by_flags_queries Unbound DNS queries by flags" print "# HELP unbound_by_flags_queries Unbound DNS queries by flags"
print "# TYPE unbound_by_flags_queries gauge" print "# TYPE unbound_by_flags_queries gauge"
for(s in sorted) { for(x in val) {
x = sorted[s];
if(x ~ /^num.query.flags./) { if(x ~ /^num.query.flags./) {
if(val[x] != "") { if(val[x] != "") {
split(x, a, "."); split(x, a, ".");

View file

@ -3,6 +3,7 @@
- Fix when use free buffer to initialize rbtree for stream reuse. - Fix when use free buffer to initialize rbtree for stream reuse.
- Fix compile warnings for windows. - Fix compile warnings for windows.
- Fix compile warnings in rpz initialization. - Fix compile warnings in rpz initialization.
- Fix contrib/metrics.awk for FreeBSD awk compatibility.
26 November 2020: Wouter 26 November 2020: Wouter
- Fix to omit UDP receive errors from log, if verbosity low. - Fix to omit UDP receive errors from log, if verbosity low.