Giter Site home page Giter Site logo

rocket_graylog's Introduction

RocketGraylog

Safe for production async wrapper around GELF & Graylog

Features

  • async send messages with concurrent-ruby actor
  • slow block execution notification
  • all internal errors supressed by default (but you can turn it on)
  • retry politics with Retriable gem
  • custom _topic with method_missing
  • test-ready

Rails configuration

Gemfile:

currently install available only through github:

gem 'rocket_graylog', github: 'https://github.com/rocketbank/rocket_graylog.git'

create config/initializers/rocket_graylog.rb with content:

RocketGraylog.configure do |cfg|
  cfg.facility    = "APPLICATION"
  cfg.host        = ENV["GRAYLOG"]
  cfg.port        = 5514
  cfg.protocol    = :tcp # :upd

  # raise errors on graylog host errors 
  # false means errors will be supressed and do not affect application
  # but message will be lost
  cfg.graylog_errors = false 

  # to retry request on graylog host errors just provide options for Retriable gem:
  # cfg.retry_on_host_errors = {
  #  :on => [Timeout::Error, Errno::ECONNREFUSED], :tries => 3
  # }

  # timeout for sending message to Gelf 
  cfg.send_timeout = 0.5

  # provide block for error notifications
  # cfg.error_hook = lambda do |error|
  #   Honeybadger.notify(error)
  # end

  cfg.test_mode = Rails.env.test?
end

Rails logging config/environments/production.rb:

Rails.application.configure do
  gelf = GELF::Logger.new(ENV['GRAYLOG'], 5514, "LAN", { :facility => "APPLICATION", :protocol => GELF::Protocol::UDP })
  gelf.rescue_network_errors = true
  config.logger = gelf
end

Usage

send event

RocketGraylog.notify("message", { :a => 100 })

send event with _topic: 'alerts'

RocketGraylog.notify_alerts("message")

notify if block time execution exceed threshold (10 seconds by default)

RocketGraylog.long_execution_detector(name: 'my_tag', threshold: 100.seconds) do
  sleep(101)
end

you will receive message long_execution_detector long_execution_detector_my_tag cost:101 threshold:100

tests/specs:

before(:each) do
  RocketGraylog.clear_test_queue!
end

it '...' do
  expect(RocketGraylog.queue.size).to eq(1)
  # ...
end

handy alias

Graylog.notify("test log message")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.