tags:

views:

148

answers:

4

I'd like to monitor the time on a couple of servers. Ideally I'd do this in an app running on a windows machine. Is this possible and where might I start? I know next to nothing about Linux.

+4  A: 

If you can install a NTP (Network Time Protocol) server on the machines in question you could query the time via NTP. NTP is a simple protocol, so implementing a client would be fairly straightforward.

  • Documentation about NTP can be found here..
  • A C# NTP client library can be found here.
  • Documentation for ntpd (the standard NTP daemon) can be found here.
ConcernedOfTunbridgeWells
Correct me if I'm wrong, but this method will require more programming, will use a non popular port (123) that might be blocked on some firewalls and it uses an obscure protocol compared to http. I don't see what advantages in terms of functionality, implementation time, usability or flexibility this method offers over running a php script on a webserver. Please let me know, as I'm a fan of learning about old and new technologies.
Wadih M.
NTP isn't exactly obscure. It's used to synchronise time across pretty much all internet infrastructure. The advantages of NTP boil down to: no PHP script at all, no web server at all (therefore less surface area to secure), easy to configure (ntpd has fairly straightforward config files.) and client libraries that parse the data for you. But, the best thing of all is that NTP was designed specifically for querying remote servers about the time, which is exactly what the OP wanted to do.
ConcernedOfTunbridgeWells
As an added bonus, you can use ntpd to synchrnize with timesources on the internet which should counteract any drift present in the hw-clock on your boxes.
Kjetil Jorgensen
The size of the nginx-0.8.4.tar.gz webserver is 581 KB. It's the most secure webserver and is very simple-featured so there's not much area to secure: you basically install it and let it be. Apache can also get pretty tiny if you disable the unused modules. You shouldn't think of a webserver as something "heavy".
Wadih M.
@Wadih - This is not something to argue about. You have proposed a perfectly workable solution. NTP is also a perfectly workable solution. Not everything is a nail.
ConcernedOfTunbridgeWells
+1  A: 

You should be able to use SNMP to access the system time from Windows.

From the comments I found at this link:

Looks like the following OID returns current date/time

.1.3.6.1.4.1.2021.100.4.0

sample:

date;snmpwalk -Cc -On -v2c -c public localhost .1.3.6.1.4.1.2021.100.4.0

Thu May 21 14:21:47 CDT 2009

.1.3.6.1.4.1.2021.100.4.0 = STRING: Thu May 21 14:21:47 2009

Dana Holt
I found the snmpwalk binary for Windows here : http://www.elifulkerson.com/articles/net-snmp-windows-binary-unofficial.php
Cheesy
+2  A: 

How about running a simple webserver like apache/nginx and have a php (or cgi or other) script that simply returns the time in any format you want. Then your .net application can simply query those pages to get the information. For example:

Linux server 1: http://linuxserver1/time.php

Linux server 2: http://linuxserver2/time.php

The php script on both servers can be:

<?php
echo date("F j, Y, g:i a");  // Looks like: March 10, 2001, 5:16 pm
// More information on changing the format of the date: http://php.net/date
?>

Then your .NET application would use an inet control to access those remote webpages via the HTTP protocol. This should be a fast, easy and flexible implementation.

Flexibility:

Another advantage with this solution is that you can also monitor pretty much anything the webserver can find (not just time) by making more php scripts, or simply making your php scripts accept some arguments. For example:

To get time: http://linuxserver2/index.php?do=time

To get CPU usage: http://linuxserver2/index.php?do=cpu

To get disk usage: http://linuxserver2/index.php?do=disk

It's also very easy to debug. Just point your browser at the script location and look at the output to see errors. You can also view the apache (webserver) logs for errors.

Installation:

  1. Use this to install apache and php on your ubuntu server:

    sudo apt-get install apache2

    sudo apt-get install php5

    sudo apt-get install libapache2-mod-php5

    sudo /etc/init.d/apache2 restart

  2. Create your time.php script in the /var/www/ directory.

  3. Program your .net application that can query html pages. And you're done.

Wadih M.
+1  A: 

As TwistedAphid suggested, SNMP is a good choice. There is also:

These are usually part of the inetd package on Linux systems.

Here is an example of a Java RFC 868 client.

Anders Lindahl