Question

My intention is to display stats like Load avg and RAM usage from a remote server onto an LCD panel 24/7. I would like the information to be updated once every 1-3 seconds.

Other threads have suggested using SSH commands to retrieve the information.

    ssh root@192.168.1.252 uptime && cat /proc/meminfo

Is using SSH suitable for my purposes, my concern is that

  1. my log files may be bloated because of all the login attempts
  2. overhead of setting up and tearing down an SSH connection every few second.

Is there any such package out there or do I have to code it myself? I would prefer one that keeps the connection open to reduce overhead. I do not require encryption as both servers are on LAN.

Thanks in advance.

Was it helpful?

Solution

Several things to note:

  1. Don't use root if you don't need to. For uptime and cat /proc/meminfo you certainly don't need root. Use another user.
  2. Note the difference between these two:

    ssh user@hostname uptime && cat /proc/meminfo
    ssh user@hostname 'uptime && cat /proc/meminfo'
    

    The first one will execute cat /proc/meminfo on your local machine, the second will execute it on the remote. I think you want to use the second version. (You want the CPU info of the remote machine, not your local machine, do you?)

You can use connection multiplexing to hit two birds with one stone: reduce the overhead of establishing new connections and avoid polluting the server log. To do this, add a configuration like this in your ~/.ssh/config file:

Host somename
User the_username
Hostname the_hostname
ControlMaster auto
ControlPath ~/.ssh/master-somename

You can choose any somename, it's like an alias. With this setting, you can connect to the server simply as:

ssh somename

While this remote session is still alive (until you logout), you can open new connections from another terminal, and they will reuse the existing connection, bypassing authentication and effectively eliminating the overhead of new connections.

This is actually a common trick when working with slow remote servers where establishing new connections is a noticeable overhead. In fact I use this setting to apply it to all remote servers I work with:

Host *
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p

I usually recommend this trick for everyone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top