1# read output of unbound-control stats 2# and output prometheus metrics style output. 3# use these options: 4# server: extended-statistics: yes 5# statistics-cumulative: no 6# statistics-interval: 0 7# remote-control: control-enable: yes 8# Can use it like unbound-control stats | awk -f "metrics.awk" 9 10BEGIN { 11 FS="="; 12} 13# everything like total.num.queries=value is put in val["total.num.queries"] 14/^.*\..*=/ { 15 val[$1]=$2; 16} 17# print the output metrics 18END { 19 print "# HELP unbound_hits_queries Unbound DNS traffic and cache hits" 20 print "# TYPE unbound_hits_queries gauge" 21 print "unbound_hits_queries{type=\"total.num.queries\"} " val["total.num.queries"]; 22 for (x=0; x<99; x++) { 23 if(val["thread" $x ".num.queries"] != "") { 24 print "unbound_hits_queries{type=\"thread" $x ".num.queries\"} " val["thread" $x ".num.queries"]; 25 } 26 } 27 print "unbound_hits_queries{type=\"total.num.cachehits\"} " val["total.num.cachehits"]; 28 print "unbound_hits_queries{type=\"total.num.prefetch\"} " val["total.num.prefetch"]; 29 print "unbound_hits_queries{type=\"num.query.tcp\"} " val["num.query.tcp"]; 30 print "unbound_hits_queries{type=\"num.query.tcpout\"} " val["num.query.tcpout"]; 31 print "unbound_hits_queries{type=\"num.query.udpout\"} " val["num.query.udpout"]; 32 print "unbound_hits_queries{type=\"num.query.tls\"} " val["num.query.tls"]; 33 print "unbound_hits_queries{type=\"num.query.tls.resume\"} " val["num.query.tls.resume"]; 34 print "unbound_hits_queries{type=\"num.query.ipv6\"} " val["num.query.ipv6"]; 35 print "unbound_hits_queries{type=\"unwanted.queries\"} " val["unwanted.queries"]; 36 print "" 37 38 print "# HELP unbound_queue_queries Unbound requestlist size" 39 print "# TYPE unbound_queue_queries gauge" 40 print "unbound_queue_queries{type=\"total.requestlist.avg\"} " val["total.requestlist.avg"]; 41 print "unbound_queue_queries{type=\"total.requestlist.max\"} " val["total.requestlist.max"]; 42 print "unbound_queue_queries{type=\"total.requestlist.overwritten\"} " val["total.requestlist.overwritten"]; 43 print "unbound_queue_queries{type=\"total.requestlist.exceeded\"} " val["total.requestlist.exceeded"]; 44 print "" 45 46 print "# HELP unbound_memory_bytes Unbound memory usage" 47 print "# TYPE unbound_memory_bytes gauge" 48 print "unbound_memory_bytes{type=\"mem.cache.rrset\"} " val["mem.cache.rrset"]; 49 print "unbound_memory_bytes{type=\"mem.cache.message\"} " val["mem.cache.message"]; 50 print "unbound_memory_bytes{type=\"mem.mod.iterator\"} " val["mem.mod.iterator"]; 51 if(val["mem.mod.validator"] != "") { 52 print "unbound_memory_bytes{type=\"mem.mod.validator\"} " val["mem.mod.validator"]; 53 } 54 if(val["mem.mod.respip"] != "") { 55 print "unbound_memory_bytes{type=\"mem.mod.respip\"} " val["mem.mod.respip"]; 56 } 57 if(val["mem.mod.subnet"] != "") { 58 print "unbound_memory_bytes{type=\"mem.mod.subnet\"} " val["mem.mod.subnet"]; 59 } 60 if(val["mem.mod.ipsecmod"] != "") { 61 print "unbound_memory_bytes{type=\"mem.mod.ipsecmod\"} " val["mem.mod.ipsecmod"]; 62 } 63 if(val["mem.mod.dynlibmod"] != "") { 64 print "unbound_memory_bytes{type=\"mem.mod.dynlibmod\"} " val["mem.mod.dynlibmod"]; 65 } 66 print "unbound_memory_bytes{type=\"msg.cache.count\"} " val["msg.cache.count"]; 67 print "unbound_memory_bytes{type=\"rrset.cache.count\"} " val["rrset.cache.count"]; 68 print "unbound_memory_bytes{type=\"infra.cache.count\"} " val["infra.cache.count"]; 69 print "unbound_memory_bytes{type=\"key.cache.count\"} " val["key.cache.count"]; 70 print "" 71 72 print "# HELP unbound_by_type_queries Unbound DNS queries by type" 73 print "# TYPE unbound_by_type_queries gauge" 74 for(x in val) { 75 if(x ~ /^num.query.type./) { 76 if(val[x] != "") { 77 split(x, a, "."); 78 print "unbound_by_type_queries{type=\"" a[4] "\"} " val[x]; 79 } 80 } 81 } 82 print "" 83 84 print "# HELP unbound_by_class_queries Unbound DNS queries by class" 85 print "# TYPE unbound_by_class_queries gauge" 86 for(x in val) { 87 if(x ~ /^num.query.class./) { 88 if(val[x] != "") { 89 split(x, a, "."); 90 print "unbound_by_class_queries{class=\"" a[4] "\"} " val[x]; 91 } 92 } 93 } 94 print "" 95 96 print "# HELP unbound_by_opcode_queries Unbound DNS queries by opcode" 97 print "# TYPE unbound_by_opcode_queries gauge" 98 for(x in val) { 99 if(x ~ /^num.query.opcode./) { 100 if(val[x] != "") { 101 split(x, a, "."); 102 print "unbound_by_opcode_queries{opcode=\"" a[4] "\"} " val[x]; 103 } 104 } 105 } 106 print "" 107 108 print "# HELP unbound_by_rcode_queries Unbound DNS answers by rcode" 109 print "# TYPE unbound_by_rcode_queries gauge" 110 for(x in val) { 111 if(x ~ /^num.answer.rcode./) { 112 if(val[x] != "") { 113 split(x, a, "."); 114 print "unbound_by_rcode_queries{rcode=\"" a[4] "\"} " val[x]; 115 } 116 } 117 } 118 print "" 119 120 print "# HELP unbound_by_flags_queries Unbound DNS queries by flags" 121 print "# TYPE unbound_by_flags_queries gauge" 122 for(x in val) { 123 if(x ~ /^num.query.flags./) { 124 if(val[x] != "") { 125 split(x, a, "."); 126 print "unbound_by_flags_queries{flag=\"" a[4] "\"} " val[x]; 127 } 128 } 129 } 130 if(val["num.query.edns.present"] != "") { 131 print "unbound_by_flags_queries{flag=\"num.query.edns.present\"} " val["num.query.edns.present"]; 132 } 133 if(val["num.query.edns.DO"] != "") { 134 print "unbound_by_flags_queries{flag=\"num.query.edns.DO\"} " val["num.query.edns.DO"]; 135 } 136 print "" 137 138 print "# HELP unbound_histogram_seconds Unbound DNS histogram of reply time" 139 print "# TYPE unbound_histogram_seconds gauge" 140 print "unbound_histogram_seconds{bucket=\"000000.000000.to.000000.000001\"} " val["histogram.000000.000000.to.000000.000001"]; 141 print "unbound_histogram_seconds{bucket=\"000000.000001.to.000000.000002\"} " val["histogram.000000.000001.to.000000.000002"]; 142 print "unbound_histogram_seconds{bucket=\"000000.000002.to.000000.000004\"} " val["histogram.000000.000002.to.000000.000004"]; 143 print "unbound_histogram_seconds{bucket=\"000000.000004.to.000000.000008\"} " val["histogram.000000.000004.to.000000.000008"]; 144 print "unbound_histogram_seconds{bucket=\"000000.000008.to.000000.000016\"} " val["histogram.000000.000008.to.000000.000016"]; 145 print "unbound_histogram_seconds{bucket=\"000000.000016.to.000000.000032\"} " val["histogram.000000.000016.to.000000.000032"]; 146 print "unbound_histogram_seconds{bucket=\"000000.000032.to.000000.000064\"} " val["histogram.000000.000032.to.000000.000064"]; 147 print "unbound_histogram_seconds{bucket=\"000000.000064.to.000000.000128\"} " val["histogram.000000.000064.to.000000.000128"]; 148 print "unbound_histogram_seconds{bucket=\"000000.000128.to.000000.000256\"} " val["histogram.000000.000128.to.000000.000256"]; 149 print "unbound_histogram_seconds{bucket=\"000000.000256.to.000000.000512\"} " val["histogram.000000.000256.to.000000.000512"]; 150 print "unbound_histogram_seconds{bucket=\"000000.000512.to.000000.001024\"} " val["histogram.000000.000512.to.000000.001024"]; 151 print "unbound_histogram_seconds{bucket=\"000000.001024.to.000000.002048\"} " val["histogram.000000.001024.to.000000.002048"]; 152 print "unbound_histogram_seconds{bucket=\"000000.002048.to.000000.004096\"} " val["histogram.000000.002048.to.000000.004096"]; 153 print "unbound_histogram_seconds{bucket=\"000000.004096.to.000000.008192\"} " val["histogram.000000.004096.to.000000.008192"]; 154 print "unbound_histogram_seconds{bucket=\"000000.008192.to.000000.016384\"} " val["histogram.000000.008192.to.000000.016384"]; 155 print "unbound_histogram_seconds{bucket=\"000000.016384.to.000000.032768\"} " val["histogram.000000.016384.to.000000.032768"]; 156 print "unbound_histogram_seconds{bucket=\"000000.032768.to.000000.065536\"} " val["histogram.000000.032768.to.000000.065536"]; 157 print "unbound_histogram_seconds{bucket=\"000000.065536.to.000000.131072\"} " val["histogram.000000.065536.to.000000.131072"]; 158 print "unbound_histogram_seconds{bucket=\"000000.131072.to.000000.262144\"} " val["histogram.000000.131072.to.000000.262144"]; 159 print "unbound_histogram_seconds{bucket=\"000000.262144.to.000000.524288\"} " val["histogram.000000.262144.to.000000.524288"]; 160 print "unbound_histogram_seconds{bucket=\"000000.524288.to.000001.000000\"} " val["histogram.000000.524288.to.000001.000000"]; 161 print "unbound_histogram_seconds{bucket=\"000001.000000.to.000002.000000\"} " val["histogram.000001.000000.to.000002.000000"]; 162 print "unbound_histogram_seconds{bucket=\"000002.000000.to.000004.000000\"} " val["histogram.000002.000000.to.000004.000000"]; 163 print "unbound_histogram_seconds{bucket=\"000004.000000.to.000008.000000\"} " val["histogram.000004.000000.to.000008.000000"]; 164 print "unbound_histogram_seconds{bucket=\"000008.000000.to.000016.000000\"} " val["histogram.000008.000000.to.000016.000000"]; 165 print "unbound_histogram_seconds{bucket=\"000016.000000.to.000032.000000\"} " val["histogram.000016.000000.to.000032.000000"]; 166 print "unbound_histogram_seconds{bucket=\"000032.000000.to.000064.000000\"} " val["histogram.000032.000000.to.000064.000000"]; 167 print "unbound_histogram_seconds{bucket=\"000064.000000.to.000128.000000\"} " val["histogram.000064.000000.to.000128.000000"]; 168 print "unbound_histogram_seconds{bucket=\"000128.000000.to.000256.000000\"} " val["histogram.000128.000000.to.000256.000000"]; 169 print "unbound_histogram_seconds{bucket=\"000256.000000.to.000512.000000\"} " val["histogram.000256.000000.to.000512.000000"]; 170 print "unbound_histogram_seconds{bucket=\"000512.000000.to.001024.000000\"} " val["histogram.000512.000000.to.001024.000000"]; 171 print "unbound_histogram_seconds{bucket=\"001024.000000.to.002048.000000\"} " val["histogram.001024.000000.to.002048.000000"]; 172 print "unbound_histogram_seconds{bucket=\"002048.000000.to.004096.000000\"} " val["histogram.002048.000000.to.004096.000000"]; 173 print "unbound_histogram_seconds{bucket=\"004096.000000.to.008192.000000\"} " val["histogram.004096.000000.to.008192.000000"]; 174 print "unbound_histogram_seconds{bucket=\"008192.000000.to.016384.000000\"} " val["histogram.008192.000000.to.016384.000000"]; 175 print "unbound_histogram_seconds{bucket=\"016384.000000.to.032768.000000\"} " val["histogram.016384.000000.to.032768.000000"]; 176 print "unbound_histogram_seconds{bucket=\"032768.000000.to.065536.000000\"} " val["histogram.032768.000000.to.065536.000000"]; 177 print "unbound_histogram_seconds{bucket=\"065536.000000.to.131072.000000\"} " val["histogram.065536.000000.to.131072.000000"]; 178 print "unbound_histogram_seconds{bucket=\"131072.000000.to.262144.000000\"} " val["histogram.131072.000000.to.262144.000000"]; 179 print "unbound_histogram_seconds{bucket=\"262144.000000.to.524288.000000\"} " val["histogram.262144.000000.to.524288.000000"]; 180 print "" 181} 182