forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nsd_test.go
244 lines (231 loc) · 6.39 KB
/
nsd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package nsd
import (
"bytes"
"testing"
"time"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
)
var TestTimeout = internal.Duration{Duration: time.Second}
func NSDControl(output string, Timeout internal.Duration, useSudo bool, Server string, ConfigFile string) func(string, internal.Duration, bool, string, string) (*bytes.Buffer, error) {
return func(string, internal.Duration, bool, string, string) (*bytes.Buffer, error) {
return bytes.NewBuffer([]byte(output)), nil
}
}
func TestParseFullOutput(t *testing.T) {
acc := &testutil.Accumulator{}
v := &NSD{
run: NSDControl(fullOutput, TestTimeout, true, "", ""),
}
err := v.Gather(acc)
assert.NoError(t, err)
assert.True(t, acc.HasMeasurement("nsd"))
assert.True(t, acc.HasMeasurement("nsd_servers"))
assert.Len(t, acc.Metrics, 2)
assert.Equal(t, 99, acc.NFields())
acc.AssertContainsFields(t, "nsd", parsedFullOutput)
acc.AssertContainsFields(t, "nsd_servers", parsedFullOutputServerAsTag)
}
var parsedFullOutputServerAsTag = map[string]interface{}{
"queries": float64(75576),
}
var parsedFullOutput = map[string]interface{}{
"num_queries": float64(75557),
"time_boot": float64(2944405.500253),
"time_elapsed": float64(2944405.500253),
"size_db_disk": float64(98304),
"size_db_mem": float64(22784),
"size_xfrd_mem": float64(83956312),
"size_config_disk": float64(0),
"size_config_mem": float64(6088),
"num_type_TYPE0": float64(6),
"num_type_A": float64(46311),
"num_type_NS": float64(478),
"num_type_MD": float64(0),
"num_type_MF": float64(0),
"num_type_CNAME": float64(272),
"num_type_SOA": float64(596),
"num_type_MB": float64(0),
"num_type_MG": float64(0),
"num_type_MR": float64(0),
"num_type_NULL": float64(0),
"num_type_WKS": float64(0),
"num_type_PTR": float64(83),
"num_type_HINFO": float64(1),
"num_type_MINFO": float64(0),
"num_type_MX": float64(296),
"num_type_TXT": float64(794),
"num_type_RP": float64(0),
"num_type_AFSDB": float64(0),
"num_type_X25": float64(0),
"num_type_ISDN": float64(0),
"num_type_RT": float64(0),
"num_type_NSAP": float64(0),
"num_type_SIG": float64(0),
"num_type_KEY": float64(1),
"num_type_PX": float64(0),
"num_type_AAAA": float64(22736),
"num_type_LOC": float64(2),
"num_type_NXT": float64(0),
"num_type_SRV": float64(93),
"num_type_NAPTR": float64(5),
"num_type_KX": float64(0),
"num_type_CERT": float64(0),
"num_type_DNAME": float64(0),
"num_type_OPT": float64(0),
"num_type_APL": float64(0),
"num_type_DS": float64(0),
"num_type_SSHFP": float64(0),
"num_type_IPSECKEY": float64(0),
"num_type_RRSIG": float64(21),
"num_type_NSEC": float64(0),
"num_type_DNSKEY": float64(325),
"num_type_DHCID": float64(0),
"num_type_NSEC3": float64(0),
"num_type_NSEC3PARAM": float64(0),
"num_type_TLSA": float64(35),
"num_type_SMIMEA": float64(0),
"num_type_CDS": float64(0),
"num_type_CDNSKEY": float64(0),
"num_type_OPENPGPKEY": float64(0),
"num_type_CSYNC": float64(0),
"num_type_SPF": float64(16),
"num_type_NID": float64(0),
"num_type_L32": float64(0),
"num_type_L64": float64(0),
"num_type_LP": float64(0),
"num_type_EUI48": float64(0),
"num_type_EUI64": float64(0),
"num_type_TYPE252": float64(962),
"num_type_TYPE253": float64(2),
"num_type_TYPE255": float64(1840),
"num_opcode_QUERY": float64(75527),
"num_opcode_NOTIFY": float64(6),
"num_class_CLASS0": float64(6),
"num_class_IN": float64(75395),
"num_class_CH": float64(132),
"num_rcode_NOERROR": float64(65541),
"num_rcode_FORMERR": float64(8),
"num_rcode_SERVFAIL": float64(0),
"num_rcode_NXDOMAIN": float64(6642),
"num_rcode_NOTIMP": float64(18),
"num_rcode_REFUSED": float64(3341),
"num_rcode_YXDOMAIN": float64(0),
"num_rcode_NOTAUTH": float64(2),
"num_edns": float64(71398),
"num_ednserr": float64(0),
"num_udp": float64(34111),
"num_udp6": float64(40429),
"num_tcp": float64(1015),
"num_tcp6": float64(2),
"num_tls": float64(0),
"num_tls6": float64(0),
"num_answer_wo_aa": float64(13),
"num_rxerr": float64(0),
"num_txerr": float64(0),
"num_raxfr": float64(954),
"num_truncated": float64(1),
"num_dropped": float64(5),
"zone_master": float64(2),
"zone_slave": float64(1),
}
var fullOutput = `server0.queries=75576
num.queries=75557
time.boot=2944405.500253
time.elapsed=2944405.500253
size.db.disk=98304
size.db.mem=22784
size.xfrd.mem=83956312
size.config.disk=0
size.config.mem=6088
num.type.TYPE0=6
num.type.A=46311
num.type.NS=478
num.type.MD=0
num.type.MF=0
num.type.CNAME=272
num.type.SOA=596
num.type.MB=0
num.type.MG=0
num.type.MR=0
num.type.NULL=0
num.type.WKS=0
num.type.PTR=83
num.type.HINFO=1
num.type.MINFO=0
num.type.MX=296
num.type.TXT=794
num.type.RP=0
num.type.AFSDB=0
num.type.X25=0
num.type.ISDN=0
num.type.RT=0
num.type.NSAP=0
num.type.SIG=0
num.type.KEY=1
num.type.PX=0
num.type.AAAA=22736
num.type.LOC=2
num.type.NXT=0
num.type.SRV=93
num.type.NAPTR=5
num.type.KX=0
num.type.CERT=0
num.type.DNAME=0
num.type.OPT=0
num.type.APL=0
num.type.DS=0
num.type.SSHFP=0
num.type.IPSECKEY=0
num.type.RRSIG=21
num.type.NSEC=0
num.type.DNSKEY=325
num.type.DHCID=0
num.type.NSEC3=0
num.type.NSEC3PARAM=0
num.type.TLSA=35
num.type.SMIMEA=0
num.type.CDS=0
num.type.CDNSKEY=0
num.type.OPENPGPKEY=0
num.type.CSYNC=0
num.type.SPF=16
num.type.NID=0
num.type.L32=0
num.type.L64=0
num.type.LP=0
num.type.EUI48=0
num.type.EUI64=0
num.type.TYPE252=962
num.type.TYPE253=2
num.type.TYPE255=1840
num.opcode.QUERY=75527
num.opcode.NOTIFY=6
num.class.CLASS0=6
num.class.IN=75395
num.class.CH=132
num.rcode.NOERROR=65541
num.rcode.FORMERR=8
num.rcode.SERVFAIL=0
num.rcode.NXDOMAIN=6642
num.rcode.NOTIMP=18
num.rcode.REFUSED=3341
num.rcode.YXDOMAIN=0
num.rcode.NOTAUTH=2
num.edns=71398
num.ednserr=0
num.udp=34111
num.udp6=40429
num.tcp=1015
num.tcp6=2
num.tls=0
num.tls6=0
num.answer_wo_aa=13
num.rxerr=0
num.txerr=0
num.raxfr=954
num.truncated=1
num.dropped=5
zone.master=2
zone.slave=1`