0

I am creating a project for Remote Monitoring Application, that consist of the service to be hosted on the individual machines. The job of the service is to collecct the information regarding CPU usage, memory usage, etc. using WMI. The service executes the scan every 15 seconds using threading. Now I want the services on each machine to be executed at exactly same time. For eg. 8.15, 8.30, 8.45. I have written a simple logix that checks the current second count and makes the thread sleep for the time system reaches the time that falls exactly either at x.15, x.30, x.45 , etc. But implementing this itself does not assure that the value collected by the service via WMI for the same process would be at same time. For eg. CPU Usage for machine 1 and CPU Usage for machine 2 should be collected at same time so that it can be compared at run time. Same goes for other processes and metric values as well.

Any help would be appreciated.

Dharmesh Tailor
  • 320
  • 1
  • 11
  • Just getting the clocks synchronized on multiple machines is a tricky problem. There's a reason why most protocols that include a time element (to e.g. prevent replay attacks) allow for *some* slack in times reported by various machines involved. – Damien_The_Unbeliever Mar 18 '13 at 11:06
  • Actually the logic that I implemented is giving me desired output, But solution is not reliable. The solution works on the assumption that everything will work fine. :-( – Dharmesh Tailor Mar 18 '13 at 11:16
  • 1
    See e.g. [Network Time Protocol](http://en.wikipedia.org/wiki/Network_Time_Protocol): "Microsoft does not guarantee that their implementation will be more accurate than 2 seconds" – Damien_The_Unbeliever Mar 18 '13 at 11:19

2 Answers2

0

What's your tolerance on "exactly same time?" Within a second? 10 milliseconds?

If your systems are on the same LAN and you have small network delays then you could use ZeroMQ to setup a TCP/IP publish-subscribe system to fire a pulse every 15 seconds that causes all systems to take their snapshot.

If the systems are widely dispersed then you can use something like this to query NTP server: How to Query an NTP Server using C#?

Community
  • 1
  • 1
Ed Power
  • 8,310
  • 3
  • 36
  • 42
0

Thanks for the help, Actually I got this working. The logic applied here (suggested by my wife). I have one static collection and there are 2-3 different threads running each one retrieving different set of value from machine using WMI queries. Now this collection of data takes place at every 1 second(at the moment) and inserted into static collection. Now there is other thread which gets the records from the collection that were inserted at time whose seconds is multiple of 15. for eg. second % 15 = 0. And now this resolves the issue. After collecting the records from the collection, I delete all the records from the collection that were collected before current time. I am not sure if this is the best of solution , but working for me.

Dharmesh Tailor
  • 320
  • 1
  • 11