@@ -392,41 +392,85 @@ def test_process(self):
392
392
self .assertGreater (len (output ), 0 )
393
393
394
394
found_cmdline = False
395
- found_env = False
395
+ for evt in output :
396
+ process = evt ["system" ]["process" ]
397
+ found_cmdline |= "cmdline" in process
398
+
399
+ # Remove 'env' prior to checking documented fields because its keys are dynamic.
400
+ process .pop ("env" , None )
401
+ self .assert_fields_are_documented (evt )
402
+
403
+ # Remove optional keys.
404
+ process .pop ("cgroup" , None )
405
+ process .pop ("fd" , None )
406
+ process .pop ("cmdline" , None )
407
+
408
+ self .assertCountEqual (SYSTEM_PROCESS_FIELDS , process .keys ())
409
+
410
+ self .assertTrue (found_cmdline , "cmdline not found in any process events" )
411
+
412
+ @unittest .skipUnless (re .match ("(?i)linux|darwin|freebsd" , sys .platform ), "os" )
413
+ def test_process_unix (self ):
414
+ """
415
+ Test system/process output for fields specific of unix systems.
416
+ """
417
+ import getpass
418
+
419
+ self .render_config_template (
420
+ modules = [{
421
+ "name" : "system" ,
422
+ "metricsets" : ["process" ],
423
+ "period" : "5s" ,
424
+ "extras" : {
425
+ "process.env.whitelist" : ["PATH" ],
426
+ "process.include_cpu_ticks" : True ,
427
+
428
+ # Remove 'percpu' prior to checking documented fields because its keys are dynamic.
429
+ "process.include_per_cpu" : False ,
430
+ },
431
+ }],
432
+ # Some info is only guaranteed in processes with permissions, check
433
+ # only on own processes.
434
+ processors = [{
435
+ "drop_event" : {
436
+ "when" : "not.equals.user.name: " + getpass .getuser (),
437
+ },
438
+ }],
439
+ )
440
+ proc = self .start_beat ()
441
+ self .wait_until (lambda : self .output_lines () > 0 )
442
+ proc .check_kill_and_wait ()
443
+ self .assert_no_logged_warnings ()
444
+
445
+ output = self .read_output_json ()
446
+ self .assertGreater (len (output ), 0 )
447
+
396
448
found_fd = False
449
+ found_env = False
397
450
found_cwd = not sys .platform .startswith ("linux" )
398
451
for evt in output :
452
+ found_cwd |= "working_directory" in evt ["process" ]
453
+
399
454
process = evt ["system" ]["process" ]
455
+ found_fd |= "fd" in process
456
+ found_env |= "env" in process
400
457
401
458
# Remove 'env' prior to checking documented fields because its keys are dynamic.
402
459
env = process .pop ("env" , None )
403
- if env is not None :
404
- found_env = True
405
-
406
460
self .assert_fields_are_documented (evt )
407
461
408
462
# Remove optional keys.
409
463
process .pop ("cgroup" , None )
410
- cmdline = process .pop ("cmdline" , None )
411
- if cmdline is not None :
412
- found_cmdline = True
413
- fd = process .pop ("fd" , None )
414
- if fd is not None :
415
- found_fd = True
416
- cwd = process .pop ("cwd" , None )
417
- if cwd is not None :
418
- found_cwd = True
464
+ process .pop ("cmdline" , None )
465
+ process .pop ("fd" , None )
419
466
420
467
self .assertCountEqual (SYSTEM_PROCESS_FIELDS , process .keys ())
421
468
422
- self .assertTrue (found_cmdline , "cmdline not found in any process events" )
423
-
424
- if sys .platform .startswith ("linux" ) or sys .platform .startswith ("freebsd" ):
469
+ if not sys .platform .startswith ("darwin" ):
425
470
self .assertTrue (found_fd , "fd not found in any process events" )
426
471
427
- if sys .platform .startswith ("linux" ) or sys .platform .startswith ("freebsd" )\
428
- or sys .platform .startswith ("darwin" ):
429
- self .assertTrue (found_env , "env not found in any process events" )
472
+ self .assertTrue (found_env , "env not found in any process events" )
473
+ self .assertTrue (found_cwd , "working_directory not found in any process events" )
430
474
431
475
@unittest .skipUnless (re .match ("(?i)win|linux|darwin|freebsd" , sys .platform ), "os" )
432
476
def test_process_metricbeat (self ):
0 commit comments