screen grab logging

This is more of a short-term workaround than a solution, but it’s kind of fun.

I’m doing some performance testing of one of our java servers, and I want my test to run in the night while I’m asleep. The test has previously been run using jconsole to get graphs of memory and thread usage. This looks good but it’s a GUI only tool so not scriptable. I figured I could run it and get some screen captures.

import from ImageMagick is a tool for doing screen grabs from a script. However it needs an X11 window ID to grab a window, which can be a little tricky to find. Another problem I found when testing was that if I had another window overlapping the window I was grabbing, that part came out black, and when the screensaver kicked in, the scripted grab didn’t work.

Taking these problems, I came up with my workaround. First, run a vncserver, so that jconsole is in a separate display which isn’t affected by other windows or the screensaver. I also set the geometry to have just enough room for the windows I want.

vncserver -geometry 1000x1500 :1

Connect to this with a vncviewer, start up jconsole and set it up to display what I’m interested in.

Now I can start my test, and run my windowdump script:

#!/bin/bash
 
dumpdir=/home/edward/screencaps
wingrep=Monitoring
 
while true; do
    pdate=`date +%Y%m%d_%H%M`
    for winid in `xwininfo -display :1 -root -tree | grep $wingrep | tr -s ' ' | cut -d' ' -f2`; do
        import -display :1 -silent -frame -window $winid "${dumpdir}/${wingrep}_${winid}_${pdate}.png"
    done
    sleep 30m
done

This uses xwininfo to grab all windows in the display, then grep and cut to get the IDs of the ones I’m interested in, and pass those to import to grab them.

Quite silly really. If I have time I’ll be writing some code to just read numbers from JMX and log them to a file.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*