How to use perfmon/logman to set up logging on a master (Windows) VM, writing to another machine on the network

environment-variableslogginglogmanperfmonvirtual-machines

I know how to set up logging to write to a remote location in the general case – just specify the output filename using the full UNC path (e.g. \\HOST-PC\directory\logoutput.etl) when creating the log job. However, a problem arises when new Virtual Machines are created from a master VM where logging has been enabled: each VM will be writing logs to the exact same file on the network. I need to find a way that each new VM will automatically write to a remote file unique to it.

I've tried using the %ComputerName% environment variable in the UNC path when setting up the log using logman.exe (e.g. \host\directory\%ComputerName%\log.etl) hoping that each VM would automatically expand this to include its unique name, but this doesn't work – you just get a folder named "%ComputerName%", without the variable being expanded. This is despite the fact that if you use e.g. %SystemRoot%, this does get expanded correctly (though of course this would create an invalid path in this instance). I'm not sure what causes some variables to be expanded and not others.

Any better ideas?

Best Answer

I don't see how it can be done natively with logman, but through both the UI and the COM interface, you can set the Subdirectory Format to include the computer name as a prefix.

Performance logs and alerts dialog showing the "Prefix subdirectory with computer name" option

See MSDN for documentation on how to set the option programmatically.

Edit: The checkbox in question appears on both the data set collector and the performance counter itself. The performance counter seems to have the option greyed out. Be sure to right click the item under "Data Collector Sets > User Defined" in the MMC tree to adjust the appropriate option.

Also, Powershell:

$taskName = "daily_perf_log"
$qualifiedName = "Service\{0}" -f $taskName

# retrieve the collection set
$dcss = new-object -com Pla.DataCollectorSetCollection
$dcss.GetDataCollectorSets($null, $qualifiedName)
$dcs = $dcss.Item(0)

# update
# 3 to enable, 1 to disable (http://msdn.microsoft.com/en-us/library/windows/desktop/aa371811(v=vs.85).aspx)
$dcs.SubdirectoryFormat = 3 <# Prepend computer name #>

# save
# 1 create new / 2 update / other options (http://msdn.microsoft.com/en-us/library/windows/desktop/aa371873(v=vs.85).aspx)
$dcs.Commit($qualifiedName, $null, 2 <# update only #>)