Going Old-School with Wavefront (or How I FaaS-ed my way to a JSON Endpoint)

August 30, 2018 Clement Pang

Departure Flap Board in GermanyDeparture board (split-flap) at Hannover Hauptbahnhof (Hannover main train station), Germany.

Wavefront is a hit with SaaS companies large and small dealing with the complexities of monitoring modern public/private cloud applications giving users full-stack visibility into infrastructure, cloud, application, packaged applications (e.g. Redis, etcd, MongoDB) and even end-user behavior. While the primary interaction with the system is over the browser for most users, I decided to go nostalgic and see what we can do with Wavefront and a bit of coding (no servers required).

Wavefront Chart Log ScaleA typical Wavefront chart with log scale

I happened to stumble upon a company based in France called Smiirl.com from Facebook and they sell these airport flap displays (I suppose they are technically called Split-flap displays: https://en.m.wikipedia.org/wiki/Split-flap_display) which allow you to not only monitor your Facebook likes or Instagram follows but also basically anything that exposes a publicly accessible endpoint (you can secure it somewhat with a pre-shared secret but given how the AWS API gateway works, it’s probably relatively safe to assume that it would be pretty hard to guess the URL).

Custom Flapboard from Smiirl ScreenshotSmiirl.com

They are a bit pricey but they let you customize the graphic on the side of the flaps and it’s quite a marvel to see when it’s delivered. You can hang it on the wall and it just needs wifi and power (Ethernet port is available and for many work places that need wifi sign-in, that helps a bit).

Custom Flapboard Pricing Screenshot5-digit and 7-digit custom counters

Wavefront 5 Digit Counter5-digit counter with Wavefront logo

Here’s the goal: display the results of a Wavefront query continuously on the Smiirl counter without hosting a single server, updating once an hour. This is not just a cost issue but rather you probably don’t want it to update all the time and end up having the room sound like a train station lobby 😛

Things you can conceivably show on the counter:

  • Number of users on the site in the last X hours
  • AWS cloud costs
  • Storage/Database utilization metrics
  • Business metrics
  • Metrics from your Tesla! (We have an integration for that)

AWS Lambda API Gateway ScreenshotAWS Lambda with API Gateway Hooked-up to it

Enter AWS Lambda, a service on AWS that anybody can sign up for and it manages all the mechanics of spinning up a server, running your code, and spinning it down. It has a free tier of 1M requests a month (as of this writing) and with the AWS API gateway (which, as of this writing, charged me 2 cents for the whole month), it allows you to host a code snippet that executes a Wavefront analytics query (which, btw, can be very complex, or simple, whatever you want it to be) and update the counter. You get to choose how often Smiirl polls Lambda for the results and the code snippet is really as straightforward as it can be:

var https = require('https');

exports.handler = (event, context, callback) => {
    console.log("Request received:\n", JSON.stringify(event));
    var options = {
        "method": "GET",
        "hostname": ".wavefront.com",
        "path": "/api/v2/chart/api?q=ts(my.metric)&s=" + ((new Date().getTime() - 1000) / 1000) + "&g=m&p=1&sorted=false",
        "headers": {
            "Content-Type": "application/json",
            "Authorization": "Bearer "

     const req = https.request(options, (res) => {
         console.log('statusCode:', res.statusCode);
         console.log('headers:', res.headers);
         var body = '';

         res.on('data', function(chunk) {
            body += chunk;

         res.on('end', function() {
            var queryResults = JSON.parse(body);
            callback(null, {
              "statusCode": 200,
              "body": JSON.stringify({ "number": Math.round(queryResults.timeseries[0].data[0][1]) }) });

     req.on('error', (e) => {
         console.log("Got error: " + e.message);
         context.done(null, 'FAILURE');
     console.log('end request'); //(4)

You just need to replace ts(my.metric) with the Wavefront query you want (you might need to url encode it). You also need a Wavefront API token (reach out to support@wavefront.com for a role account token so that it’s not tied to a user). You also need to specify the cluster (e.g. longboard.wavefront.com). The rest of the code is pretty self-explanatory. Hooking up AWS API Gateway nets you the URL:

AWS API Gateway ScreenshotSetting up AWS API Gateway for the AWS Lambda Function

Finally, you plop in the URL into Smiirl.com and select how frequently you want the flaps to, well, “flap”. We choose one hour at the office since it’s pretty loud (you can fix that also by changing the query so that it reports align hourly, summarized for instance too).

AWS URL Options ScreenshotPlop in the AWS API Gateway URL and off you go!

Wavefront Flapboard CountingYou can always trim off a couple digits by dividing the ts() expression so you don’t really need 7 digits unless you really want it 🙂

I did all of this while standing at my kitchen computer after opening the box from Smiirl.com, so it’s safe to say it’s relatively easy to pull this off (given that I already have an account with AWS that is, and even that is easy since you can use your Amazon.com sign-in and payment credentials to get started).

Finally, Wavefront offers a first-class integration SDK with AWS Lambda which lets you monitor beyond what CloudWatch gives you (also allows you to emit custom metrics). For Node.js, you can see the instructions here. With that, you also get metrics from your AWS Lambda functions in Wavefront.

Computing has gone a long way in recent years with cloud, containers and now serverless. While serverless (or FaaS) is still a nascent offering (and I doubt we’ll be wholesale writing everything with it anytime soon), there are use cases that works very well — e.g. I need a URL that does 10 lines of logic every hour probably fits the bill perfectly. Not having to run, maintain, patch and pay for the server is a great benefit.

Interested in learning more about Wavefront? Why not try it free for 30 days and get unlimited monitoring! Click here to sign up now.

Get Started with Wavefront Follow @panghy Follow @WavefrontHQ

The post Going Old-School with Wavefront (or How I FaaS-ed my way to a JSON Endpoint) appeared first on Wavefront by VMware.

How OKTA and uShip Scale their Cloud Services with Wavefront Monitoring – Part 1 of 2
How OKTA and uShip Scale their Cloud Services with Wavefront Monitoring – Part 1 of 2

Last week at VMworld, I had the pleasure to introduce the latest Wavefront enhancements and co-present with...

100,000 Containers and Counting! Wavefront Enterprise-Grade Enhancements Help Reliably and Securely Scale Cloud Applications
100,000 Containers and Counting! Wavefront Enterprise-Grade Enhancements Help Reliably and Securely Scale Cloud Applications

The major focus of the Wavefront release for VMworld 2018 is to enable our SaaS and cloud-enabled business ...

Visionary in Gartner® Magic Quadrant™

Learn More