@@ -44,6 +44,7 @@ type Config struct {
4444 ProcessInclude * regexp.Regexp `yaml:"include"`
4545 ProcessExclude * regexp.Regexp `yaml:"exclude"`
4646 EnableWorkerProcess bool `yaml:"iis"`
47+ EnableCMDLine bool `yaml:"cmdline"`
4748 CounterVersion uint8 `yaml:"counter-version"`
4849}
4950
@@ -52,6 +53,7 @@ var ConfigDefaults = Config{
5253 ProcessInclude : types .RegExpAny ,
5354 ProcessExclude : types .RegExpEmpty ,
5455 EnableWorkerProcess : false ,
56+ EnableCMDLine : true ,
5557 CounterVersion : 0 ,
5658}
5759
@@ -131,6 +133,11 @@ func NewWithFlags(app *kingpin.Application) *Collector {
131133 "Enable IIS collectWorker process name queries. May cause the collector to leak memory." ,
132134 ).Default (strconv .FormatBool (c .config .EnableWorkerProcess )).BoolVar (& c .config .EnableWorkerProcess )
133135
136+ app .Flag (
137+ "collector.process.cmdline" ,
138+ "If enabled, the full cmdline is exposed to the windows_process_info metrics." ,
139+ ).Default (strconv .FormatBool (c .config .EnableCMDLine )).BoolVar (& c .config .EnableCMDLine )
140+
134141 app .Flag (
135142 "collector.process.counter-version" ,
136143 "Version of the process collector to use. 1 for Process V1, 2 for Process V2. Defaults to 0 which will use the latest version available." ,
@@ -415,19 +422,25 @@ func (c *Collector) getExtendedProcessInformation(hProcess windows.Handle) (stri
415422 return "" , 0 , fmt .Errorf ("failed to read process memory: %w" , err )
416423 }
417424
418- cmdLineUTF16 := make ([] uint16 , processParameters . CommandLine . Length )
425+ var cmdLine string
419426
420- err = windows .ReadProcessMemory (hProcess ,
421- uintptr (unsafe .Pointer (processParameters .CommandLine .Buffer )),
422- (* byte )(unsafe .Pointer (& cmdLineUTF16 [0 ])),
423- uintptr (processParameters .CommandLine .Length ),
424- nil ,
425- )
426- if err != nil {
427- return "" , processParameters .ProcessGroupId , fmt .Errorf ("failed to read process memory: %w" , err )
427+ if c .config .EnableCMDLine {
428+ cmdLineUTF16 := make ([]uint16 , processParameters .CommandLine .Length )
429+
430+ err = windows .ReadProcessMemory (hProcess ,
431+ uintptr (unsafe .Pointer (processParameters .CommandLine .Buffer )),
432+ (* byte )(unsafe .Pointer (& cmdLineUTF16 [0 ])),
433+ uintptr (processParameters .CommandLine .Length ),
434+ nil ,
435+ )
436+ if err != nil {
437+ return "" , processParameters .ProcessGroupId , fmt .Errorf ("failed to read process memory: %w" , err )
438+ }
439+
440+ cmdLine = strings .TrimSpace (windows .UTF16ToString (cmdLineUTF16 ))
428441 }
429442
430- return strings . TrimSpace ( windows . UTF16ToString ( cmdLineUTF16 )) , processParameters .ProcessGroupId , nil
443+ return cmdLine , processParameters .ProcessGroupId , nil
431444}
432445
433446func (c * Collector ) getProcessOwner (logger * slog.Logger , hProcess windows.Handle ) (string , error ) {
0 commit comments