My Big Data "Pet" Project: How I used Splunk to be a better lizard parent

Can't remember when the last time you fed your lizard (or other pet of choice) was? Wondering if her tank was left at the perfect temperature to keep cozy during the snowstorm? In Ryan's latest blog, he discusses how he utilized Splunk to assist him in the parenting care of his niece’s famed 3rd grade class lizard and his new pet: Glitzy Whitaker.

Areas that get heavy snowfall are susceptible to dangerous road conditions. This means that people end up trapped inside. So, what is there to do when this happens? Why not work on one of your pet projects? That’s exactly what I did for part of the first snowfall of the year in Connecticut. 

Allow me to introduce you to the famed lizard from my niece’s 3rd grade class, and my new pet: Glitzy Whitaker.

Glitzy is a Green Anole that my niece “won”, named, and I ended up adopting. The jury is still out on if I actually “won” Glitzy, or if my niece just wanted a lizard and dropped it off at my house. Nevertheless, I don’t have any choice in the matter and I am therefore embracing my new parent status.

When I received this lizard, I did what any respectable parent would do: Started to worry. I had so many immediate questions. Could I afford this lizard child? Was I feeding this precious little angel enough? Was her tank nice and warm and cozy? I wanted to answer as many of these questions as I could. Of course, this is a Splunk-centered article, so you better believe there is some data coming to backup my terrific parenting skills.

Was I feeding Glitzy enough?

To answer this question, I had to first define “enough”. I was told when I adopted Glitzy that feeding her twice a week was the appropriate amount. That seems to align with most websites I read. Seeing as how I am not a reptile expert, I’m happy to hear any feedback anyone has on this number. I did look into a couple different websites and they told me this twice a week number was about right.

http://www.reptilesncritters.com/care-guide-brown-anole.html

http://lizardsandfriends.org/wp-content/uploads/2013/06/lizardcare_STI2013.pdf

So, how can I track feeding a Lizard with data? I’m sure there are many ways, but this one is actually somewhat manual so far. As it stands, I’m exporting a CSV of my credit card transactions at the local pet store. I’m not going to screenshot that process for obvious reasons.

The data collection is 90% done for me, as long as I purchase crickets with my credit card. I just need to copy and paste my transactions from my Credit Card’s website into a lookup table. This seems to work quite well so far for my needs. One really nice app to get this done is the Lookup File Editor app.

With the table populated, I can run a quick search to look at feeding times over time. I can actually use some fancy SPL to turn a date from a lookup table into a _time field to be used with the timechart command as shown below.

And, if I’m at work, and I can’t remember if I need to buy crickets, I just ask Alexa: “Alexa, Ask Splunk ‘When was the last time Ryan fed his Lizard?’”

Was Glitzy’s tank warm enough?

This was my favorite part of this project. I didn’t want to have a thermometer I had to manually read sitting on the side of the tank, I wanted to know how many rays of light my precious little lizard was soaking up, in real-time. I finally had a legitimate use case for building a circuit with a Raspberry Pi. The circuit was straightforward with great instructions that can be found here.

Once I had the circuit constructed, I slightly modified the script provided in the article mentioned above. This resulted in a very simple python script that could export data from my thermometer at a given internal.

therm.py

import os

import glob

import time



os.system('modprobe w1-gpio')

os.system('modprobe w1-therm')



base_dir = '/sys/bus/w1/devices/'

device_folder = glob.glob(base_dir + '28*')[0]

device_file = device_folder + '/w1_slave'



def read_temp_raw():

   f = open(device_file, 'r')

   lines = f.readlines()

   f.close()

   return lines



def read_temp():

   lines = read_temp_raw()

   while lines[0].strip()[-3:] != 'YES':

       time.sleep(0.2)

       lines = read_temp_raw()

   equals_pos = lines[1].find('t=')

   if equals_pos != -1:

       temp_string = lines[1][equals_pos+2:]

       temp_c = float(temp_string) / 1000.0

       temp_f = temp_c * 9.0 / 5.0 + 32.0

       return "temp_c="+str(temp_c)+" "+"temp_f="+str(temp_f)

print(read_temp())

With the script created, the rest of this was simple. I already had a Raspberry Pi up and running with the Splunk Universal Forwarder for my Coffee, so I just needed to create a small app that can be found here to run this script and send the data to my Splunk instance. So, what does that data look like?

Could I afford to take care of Glitzy?

This was a fun question to answer and I had to think through how I was going to do it. To start, I had to determine all of my costs. I figured my costs were limited to a couple of different things.  

  1. What was it costing me to heat the tank?
  2. What was it costing me to feed Glitzy?

What was it costing me to feed Glitzy?

Figuring out cost of feeding this little beast was pretty straight forward. Like I said before, it is somewhat manual. So, finding that data was a matter of using my lookup table.

What was it costing me to heat the tank?

Measuring the cost of heating was fairly straightforward by using some of the technology I had already set up for my coffee blog. The TP-Link has proven to be a really versatile device and is capable of outputting some great data on a very regular basis. In my case, I have a power strip hooked up to it with both of my light bulbs and a heating pad. It looks something like this.

The reason I’m showing you this diagram is that even though there are three different devices here, the amount of kWh they are using, is all going to be recorded on the same TP-Link. As a result I can take the number of kWh from my TP-Link, multiply it by my cost per kWh ($0.0814) from my electric bill, and automatically I will have a cost of how much this tank cost me to run that day. As it turns out, this tank setup is quite inexpensive. Overall, the days I’m spending the most money on Glitzy, are the days I’m buying crickets.

Another benefit to this configuration is that even though these devices are all through the same TP-Link, they all have different electrical signatures. So the combination of any two devices should be unique. This way I can still determine when my Day light is on, and when the Night Light is on. This is extremely helpful if I can’t remember if I switched it. I can say to Alexa, “Alexa ask Splunk what light is on in the lizard tank?”



Close off Canvas Menu