diff --git a/bind_exporter_test.go b/bind_exporter_test.go index 98f09bb..e8fe67f 100644 --- a/bind_exporter_test.go +++ b/bind_exporter_test.go @@ -70,14 +70,92 @@ var ( `bind_tasks_running 8`, `bind_worker_threads 16`, } + trafficStats = []string{ + `bind_traffic_received_size_bucket{transport="tcpv4",le="+Inf"} 0`, + `bind_traffic_received_size_sum{transport="tcpv4"} NaN`, + `bind_traffic_received_size_count{transport="tcpv4"} 0`, + `bind_traffic_received_size_bucket{transport="udpv4",le="31"} 9992`, + `bind_traffic_received_size_bucket{transport="udpv4",le="47"} 82206`, + `bind_traffic_received_size_bucket{transport="udpv4",le="63"} 108619`, + `bind_traffic_received_size_bucket{transport="udpv4",le="79"} 109630`, + `bind_traffic_received_size_bucket{transport="udpv4",le="95"} 109683`, + `bind_traffic_received_size_bucket{transport="udpv4",le="111"} 109688`, + `bind_traffic_received_size_bucket{transport="udpv4",le="127"} 109691`, + `bind_traffic_received_size_bucket{transport="udpv4",le="+Inf"} 109691`, + `bind_traffic_received_size_sum{transport="udpv4"} NaN`, + `bind_traffic_received_size_count{transport="udpv4"} 109691`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="31"} 28`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="47"} 231`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="63"} 16733`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="79"} 30487`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="95"} 49751`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="111"} 63255`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="127"} 72236`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="143"} 87215`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="159"} 94972`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="175"} 104161`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="191"} 111804`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="207"} 118777`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="223"} 121560`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="239"} 126934`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="255"} 129430`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="271"} 131161`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="287"} 131623`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="303"} 132135`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="319"} 133212`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="335"} 134165`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="351"} 134176`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="367"} 134485`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="383"} 134591`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="399"} 134671`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="415"} 134680`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="447"} 134801`, + `bind_traffic_sent_size_bucket{transport="tcpv4",le="+Inf"} 134801`, + `bind_traffic_sent_size_sum{transport="tcpv4"} NaN`, + `bind_traffic_sent_size_count{transport="tcpv4"} 134801`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="31"} 11`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="47"} 666`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="63"} 10038`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="79"} 18547`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="95"} 34436`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="111"} 53146`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="127"} 59515`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="143"} 66961`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="159"} 72058`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="175"} 78111`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="191"} 82872`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="207"} 85954`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="223"} 89229`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="239"} 93461`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="255"} 94787`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="271"} 96226`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="287"} 96579`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="303"} 97020`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="319"} 97653`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="335"} 97685`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="351"} 97701`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="367"} 97717`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="383"} 97793`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="399"} 97820`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="415"} 97860`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="431"} 97899`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="447"} 97918`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="479"} 97951`, + `bind_traffic_sent_size_bucket{transport="udpv4",le="+Inf"} 97951`, + `bind_traffic_sent_size_sum{transport="udpv4"} NaN`, + `bind_traffic_sent_size_count{transport="udpv4"} 97951`, + `bind_traffic_sent_size_bucket{transport="udpv6",le="+Inf"} 0`, + `bind_traffic_sent_size_sum{transport="udpv6"} NaN`, + `bind_traffic_sent_size_count{transport="udpv6"} 0`, + } ) func TestBindExporterJSONClient(t *testing.T) { bindExporterTest{ server: newJSONServer(), - groups: []bind.StatisticGroup{bind.ServerStats, bind.ViewStats, bind.TaskStats}, + groups: []bind.StatisticGroup{bind.ServerStats, bind.ViewStats, bind.TaskStats, bind.TrafficStats}, version: "json", - include: combine([]string{`bind_up 1`}, serverStats, viewStats, taskStats), + include: combine([]string{`bind_up 1`}, serverStats, viewStats, taskStats, trafficStats), }.run(t) } @@ -172,9 +250,10 @@ func newV3Server() *httptest.Server { func newJSONServer() *httptest.Server { m := map[string]string{ - "/json/v1/server": "fixtures/json/server.json", - "/json/v1/tasks": "fixtures/json/tasks.json", - "/json/v1/zones": "fixtures/json/zones.json", + "/json/v1/server": "fixtures/json/server.json", + "/json/v1/tasks": "fixtures/json/tasks.json", + "/json/v1/traffic": "fixtures/json/traffic.json", + "/json/v1/zones": "fixtures/json/zones.json", } return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if f, ok := m[r.RequestURI]; ok { diff --git a/fixtures/json/traffic.json b/fixtures/json/traffic.json new file mode 100644 index 0000000..6c43100 --- /dev/null +++ b/fixtures/json/traffic.json @@ -0,0 +1,87 @@ +{ + "json-stats-version":"1.8", + "boot-time":"2024-02-04T17:26:28.754Z", + "config-time":"2024-02-04T17:26:28.846Z", + "current-time":"2024-02-16T23:34:43.797Z", + "version":"9.19.19-1-Debian", + "traffic":{ + "dns-udp-requests-sizes-received-ipv4":{ + "16-31":9992, + "32-47":72214, + "48-63":26413, + "64-79":1011, + "80-95":53, + "96-111":5, + "112-127":3 + }, + "dns-udp-responses-sizes-sent-ipv4":{ + "16-31":11, + "32-47":655, + "48-63":9372, + "64-79":8509, + "80-95":15889, + "96-111":18710, + "112-127":6369, + "128-143":7446, + "144-159":5097, + "160-175":6053, + "176-191":4761, + "192-207":3082, + "208-223":3275, + "224-239":4232, + "240-255":1326, + "256-271":1439, + "272-287":353, + "288-303":441, + "304-319":633, + "320-335":32, + "336-351":16, + "352-367":16, + "368-383":76, + "384-399":27, + "400-415":40, + "416-431":39, + "432-447":19, + "464-479":33 + }, + "dns-tcp-requests-sizes-received-ipv4":{ + "16-31":18600, + "32-47":93199, + "48-63":22292, + "64-79":707, + "80-95":3 + }, + "dns-tcp-responses-sizes-sent-ipv4":{ + "16-31":28, + "32-47":203, + "48-63":16502, + "64-79":13754, + "80-95":19264, + "96-111":13504, + "112-127":8981, + "128-143":14979, + "144-159":7757, + "160-175":9189, + "176-191":7643, + "192-207":6973, + "208-223":2783, + "224-239":5374, + "240-255":2496, + "256-271":1731, + "272-287":462, + "288-303":512, + "304-319":1077, + "320-335":953, + "336-351":11, + "352-367":309, + "368-383":106, + "384-399":80, + "400-415":9, + "432-447":121 + }, + "dns-udp-requests-sizes-received-ipv6":{}, + "dns-udp-responses-sizes-sent-ipv6":{}, + "dns-tcp-requests-sizes-received-ipv6":{}, + "dns-tcp-responses-sizes-sent-ipv6":{} + } +} \ No newline at end of file