问题
I try to use PerformanceCounter to monitor remote server information in a domain environment, like:
var counter = new PerformanceCounter("PhysicalDisk", "Disk Bytes/sec", "_Total", "REMOTE_SERVER");
there is only 1 line of code, running the above code will wait at least 50 seconds.
I tried to impersonate the admin etc, still same time.
I also tried with PowerShell get-counter, still more or less speed.
I tried with windows native Performance Monitoring Tool in computer management, connect to remote server, takes a few second only.
Any idea how to improve the connection speed?
回答1:
If you are monitoring your local computer, I've found if I try and monitor localhost I sometimes get 1 minute or greater waits when setting up my PerformanceCounter objects. If I instead use 127.0.0.1 it seems to help.
However, it still happens sometimes when monitoring remote machines. Will update if I find a solution, I believe there is an alternative library called PDH which I am about to look into.
来源:https://stackoverflow.com/questions/14743852/performancecounter-extremely-slow-in-connecting-remote-server