我正在尝试设置一些性能监视器。我还想用数据(csv)做一些事情,包括在收集分段时用一些PS脚本分析数据。这是我创建logman条目的PS命令:
logman create counter -n NetLog -f csv -si 00:00:30 `
-cnf 00:01:00 -c "\Network Interface(*)\Bytes Total/sec" -r -v mmddhhmm `
-b 00:00:00 -e 23:59:59 -rc C:\PerfLogs\Admin\NetLogConfig\hello.cmd
请注意,段长度和采样间隔等详细信息仅用于测试目的。生产将会有很大的不同,虽然尚未确定,但我离题了。现在,这很有用:
logman create counter -n NetLog -f csv -si 00:00:30 `
-cnf 00:01:00 -c "\Network Interface(*)\Bytes Total/sec" -r -v mmddhhmm `
-b 00:00:00 -e 23:59:59
但出于某种原因,只要我添加-rc C:\PerfLogs\Admin\NetLogConfig\hello.cmd
,计数器就会在收集期间分段而不是分段和继续时停止。请注意,创建计数器的命令成功,计数器将成功启动,但关闭文件以进行分段时,收集器集将暂停。它根本不运行命令。我也尝试过.bat的文件类型而不是.cmd,我也尝试直接在-rc参数中输入命令(例如-rc echo "Hello World!"
)。 .bat没有任何区别,直接输入命令会给我一个很好的错误信息,关于它不是一个可接受的参数。文件内部是一个占位符命令,现在:
echo "Hello World!"
pause
那么如何获得在分段/文件关闭时运行的命令?我会考虑解决方法,但这似乎是迄今为止最干净的解决方案。
答案 0 :(得分:0)
阅读最新logman create counter参考:
<input type="text" id="num"> <button type="button" onclick=getIndexToIns(document.getElementById('num').value);>Find Pos</button>
请注意,-[-]rc <task> Run the command specified each time the log is closed.
切换参数为-rc
(older Technet document为-rc <task>
)。那么-rc FileName
代表什么?阅读Data Collector Set Properties和/或运行<task>
,请参见下图:
perfmon.exe
最后,从WMI task documentation开始,我认识到Task - You can run a Windows Management Instrumentation (WMI) task upon completion
of the Data Collector Set collection by entering the command in the
Run this task when the data collector set stops box.
Refer to WMI task documentation for options.
中的 <task>
应该是预定任务的名称。下次修改您的尝试可能会提供一个证明(-rc <task>
窗口的新实例每分钟闪烁一次,输出文件按预期填充):
cmd
<强>输出强>:
erase d:\bat\SO\38859079.txt
erase C:\PerfLogs\Admin\NetLog*.csv
logman delete NetLog
logman create counter -n NetLog -f csv -si 00:00:15 -cnf 00:01:00 ^
-rf 00:05:00 -c "\Network Interface(*)\Bytes Total/sec" -r -v mmddhhmm ^
-b 00:00:00 -e 23:59:59 -rc 38859079
logman start NetLog
timeout /T 360 /Nobreak
logman stop NetLog
dir /B /S C:\PerfLogs\Admin\NetLog*.csv
type d:\bat\SO\38859079.txt
Schtasks /Query /FO LIST /V /TN 38859079 | findstr /I /C:"Task To" /C:"Type"
请注意,您的问题与==> D:\bat\SO\38859079.bat
==> erase d:\bat\SO\38859079.txt
==> erase C:\PerfLogs\Admin\NetLog*.csv
==> logman delete NetLog
The command completed successfully.
==> logman create counter -n NetLog -f csv -si 00:00:15 -cnf 00:01:00 -rf 00:05:00 -c "\
Network Interface(*)\Bytes Total/sec" -r -v mmddhhmm -b 00:00:00 -e 23:59:59 -rc 388590
79
The command completed successfully.
==> logman start NetLog
The command completed successfully.
==> timeout /T 360 /Nobreak
Waiting for 0 seconds, press CTRL+C to quit ...
==> logman stop NetLog
Error:
Data Collector Set is not running.
==> dir /B /S C:\PerfLogs\Admin\NetLog*.csv
C:\PerfLogs\Admin\NetLog_08101250.csv
C:\PerfLogs\Admin\NetLog_08101251.csv
C:\PerfLogs\Admin\NetLog_08101252.csv
C:\PerfLogs\Admin\NetLog_08101253.csv
C:\PerfLogs\Admin\NetLog_08101254.csv
==> type d:\bat\SO\38859079.txt
10.08.2016 12:51:47,99
10.08.2016 12:52:49,04
10.08.2016 12:53:50,06
10.08.2016 12:54:51,07
10.08.2016 12:55:48,00
==> Schtasks /Query /FO LIST /V /TN 38859079 | findstr /I /C:"Task To" /C:"Type"
Task To Run: cmd /c >>d:\bat\SO\38859079.txt echo %date% %time%
Schedule Type: On demand only
==>
(恕我直言,错误标签)无关;在我的示例中,计划任务是运行powershell
但是它也适用于cmd
。