Aug 10

When you are working with VMs, the hierarchy of needs tends to be Memory, Storage, Network, CPU.  You can never have too much RAM when you are talking about a VM server.  Since you usually consume all of your memory first, it’s nice to have a little one liner that lets you know how much memory you have allocated to VMs, and using the VirtualBox command line, this does exactly that. You’ll note that this isn’t my best work, but it’s quick and I’m not worried about all of the forking because we’re only talking about a dozen or so lines at most. Feel free to add tweaks in the comments if you can pretty it up!

VBoxManage list -l runningvms |grep Memory | awk {‘print $3′} | awk -F”MB” {‘print $1′} | echo `sed ’s/$/+/’` | sed ’s/+$//g’ | bc

Or this one is a little fancier and takes the total memory installed in the system, subtracts the VM memory in use +512 for the host and gives you the total physical RAM left for VM usage

VM=`VBoxManage list -l runningvms |grep Memory | awk {‘print $3′} | awk -F”MB” {‘print $1′} | echo \`sed ’s/$/+/’\` | sed ’s/+$//g’ | bc`; MEM=`grep MemTotal /proc/meminfo | awk {‘print $2′} | sed ’s/$/ \/ 1024/g’|bc` >/dev/null; echo “$MEM – $VM – 512″ | bc -l

Jul 15

I have a box at home that gets lots of information, but is more of an appliance then most of my machines. I would like it to be able to send events that get displayed to my MythTV frontends, but installing mythtvosd isn’t an option. Fortunately, in this case, MythTV uses a non encrypted XML over UDP scheme to get messages sent to the various frontend nodes. This means I can use netcat in UDP mode to just shoot an xml file out over my network and get the data I want on my TV screen without having to shoehorn mythtvosd onto the appliance.
I’ve created a file called message.xml that has the message that I would like to display on my TV in the format of my choosing. I prefer the scroller, but you can use the CID or alert XML schemas if you so choose. See the main.c source code file for mythtvosd in the contrib directory for the schemas.

<?xml version=”1.0″?>
<mythnotify version=”1″><container name=”news_scroller”><textarea name=”text_scroll”><value>Testing</value></textarea></container></mythnotify>

Then I just use netcat to send that message via UDP to my main frontend. I could broadcast this out to all of my frontend nodes, but prefer to do these messages in a targeted manner.

cat message.xml | nc -uv -q1 serenity 6948

The end result is that I can now get messages on my TV for everything from RSS updates to stock reports to firewall alerts. Anything that can be sent as a text string can be displayed!

Jul 15

Whenever WHIA encounters an error, I have it send me a twitter message letting me know.  Using the twitter API and curl, this is a simple operation.

curl –basic –user “Twitter_Username:Twitter_Password” –data status=”Twitter Message Here” http://twitter.com/statuses/update.xml

replace Twitter_Username with your username and Twitter_Password with your password, keeping the colon “:” as the separator.

May 17

I have this perl script called Get_Temperature.pl that has been giving me fits. It simply reads a serial port that gets updated every second and does some regex on those values. The script was slowly consuming more and more CPU over time and creating a huge backlog of data. By the time it had run for an hour, it was at 60% CPU. To help troubleshoot, I wanted to output the amount of CPU that the script was using every time it processed a string, so I used this.

ps -o pcpu,pid,user,args -C Get_Temperature.pl

the -C flag allows me to specify the process name instead of a PID and the output looks like this

%CPU PID USER COMMAND
0.0 1075 jason /usr/bin/perl ./Get_Temperature.pl

Quick, low impact and works.

Apr 29

Just taking a moment to geek out. I finished my arduino code for my home HVAC project and decided to give it a burn in test tonight. I have 5 DS18S20 temperature sensors connected via parasitic 1-wire to pin 10 on a boarduino. My code just goes out and does a beacon looking for any 1-wire devices on the network and then queries them. It takes that data, turns it from hex to a Fahrenheit temperature and then prints a colon delimited string with that information out onto the serial port. I had been using just 1 probe, so tonight I decided for giggles to hot add 4 more. I smacked the ICs onto the breadboard while everything was running and what do you know, the code picked the new units up and never skipped a beat! Cool!

« Previous Entries