@@ -133,6 +133,7 @@ def test_element_localtion(self):
133133 def test_post_format (self ):
134134
135135 a = netuitive .Element ('SERVER' , 'here' )
136+ a .merge_metrics ()
136137 ajson = json .dumps (
137138 [a ], default = lambda o : o .__dict__ , sort_keys = True )
138139
@@ -157,7 +158,7 @@ def test(self):
157158 self .assertEqual (self .a .attributes [1 ].value , 'TestValue2' )
158159
159160 def test_post_format (self ):
160-
161+ self . a . merge_metrics ()
161162 ajson = json .dumps (
162163 [self .a ], default = lambda o : o .__dict__ , sort_keys = True )
163164
@@ -180,7 +181,7 @@ def test(self):
180181 self .assertEqual (self .a .relations [1 ].fqn , 'Test2' )
181182
182183 def test_post_format (self ):
183-
184+ self . a . merge_metrics ()
184185 ajson = json .dumps (
185186 [self .a ], default = lambda o : o .__dict__ , sort_keys = True )
186187
@@ -220,8 +221,8 @@ def test_add_sample(self):
220221 self .assertEqual (a .id , 'hostname' )
221222 self .assertEqual (a .name , 'hostname' )
222223
223- self .assertEqual (a .metrics [ 0 ].id , 'metricId' )
224- self .assertEqual (a .metrics [ 0 ].type , 'COUNTER' )
224+ self .assertEqual (a ._metrics [ 'metricId' ].id , 'metricId' )
225+ self .assertEqual (a ._metrics [ 'metricId' ].type , 'COUNTER' )
225226
226227 def test_add_sample_with_tags (self ):
227228 a = netuitive .Element ()
@@ -231,32 +232,40 @@ def test_add_sample_with_tags(self):
231232 self .assertEqual (a .id , 'hostname' )
232233 self .assertEqual (a .name , 'hostname' )
233234
234- self .assertEqual (a .metrics [ 0 ].id , 'tagged' )
235- self .assertEqual (a .metrics [ 0 ].type , 'COUNTER' )
236- self .assertEqual (a .metrics [ 0 ].tags [0 ].name , 'utilization' )
237- self .assertEqual (a .metrics [ 0 ].tags [0 ].value , 'true' )
235+ self .assertEqual (a ._metrics [ 'tagged' ].id , 'tagged' )
236+ self .assertEqual (a ._metrics [ 'tagged' ].type , 'COUNTER' )
237+ self .assertEqual (a ._metrics [ 'tagged' ].tags [0 ].name , 'utilization' )
238+ self .assertEqual (a ._metrics [ 'tagged' ].tags [0 ].value , 'true' )
238239
239240 def test_duplicate_metrics (self ):
240241 a = netuitive .Element ()
241242
242243 a .add_sample (
243244 'metricId' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' )
245+ a .add_sample (
246+ 'metricId' , 1434110795 , 2 , 'COUNTER' , host = 'hostname' )
244247
245248 # don't allow duplicate metrics
246- self .assertEqual (len (a .metrics ), 1 )
249+ self .assertEqual (len (a ._metrics ), 1 )
250+ self .assertEqual (a ._metrics ['metricId' ].id , 'metricId' )
251+ self .assertEqual (a ._metrics ['metricId' ].type , 'COUNTER' )
247252
248253 self .assertEqual (a .samples [0 ].metricId , 'metricId' )
249254 self .assertEqual (a .samples [0 ].timestamp , 1434110794000 )
250255 self .assertEqual (a .samples [0 ].val , 1 )
256+ self .assertEqual (a .samples [1 ].metricId , 'metricId' )
257+ self .assertEqual (a .samples [1 ].timestamp , 1434110795000 )
258+ self .assertEqual (a .samples [1 ].val , 2 )
251259
252260 def test_clear_samples (self ):
253261 a = netuitive .Element ()
254262 a .add_sample (
255263 'metricId' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' )
256264 # test clear_samples
257- self .assertEqual (len (a .metrics ), 1 )
265+ self .assertEqual (len (a ._metrics ), 1 )
258266 a .clear_samples ()
259267 self .assertEqual (len (a .metrics ), 0 )
268+ self .assertEqual (len (a ._metrics ), 0 )
260269 self .assertEqual (len (a .samples ), 0 )
261270
262271 def test_with_sparseDataStrategy (self ):
@@ -268,9 +277,8 @@ def test_with_sparseDataStrategy(self):
268277 a .add_sample (
269278 'sparseDataStrategy' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' , sparseDataStrategy = 'ReplaceWithZero' )
270279
271- self .assertEqual (a .metrics [0 ].sparseDataStrategy , 'None' )
272- self .assertEqual (
273- a .metrics [1 ].sparseDataStrategy , 'ReplaceWithZero' )
280+ self .assertEqual (a ._metrics ['nonsparseDataStrategy' ].sparseDataStrategy , 'None' )
281+ self .assertEqual (a ._metrics ['sparseDataStrategy' ].sparseDataStrategy , 'ReplaceWithZero' )
274282
275283 a .clear_samples ()
276284
@@ -284,10 +292,9 @@ def test_with_unit(self):
284292 a .add_sample (
285293 'nonunit' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' )
286294
287- self .assertEqual (
288- a .metrics [0 ].unit , 'Bytes' )
295+ self .assertEqual (a ._metrics ['unit' ].unit , 'Bytes' )
289296
290- self .assertEqual (a .metrics [ 1 ].unit , '' )
297+ self .assertEqual (a ._metrics [ 'nonunit' ].unit , '' )
291298
292299 def test_with_min (self ):
293300 a = netuitive .Element ()
@@ -339,47 +346,15 @@ def test_add_sanitize(self):
339346 a .add_sample (
340347 'mongo.wiredTiger.cache.eviction$server populating queue,:but not evicting pages' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' )
341348
342- self .assertEqual (a .metrics [
343- 0 ].id , 'mongo.wiredTiger.cache.eviction_server_populating_queue__but_not_evicting_pages' )
349+ self .assertEqual (a ._metrics ['mongo.wiredTiger.cache.eviction_server_populating_queue__but_not_evicting_pages' ].id , 'mongo.wiredTiger.cache.eviction_server_populating_queue__but_not_evicting_pages' )
344350
345351 def test_post_format (self ):
346352 a = netuitive .Element ()
347353
348- a .add_sample (
349- 'nonsparseDataStrategy' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' )
350- a .add_sample (
351- 'sparseDataStrategy' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' , sparseDataStrategy = 'ReplaceWithZero' )
352-
353- a .add_sample (
354- 'unit' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' , unit = 'Bytes' )
355-
356- a .add_sample (
357- 'nonunit' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' )
358-
359- a .add_sample (
360- 'tagged' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' , tags = [{'utilization' : 'true' }])
361-
362- a .add_sample (
363- 'min' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' , min = 0 )
364-
365- a .add_sample (
366- 'max' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' , max = 100 )
367-
368- a .add_sample (
369- 'avg' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' , avg = 50 )
370-
371- a .add_sample (
372- 'sum' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' , sum = 2 )
373-
374- a .add_sample (
375- 'cnt' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' , cnt = 3 )
376-
377354 a .add_sample (
378355 'min.max.avg.sum.cnt' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' , min = 0 , max = 100 , avg = 50 , sum = 2 , cnt = 3 )
379356
380- a .add_sample (
381- 'cnt2' , 1475158966202 , 1 , 'COUNTER' , host = 'hostname' , cnt = 3 , ts_is_ms = True )
382-
357+ a .merge_metrics ()
383358 ajson = json .dumps (
384359 [a ], default = lambda o : o .__dict__ , sort_keys = True )
385360
@@ -518,7 +493,7 @@ def test_check(self):
518493
519494 self .assertEqual (self .check .name , 'checkName' )
520495 self .assertEqual (self .check .elementId , 'elementId' )
521- self .assertEqual (self .check .interval , 60 )
496+ self .assertEqual (self .check .ttl , 60 )
522497
523498 def tearDown (self ):
524499 pass
0 commit comments