Project

bernard

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Sends event data to visualisation services.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.10
~> 11.1
~> 3.4
~> 1.24
 Project Readme

Bernard

Sends event data to visualisation services.

Currently supporting:

  • Keen.io

bernard

Install

Add this line to your application's Gemfile:

gem 'bernard', '~> 2.0.0'

And then execute:

$ bundle

Basic setup

Create a new client on the fly:

client = Bernard::Keen::Client.new(
  application_name: '<YOUR APPLICATION NAME>'
  project_id: '<YOUR PROJECT ID>'
  write_key: '<YOUR WRITE KEY>'
  ready_key: '<YOUR READ KEY>'
)

Usage

Tick

Increment an event that has occurred by 1.

client.tick('foo')

Count

Increment an event that has occurred by 5.

client.count('visitors', '5')

Gauge

Update an event to a new value.

client.gauge('office_noise_level', '43')

Splat

Update multiple events at once

events = [
  { value: { name: 'ruby', count: 1 }, application_name: 'demo', type: 'github_language'} },
  { value: { name: 'go', count: 2 }, application_name: 'demo', type: 'github_language'} },
]
client.splat(events)

Advanced configuration

Initializer

Create a new initializer config/bernard.rb in your application

Bernard::Keen::Client.configure do |client|
  client.config = {
    application_name: '<YOUR APPLICATION NAME>',
    project_id: '<YOUR PROJECT ID>',
    write_key: '<YOUR WRITE KEY>',
    read_key: '<YOUR READ KEY>'
  }
end

Run asynchronously

Given that this Gem is making HTTP requests which can be slow, we'd advise using a worker like Sidekiq.

For example adding this to your applications's workers/bernard_worker.rb file:

require 'bernard'

class BernardWorker
  include Sidekiq::Worker

  def perform(event_type, event_name, value = 0)
    case event_type.to_sym
    when :tick then Bernard::Keen::Client.new.tick(event_name)
    when :count then Bernard::Keen::Client.new.count(event_name, value)
    when :gauge then Bernard::Keen::Client.new.gauge(event_name, value)
    else
    end
  end
end

and invoke using this worker instead to ensure it doesn't interrupt your application's processes:

BernardWorker.perform_async(:tick, :vote)
BernardWorker.perform_async(:count, :visitors, 3)
BernardWorker.perform_async(:gauge, :temperature, 32.5)

License

(c) 2016 The Dextrous Web Ltd. Released under the MIT license.