Skip to content

Log Insight: Analyzing the Weather

Collecting log messages and analyzing them with Log Insight is easy, but what about collecting and monitoring other types of events? How about logging and analyzing the weather for example?! Read on to learn how.

NOTE: My good friend and colleague Tomas Baublys did an awesome blog post on how to log the weather with Log Insight here. With his permission, I am doing an english version of the post. The concept, information, and content pack are all his work.

How to collect the weather

First, a script to collect weather metrics (this one requires cURL and logger):

Next, save and run the script on a schedule. For example, to run the script every five minutes with cron use something like:

The output of the cURL command is a JSON string like:

The string is sent over the syslog protocol as defined by the logger command. While the logger command can be run without flags, I would encourage looking at the logger man page and consider adding at least a tag to messages to make querying easier. Also, newer versions of the logger command support sending events to a remote syslog destination via flags.

How to send weather data to Log Insight

If the logger command supports sending to a remote syslog destination then this is one way to get the data into Log Insight. An alternative is to have logger log to the local system and then use a syslog agent like syslog-ng or rsyslog to forward events to Log Insight. I covered forwarding events using a syslog agent in this post.

Analyzing weather data in Log Insight

Looking on the Interactive Analytics page of Log Insight you should see weather events coming in based on the schedule you set above. The JSON format of the event makes it easy to extract useful pieces of information such as the wind speed. To do this, highlight the wind speed, select the Extract Field option, and give the field a name (if you used the tag flag on logger you may want to add that information into the pre-context of the field):
log-insight-speed
Once you extract the fields you care about, you can use the fields in queries and as part of aggregation functions and groupings to change the visual representation of events at the top of the screen. For example, you can select the maximum wind speed over time:
log-insight-maximum-speed
The possibilities of what you can analyze is only limited by the information provided in the JSON. Here is an example of a content pack analyzing the weather:
log-insight-weather
Here is an example content pack: Weather.vlcp

NOTE: This content pack is based on, but different from the one created by Tomas:

  • Generalized queries
  • Grouped by coordinates to support multiple locations
  • Optimized extracted fields for performance

How about other types of data

This is just one example of collecting and analyzing data with Log Insight. The possibilities are endless! Another example would be to monitor stock prices. Here is a sample script that would do just that:

All the credit goes to Tomas, great work!
UPDATE: I was asked if the weather could be collected an analyzed without using cURL and logger. Basically, you need a way to collect the weather and cURL is one way to do it. Another option would be to use wget. Alternatively, if you have a way to get the data on the filesystem you could use that as well. Logger is used to send the events over syslog either locally or to a remote destination. As an alternative to logger, you could just write the data to a file and then have a syslog agent monitor the file and send the changes over syslog to Log Insight. I covered monitoring a file in this blog post.

© 2013, Steve Flanders. All rights reserved.

Published inVMware

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *