Monitor Application with Web Screenshots

Ok, I have done some pretty geeky things in the past....but I think this one will rank in the top 10 8) Also, there could be a better way to do this, however I quickly needed to solve a problem, and I came up with this method in about 10 not bad.

You have a wireless device, like a nice Treo 700p device, and you want to monitor an application on a server. This application could really be anything. However, the only way you can see/use this application is via your big ol' laptop, via a VPN connection. You would REALLY like to just see what the app is doing every now and then. There are a bunch of factors though, that might not let you do that. The existing VPN connection, the server is NOT on the web, or it's behind a firewall and you can't get to via your Palm device. Heck, even if you can get to it...there probably isn't any software on your phone that would allow you to remote the server. What do you do....what do you do???


For this example, I am going to use a situation where I needed to monitor a NetWare server via RConJ. The screen I will be monitoring will always be changing, so what I am going to do is take a screenshot of just the RConJ application, rotate it 90 degrees so it fits nicely on my phone device, and then upload the image to a webserver where I have a index.html file set to META REFRESH the page every 11 seconds forcing the cache to clear as well. That way, all you have to do on your palm device, is simply visit the web page, and you'll always see an updated screenshot of the RConJ session. Pretty cool, huh :wink:


First, I will assume you already have a web server up and running, and an automated way of copying files up to it.

Second, create a web directory on that webserver. For this example, I used an NFS share, however you can really use whatever method you want to get the updated image to the webserver. (FTP, SFTP...whatever.)

On the linux box that has the application (RConJ for my situation) connected to the remote server, we first need to find out what the "window id" of the application is called. Look to see if there is a title of your app, mine was simply called RConsoleJ. Run the following command to get it's window ID:

xwininfo -root -children | grep RConsoleJ | awk '{print $1}'

...this command should kick back something like this 0x121325d That is the window ID of RConJ. Sometimes you might get a couple of window IDs kicked back to you, so you'll just need to run this next command a few times to see which is which....let's move on and I'm sure you'll see what I mean.

Now, we want to use ImageMagick and grab just that application. If you don't have ImageMagick insatlled (don't think it's default on Ubuntu) then just run:

sudo apt-get install imagemagick

Now let's check to see if the window ID above is the correct app. If not, no biggie, just keep running that above xwininfo command until you see the correct screenshot of your running app. Here is the test ImageMagick command:

import -window 0x121325d test.jpg open test.jpg and see if it is a screenshot of your app. If so, then we're almost done. There is some cool little tricks you can do with ImageMagick. For instance, to have the image come out in a little more of a viewable state, I rotated the image 90 degrees. You can test that out like so:

import -window 0x121325d -rotate 90 test.jpg

...then copy that test.jpg file up to your web server and check out the image.

Next, we want to take constant screenshots of that application (like every 10 seconds) and then just get them into your web directory that has a little index.html file setup to refresh the page every 11 seconds, forcing it to remove the cache as well. In the web directory place a file called index.html that has the following code

<meta http-equiv="refresh" content="11">
<meta http-equiv="Cache-Control" content="no-cache">
<img src="watchme.jpg">

Then, just run this repeating while script on your Linux box which should also drop the image (watchme.jpg) via NFS into the same web directory:

while(true); do import -window 0x121325d -rotate 90 watchme.jpg&& sleep 10; done


...get it? See how simple that is? Does it all make sense? All you have to do is view the above web directory on your PDA's browser, and you should get a 11 second (change the seconds as you see fit) updated screenshot of the application. Not bad, huh?


That is about all there is to it. Like I said, I came up with this in about 10 seconds (heh, took longer than that to document all this), as I just quickly needed to solve a problem. There might be a better way to do something like this, then again....this method could also be used in other situations. The simplicity of it, actually gives it some power. I bet you are already thinking of either a way you could use this....or a way to improve it. Either way, let me know what you think.