-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpt_heartbeat_agent
executable file
·63 lines (48 loc) · 1.42 KB
/
pt_heartbeat_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
#! /usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "newrelic_plugin"
module PtHeartbeatAgent
class Agent < NewRelic::Plugin::Agent::Base
agent_guid "com.scoutmob.pt_heartbeat"
agent_version "1.0.3"
agent_config_options :name, :master_server_id, :database, :user, :password, :host
agent_human_labels("pt-heartbeat") { "pt-heartbeat on #{name}" }
def poll_cycle
heartbeat_options = [
'-D', database,
'--utc',
'--check'
]
if master_server_id
heartbeat_options << "--master-server-id=#{master_server_id}"
end
if user
heartbeat_options << '-u'
heartbeat_options << user
end
if password
heartbeat_options << '-p'
heartbeat_options << password
end
if host
heartbeat_options << '-h'
heartbeat_options << host
end
lag = `sudo pt-heartbeat #{heartbeat_options.join(' ')}`
puts lag
report_metric "ReplicationLag", "Value", lag.to_f
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 :pt_heartbeat, PtHeartbeatAgent
#
# Launch the agent; this never returns.
#
NewRelic::Plugin::Run.setup_and_run
end