Project

healthety

0.0
No commit activity in last 3 years
No release in over 3 years
Sends JSON wrapped data via UDP packets to a given host.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.6.0

Runtime

~> 1.1.3
~> 1.5.1
 Project Readme

Ruby Worker

The Ruby Worker sends JSON wrapped data via UDP packets to a given host at a defined interval.

Installation

$ gem install healthety

Usage

require "healthety"

Healthety.workers do
  host "localhost"
  port 41234

  worker :load_average do
    interval 0.5
    # Gets load average with a system call (Mac OS X)
    value `w | head -n1 | cut -f4 -d":" | cut -f2 -d" "`.to_f
  end

  worker :random do
    interval 2
    value rand(10)
  end
end

That's all you need to do to define two different workers.

Defining helpers

If you want to define some helper methods create a new module first. Note the helpers method at the end to include your module into the workers. In this case a new file called connection_helper.rb contains the MySQL connection handling.

require "mysql2"

module Healthety
  module ConnectionHelper
    def mysql
      @client ||= Mysql2::Client.new(:host => "localhost", :username => "root")
    end
  end

  helpers ConnectionHelper
end

In your workers you can now use the helper method. Since the MySQL connection gets saved into a class instance variable the connection gets established only once.

$:.unshift File.dirname(__FILE__)

require "healthety"
require "connection_helper"

Healthety.workers do
  host "localhost"
  port 41234

  worker :user_count do
    interval 5
    value mysql.query("SELECT COUNT(*) AS count FROM users").first["count"]
  end
end