-
Notifications
You must be signed in to change notification settings - Fork 3
/
newrelic_puma_agent
executable file
·73 lines (54 loc) · 1.56 KB
/
newrelic_puma_agent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "newrelic_plugin"
require 'yaml'
require 'json'
require 'faraday'
module Puma
class Configuration
attr_reader :options
def initialize(options)
@options = options
end
def control_url
options[:control_url].gsub("tcp","http")
end
def control_auth_token
options[:control_auth_token]
end
def control_url_and_auth_token
[control_url,control_auth_token]
end
end
end
module PumaAgent
class Agent < NewRelic::Plugin::Agent::Base
agent_guid "com.ubxd.newrelic_puma"
agent_version "0.0.2"
agent_config_options :state_file
agent_human_labels("Puma Agent") { `hostname` }
def poll_cycle
control_url,control_auth_token = puma_config.control_url_and_auth_token
conn = Faraday.new(:url => "#{control_url}")
response = conn.get '/stats', { :token => control_auth_token }
result = JSON.parse(response.body)
report_metric "backlog", "threads", result['backlog'].to_i
report_metric "running", "threads", result['running'].to_i
end
def puma_config
YAML.load_file(state_file)['config']
end
end
#
# Register this agent with the component.
# The ExampleAgent is the name of the module that defines this
# driver (the module must contain at least three classes - a
# PollCycle, a Metric and an Agent class, as defined above).
#
NewRelic::Plugin::Setup.install_agent :puma, PumaAgent
#
# Launch the agent; this never returns.
#
NewRelic::Plugin::Run.setup_and_run
end