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.
views:
148answers:
4If 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.
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
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:
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
Create your time.php script in the /var/www/ directory.
Program your .net application that can query html pages. And you're done.
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.