lib/heartbeat-client.rb in heartbeat-client-0.4.4 vs lib/heartbeat-client.rb in heartbeat-client-0.5.0
- old
+ new
@@ -3,10 +3,11 @@
require 'httparty'
require 'logger'
require 'macaddr'
require 'net/http'
require 'json'
+require 'keen'
class Heartbeat
include HTTParty
def self.is_mac?
@@ -31,10 +32,13 @@
apikey = config['apikey']
endpoint = config['endpoint']
name = config['name']
apache_status = config['apache_status']
mongostat_arguments = config['mongostat_arguments']
+ keen_project_token = config['keen_project_token']
+ keen_api_key = config['keen_api_key']
+ keen_collection = config['keen_collection']
if gather_metrics
procs = {'total' => 0, 'running' => 0, 'stuck' => 0, 'sleeping' => 0, 'threads' => 0, 'stopped' => 0, 'zombie' => 0}
load_avg = []
cpu_usage = {'user' => 0, 'sys' => 0, 'idle' => 0}
@@ -143,9 +147,15 @@
}
log.info("#create - Sending data to endpoint (with metrics)...")
res = Heartbeat.post(endpoint + '/heartbeat', options)
log.debug("Response: #{res.response.inspect}") if res
+
+ if keen_project_token and keen_api_key and keen_collection
+ keen = Keen::Client.new(:project_id => keen_project_token, :api_key => keen_api_key)
+ data = options[:body][:heartbeat]
+ keen.publish(keen_collection, {:host => data[:host], :cpu => data[:values][:cpu_usage]})
+ end
else
log.error "No top output found."
end
else
options = {