This Community site is new! Please help us build a community around the JNIOR.
Sign up, and help share your knowledge. Please sign-up even if you do not plan to post as a sign of support.
If there is evidence of a demand we will continue to develop the content here.

Uptime Survey

You got ideas? Let's hear 'em. Here we can talk about your experiences programming on the JNIOR or items that you may wish to have INTEG assist you with.
Post Reply
bscloutier
Posts: 401
Joined: Thu Sep 14, 2017 12:55 pm

Uptime Survey

Post by bscloutier » Fri Sep 29, 2017 3:43 pm

Since JANOS now tracks peer JNIORs on the same subnet an application program can easily scan those JNIORs. Also with v1.6.2 the System Up Time is displayed as part of the Telnet banner prior to any login. So the following is pretty simple to get. Note that the banner will say "Record" when that unit is setting its own uptime record.
bruce_dev /> juptime
      10.0.0.231 System up time: 2 Days 4 Hours 58:14.714
       10.0.0.61 System up time: 2 Days 4 Hours 59:38.884
       10.0.0.82 System up time: 2 Days 4 Hours 58:45.832
       10.0.0.64 System up time: 2 Days 4 Hours 59:28.742
      10.0.0.236 System up time: 2 Days 4 Hours 58:09.222
      10.0.0.238 System up time: 2 Days 4 Hours 58:11.696
      10.0.0.247 System up time: 2 Days 4 Hours 53:26.190
       10.0.0.66 System up time: 20 Hours 42:35.625
       10.0.0.75 System up time: 2 Days 4 Hours 58:56.870
      10.0.0.239 System up time: 2 Days 4 Hours 58:02.212
      10.0.0.225 System up time: 2 Days 2 Hours 48:06.711
      10.0.0.248 System up time: 2 Days 4 Hours 58:11.053
       10.0.0.58 System up time: 6 Hours 19:10.564
       10.0.0.62 System up time: 2 Days 4 Hours 59:47.148
       10.0.0.74 System up time: 2 Days 4 Hours 58:57.636
      10.0.0.200 System up time: 2 Days 4 Hours 58:53.366
       10.0.0.60 System up time: 2 Days 4 Hours 59:49.208
      10.0.0.251 System up time: 21 Hours 25:56.572
       10.0.0.71 System up time: 19 Hours 33:25.958
       10.0.0.73 System up time: 2 Days 4 Hours 58:59.948
      10.0.0.252 System up time: 2 Days 4 Hours 58:16.693
       10.0.0.63 System up time: 2 Days 4 Hours 56:52.631
       10.0.0.69 System up time: 2 Days 4 Hours 59:53.297
      10.0.0.253 System up time: 2 Days 4 Hours 58:07.219
      10.0.0.237 System up time: 2 Days 4 Hours 57:48.519
       10.0.0.70 System up time: 1 Day 2 Hours 46:59.165
      10.0.0.242 Record up time: 2 Days 4 Hours 57:51.627

bruce_dev />

bscloutier
Posts: 401
Joined: Thu Sep 14, 2017 12:55 pm

Re: Uptime Survey

Post by bscloutier » Fri Sep 29, 2017 3:49 pm

Here's the application code for this.
/*
 *  Program to check peer running times
 */
package juptime;

import com.integpg.system.JANOS;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class JUptime {

    public static void main(String[] args) {
        
        String ipaddr_pattern = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
                "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
                "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
                "([01]?\\d\\d?|2[0-4]\\d|25[0-5])";
        Pattern regex_ipaddr = Pattern.compile(ipaddr_pattern);
        
        String uptime_pattern = " up time: ";
        Pattern regex_uptime = Pattern.compile(uptime_pattern);
        
        String[] peers = JANOS.getRegistryList("Peers");
        for (int n = 0; n < peers.length; n++) {
            String peer = JANOS.getRegistryString("Peers/"+peers[n], "");
            Matcher match = regex_ipaddr.matcher(peer);
            if (match.find()) {
                try {
                    String ip_addr = match.group();
                    Socket telnet_socket = new Socket(ip_addr, 23);
                    telnet_socket.setSoTimeout(2000);                    
                    BufferedReader in = new BufferedReader(
                            new InputStreamReader(telnet_socket.getInputStream()));
                    
                    String response;
                    while ((response = in.readLine()) != null) {
                        Matcher check = regex_uptime.matcher(response);
                        if (check.find()) {
                            System.out.printf("%16s %s\r\n", ip_addr, response);
                            break;
                        }
                    }
                    
                    in.close();
                    telnet_socket.close();
                } catch (IOException ex) {
                }
            }
        }
    }
}

bscloutier
Posts: 401
Joined: Thu Sep 14, 2017 12:55 pm

Re: Uptime Survey

Post by bscloutier » Fri Sep 29, 2017 3:54 pm

By the way these are mostly 2 days running as we released JANOS v1.6.2 which was promptly pushed into the office. Not all units were updated.

Post Reply