@@ -305,6 +305,58 @@ def test_produces_simple_percent(self, publish_mock):
305
305
})
306
306
307
307
308
+ class TestCPUCollectorExtended (CollectorTestCase ):
309
+
310
+ def setUp (self ):
311
+ self .config = get_collector_config ('CPUCollector' , {
312
+ 'interval' : 10 ,
313
+ 'normalize' : False ,
314
+ 'extended' : True ,
315
+ })
316
+
317
+ self .collector = CPUCollector (self .config , None )
318
+
319
+ def test_import (self ):
320
+ self .assertTrue (CPUCollector )
321
+
322
+ @patch .object (Collector , 'publish' )
323
+ def test_produces_simple_and_complex (self , publish_mock ):
324
+ # similar to above, we need three mock values: two for the simple
325
+ # metric (to calculate a delta), plus one more for the standard
326
+ # metrics
327
+ patch_open = patch ('__builtin__.open' , Mock (side_effect = [
328
+ StringIO ('cpu 100 200 300 400 500 0 0 0 0 0' ),
329
+ StringIO ('cpu 110 220 330 440 550 0 0 0 0 0' ),
330
+ StringIO ('cpu 100 200 300 400 500 0 0 0 0 0' ),
331
+ ]))
332
+
333
+ patch_open .start ()
334
+ self .collector .collect ()
335
+ patch_open .stop ()
336
+
337
+ self .assertPublishedMany (publish_mock , {})
338
+
339
+ patch_open = patch ('__builtin__.open' , Mock (side_effect = [
340
+ StringIO ('cpu 110 220 330 440 550 0 0 0 0 0' ),
341
+ StringIO ('cpu 120 230 340 450 560 0 0 0 0 0' ),
342
+ StringIO ('cpu 110 220 330 440 550 0 0 0 0 0' ),
343
+ ]))
344
+
345
+ patch_open .start ()
346
+ self .collector .collect ()
347
+ patch_open .stop ()
348
+
349
+ # Since the `extended` config option is set, we should see both simple
350
+ # percent-only metrics, but also the standard metrics
351
+ self .assertPublishedMany (publish_mock , {
352
+ 'total.user' : 1.0 ,
353
+ 'total.nice' : 2.0 ,
354
+ 'total.system' : 3.0 ,
355
+ 'total.idle' : 4.0 ,
356
+ 'percent' : 75.0
357
+ })
358
+
359
+
308
360
##########################################################################
309
361
if __name__ == "__main__" :
310
362
unittest .main ()
0 commit comments