-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnewrelic_redborder_agent
executable file
·188 lines (173 loc) · 6.24 KB
/
newrelic_redborder_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#! /usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'snmp'
require 'pry'
require_relative 'src/druid-master'
require_relative 'src/nginx-master'
require_relative 'src/chef-master'
require_relative 'src/check-master'
require_relative 'lib/rb-monitor'
require 'newrelic_plugin'
require('logger')
require 'rationalist'
module RedborderAgent
class Agent < NewRelic::Plugin::Agent::Base
# Agent configuration
agent_guid 'com.redborder.redborder'
agent_version '1.0.2'
agent_config_options :snmp_host, :snmp_community, :services
agent_human_labels('Manager') { 'testingCluster' }
$logger = Logger.new('/var/log/newrelic/plugin.log')
argv = Rationalist.parse(ARGV)
# ./newrelic_redborder_agent --log debug
if (argv[:log] == 'debug')
$logger.level = Logger::DEBUG
else
$logger.level = Logger::INFO
end
$metrics = []
$nginx = []
$chef = []
$check = []
$logger.formatter = proc do |severity, datetime, progname, msg|
'#{severity}: #{datetime}: #{msg}\n'
end
$i=0
$var = 0
$number = 0
# Thread managers for detailed services
druid_master
nginx_master
chef_master
Thread.new do
$logger.debug('Nginx recolector launched')
recolector($nginx)
end
Thread.new do
$logger.debug('Druid recolector launched')
recolector($metrics)
end
def poll_cycle
# poll_cycle is the loop where the agent collect&report metrics
host = `hostname`.strip
# SNMP manager initialization
SNMP::Manager.open(community: snmp_community, host: snmp_host) do |manager|
memory_total = mem_total(manager)
services.each do |service|
check_master(service)
end
memory = (memory_total -
mem_free(manager) -
mem_total_buffer(manager) -
mem_total_cache(manager)) * 100
#----------------------------------- RB_MONITOR METRICS ---------------
report_metric 'CPU_PERC_' + host,
'Value', cpu(manager)
report_metric 'LATENCY_' + host,
'Value', latency(host)
report_metric 'PKTS_RCV_' + host,
'Value', pkts_rcv(host)
report_metric 'MEM_TOTAL_' + host,
'Value', memory_total
report_metric 'MEM_FREE_' + host,
'Value', mem_free(manager)
report_metric 'MEM_TOTAL_BUFFER_' + host,
'Value', mem_total_buffer(manager)
report_metric 'MEM_TOTAL_CACHE_' + host,
'Value', mem_total_cache(manager)
report_metric 'MEM_PERC_' + host,
'Value', memory / memory_total
# (disk utilization)avio shows the average number of milliseconds p/req
report_metric 'AVIO_' + host,
'Value', get_avio()
report_metric 'DISK_PERCENT_' + host,
'Value', disk_percent(manager)
report_metric 'DISK_LOAD_' + host,
'Value', disk_load()
report_metric 'MEMORY_DRUID_BROKER_' + host,
'Value', 100 * memory_total_druid_broker()/memory_total
report_metric 'MEMORY_DRUID_COORDINATOR_' + host,
'Value', 100 * memory_total_druid_coordinator()/memory_total
report_metric 'MEMORY_DRUID_HISTORICAL_' + host,
'Value', 100 * memory_total_druid_historical()/memory_total
report_metric 'MEMORY_DRUID_REALTIME_' + host,
'Value', 100 * memory_total_druid_realtime()/memory_total
report_metric 'MEMORY_KAFKA_' + host,
'Value', 100 * memory_total_kafka()/memory_total
report_metric 'MEMORY_NPROBE_' + host,
'Value', 100 * memory_total_nprobe()/memory_total
report_metric 'MEMORY_POSTGRESQL_' + host,
'Value', 100 * memory_total_postgresql()/memory_total
report_metric 'MEMORY_RBWEBUI_' + host,
'Value', 100 * memory_total_rbwebui()/memory_total
report_metric 'MEMORY_ZOOKEEPER_' + host,
'Value', 100 * memory_total_zookeeper()/memory_total
report_metric 'jvm_mem_init',
'Value', 1
end
$logger.debug('General metrics reported')
#
# Druid metrics reporting
#
$metrics.each do |m|
unless m['metric'].nil? || m['service'].nil? || m['value'].nil?
report_metric 'druid_' +
m['metric'] + '_' + m['service'] + '_' + host, 'Value', m['value']
m['ttl'] -= 1
# puts 'druid_' + m['metric'] + m['service'] + '_' + host + ' Value: ' + m['value'].to_s
end
end
$logger.debug('Druid metrics reported')
#
# Nginx metrics reporting
#
$nginx.each do |m|
unless m['status'].nil? || m['times'].nil?
report_metric 'nginx_' + m['status'] + '_' + host, 'Value', m['times']
m['ttl'] -= 1
# puts 'nginx_' + m['status'] + '_' + host + ' Value: ' + m['times'].to_s
end
end
$logger.debug('Nginx metrics reported')
#
# Chef metrics reporting
#
$chef.each do |m|
unless m['error'].nil? || m['times'].nil?
report_metric 'chef_' + m['error'] + '_' + host, 'Value', m['times']
# puts 'chef_' + m['error'] + '_' + host + ' Value: ' + m['times'].to_s
end
end
$logger.debug('Chef metrics reported')
#
# Check metrics reporting
#
$check.each do |m|
unless m['service'].nil? || m['value'].nil?
report_metric 'check_' + m['service'] + '_' + host, 'Value', m['value']
# puts 'check_' + m['service'] + '_' + host + ' Value: ' + m['value'].to_s
end
end
$logger.debug('Checks metrics reported')
$i += 1
$number+=1
if $i%60 == 0
chef_recolector
$logger.debug('Chef recolector executed')
end
end
$logger.info('Pollcycle number ' + $number.to_s + ' finished ')
end
#
# Register this agent with the component.
# The RedborderAgent 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 :redborder, RedborderAgent
#
# Launch the agent
#
NewRelic::Plugin::Run.setup_and_run
end