Heroku Add-on for Sumo Logic Quick Start

来源:互联网 时间:1970-01-01

In test driving the new Heroku Add-on for Sumo Logic beta, I needed to create a simple app on Heroku, then start logging data.Heroku is a managed container environment that supports several popular development stacks including Java, Ruby and Node.js.This Quick Start walks you through the steps of creating a Ruby app on Heroku, then shows how you can deploy the app and begin logging data in real-time using the Sumo Logic add-on.

The Ruby app is kind of fun, and shows the power of Ruby as a web development language. The app, which I call switcher, responds to different URLs based on the path (or route) the user has selected. Switcher uses Sinatra, an open source DSL for quickly creating web applications in Ruby. It is an alternative to other Ruby web application frameworks like Rails.

Setting up your environment

For this example, you’ll need to install Xcode, Homebrew, Git, RVM, Ruby, Rails, and Heroku Toolbelt. To save space, here’s a Gist that walks you through installing everything (plus Postgres and mySQL) on OS X Yosemite.

You’ll also need to signup forSumo Free. The Gist shows you how to install Heroku toolbelt. Part of that process is signing up for a free Heroku account.

After installing Heroku Toolbelt, you’ll have access to the heroku command from your command shell. Log in using the email address and password you used when creating your Sumo Logic and Heroku accounts:

$ heroku login

Enter your Heroku credentials.

Email: [email protected]


You should then see a message like:

Could not find an existing public key.

Would you like to generate one? [Yn]

Generating new SSH public key.

Uploading ssh public key /Users/jon/.ssh/id_rsa.pub

When first run, the heroku login command creates a SSH key which it then uploads to Heroku. You’re now ready to start development.

Creating a Gemfile

A Gemfile lets you specify any external dependencies for your application. These will typically be libraries that you will make use of when you write your app. Create a new file, and name it Gemfile, and add the following:

source ‘https://rubygems.org’

ruby ‘2.2.1’

gem ‘thin’

gem ‘sinatra’

This ensures that you’ll have the thin web server available, together with the Sinatra web framework.

If you followed the instructions in the Gist, you should have bundler installed. Instruct bundler to download and install the dependencies:

$ bundle install

Fetching gem metadata from https://rubygems.org/.. Resolving dependencies…

Installing daemons (1.1.9)

Using eventmachine (1.0.3)

. . .

That’s it. Now that you have all the gems in place, you’re ready to start coding.

Building a Sinatra App

Here’s a simple web application that responds to two different URLs, or routes: The root URL (/) will display “Home”, while the /hello URL will display a greeting. Start by creating a new file and calling it something like, FirstApp.rb.

require "sinatra/base"class MyApp < Sinatra::Baseget '/' do 'Home'endget '/hello' do'Hello, How is your logging example going?'endget '/hello/:name' do # matches "GET /hello/foo" and "GET /hello/bar" # params['name'] is 'foo' or 'bar' "Hello #{params['name']}!"endget '/posts' do # matches "GET /posts?title=foo&author=bar" title = params['title'] author = params['author']endrun! if app_file == $0end

To run the application locally, enter the following on the command line:

$ bundle exec ruby myapp.rb

You should see the following:

== Sinatra/1.4.3 has taken the stage on 4567 for development with backup from Thin

>> Thin web server (v1.5.1 codename Straight Razor)

>> Maximum connections set to 1024

>> Listening on localhost:4567, CTRL+C to stop

Now open your browser and visit http://localhost:4567 . You can also visit http://localhost:4567/hello and /posts.

Once you have verified your app is running use the Ctrl-C keystroke in your terminal to stop the app.

Deploying Your App

Now get the app up and running on Heroku. Deploying to Heroku involves sending the source code for the application to Heroku using Git . Heroku doesn’t require any changes to your app – it will run in a very similar manner in the cloud as it does locally. In particular, the Gemfile will be used by Heroku to pull down the dependencies, and the Procfile will be used to understand what command to execute to start the application.

First, add your application to Git:

$ git init .

$ git add .

$ git commit -m “First commit”

Now create the application on Heroku:

$ heroku create

You should see something like the following:

Creating limitless-anchorage-7606in organization heroku… done, region is us http://limitless-anchorage-7606.herokuapp.com/ | [email protected]:limitless-anchorage-7606.git

This command does a few things. Firstly, it creates a domain for the app.Secondly, it creates a Git remote (with a default name of heroku), which you can utilize for deployment. Use git push heroku master to deploy the app:

$ git push heroku master

You should see something like:

Counting objects: 1202, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (391/391), done.

Writing objects: 100% (1078/1078), 374.90 KiB | 412.00 KiB/s, done.

Total 1078 (delta 761), reused 990 (delta 684)

—–> Ruby/Rails app detected


Now you visit your application on the web using:

$ heroku open

This should launch your browser open to a URL that corresponds to the domain for the app.

Using the Add-on

Installingthe add-on is easy using addons:create . Simply run the following on the command line to create your app:

heroku addons:create sumologic –app <my_app_name>

Be sure to replace <my_app_name> with the name of your app.In my case, the app name is limitless-anchorage-7606. Thisconfigures your app, associating with the Sumo add-on and points the log drain to the Sumo Logic service for you automatically.

After installation, go to your app at https://dashboard.heroku.com/apps . You will see the installed add-on icon now appears below the search bar. A Sumo Logic account will have been created with the app owner’s email. App logs generated after installation will be forwarded to sumo logic.

To view your logs, click on the Sumo Logic add-on, which will open the Sumo Logic Web Application.

Now you can gather log data, check status, gather metrics, search your logs, set alerts and receive notifications, all from the Sumo Logic Web application.

About the Author

Michael is the Head of Developer Programs at Sumo Logic. You can follow him on Twitter @CodeJournalist or LinkedIn .