netuitive_ruby_api 0.9.8 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -11
- data/config/agent.yml +3 -0
- data/lib/netuitive_ruby_api.rb +74 -13
- data/lib/netuitive_ruby_api/config_manager.rb +76 -0
- data/lib/netuitive_ruby_api/netuitive_logger.rb +49 -0
- metadata +4 -4
- data/lib/netuitive/netuitive_ruby_logger.rb +0 -24
- data/lib/netuitive/ruby_config_manager.rb +0 -50
data/README.md
CHANGED
@@ -1,21 +1,29 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Netuitive Ruby API
|
2
|
+
===================
|
3
3
|
|
4
|
-
|
5
|
-
netuitived must be running
|
4
|
+
The Netuitive Ruby API provides an easy interface to communicate with the Netuitive Ruby daemon [NetuitiveD](https://rubygems.org/gems/netuitived). NetuitiveD is meant to work in conjunction with NetuitiveD and the [netuitive_rails_agent](https://rubygems.org/gems/netuitive_rails_agent) gem to help [Netuitive](https://www.netuitive.com) monitor your Ruby applications.
|
6
5
|
|
7
|
-
|
6
|
+
For more information on the Netuitive Ruby API, see our Ruby agent [help docs](https://help.netuitive.com/Content/Misc/Datasources/new_ruby_datasource.htm), or contact Netuitive support at [support@netuitive.com](mailto:support@netuitive.com).
|
8
7
|
|
9
|
-
|
8
|
+
Requirements
|
9
|
+
-------------
|
10
10
|
|
11
|
-
|
11
|
+
[NetuitiveD](https://github.com/Netuitive/netuitived) must be installed and running.
|
12
12
|
|
13
|
-
|
13
|
+
Installing the Netuitive Ruby API
|
14
|
+
----------------------------------
|
15
|
+
|
16
|
+
`gem install netuitive_ruby_api`
|
17
|
+
|
18
|
+
Using the Netuitive Ruby API
|
19
|
+
-----------------------------
|
14
20
|
|
15
21
|
Single sample example:
|
16
|
-
|
22
|
+
|
23
|
+
NetuitiveRubyAPI::netuitivedServer.addSample("metric.name", [metric value])
|
17
24
|
|
18
25
|
Add the aggregation value to the existing value for the metric for this interval:
|
19
|
-
NetuitiveRubyAPI::netuitivedServer.aggregateMetric("metric.name", [aggregation value])
|
20
26
|
|
21
|
-
|
27
|
+
NetuitiveRubyAPI::netuitivedServer.aggregateMetric("metric.name", [aggregation value])
|
28
|
+
|
29
|
+
An aggregation value is the sum of metric values over the course of a single interval. Aggregation can be quite useful for datasets like the number of requests per minute.
|
data/config/agent.yml
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
#all are configurable using environment variables
|
2
|
+
logLocation: #absolute path of log file. leave blank for default location in the gem directory. environment variable: NETUITIVE_RUBY_LOG_LOCATION
|
3
|
+
logAge: daily #Number of old log files to keep, or frequency of rotation (daily, weekly or monthly). environment variable: NETUITIVE_RUBY_LOG_AGE
|
4
|
+
logSize: #Maximum logfile size in bytes (only applies when shift_age is a number). environment variable: NETUITIVE_RUBY_LOG_SIZE
|
2
5
|
debugLevel: info #options (in ascending order of debugness) are: error, info, debug. environment variable: NETUITIVE_RUBY_DEBUG_LEVEL
|
3
6
|
netuitivedAddr: localhost #environment variable: NETUITIVE_RUBY_NETUITIVED_ADDR
|
4
7
|
netuitivedPort: 8875 #environment variable: NETUITIVE_RUBY_NETUITIVED_PORT
|
data/lib/netuitive_ruby_api.rb
CHANGED
@@ -1,17 +1,78 @@
|
|
1
|
-
require '
|
1
|
+
require 'yaml'
|
2
|
+
require 'logger'
|
2
3
|
require 'drb/drb'
|
4
|
+
require 'netuitive_ruby_api/config_manager'
|
5
|
+
require 'netuitive_ruby_api/netuitive_logger'
|
6
|
+
|
3
7
|
class NetuitiveRubyAPI
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
class << self
|
9
|
+
def setup(server)
|
10
|
+
@@netuitivedServer = server
|
11
|
+
end
|
12
|
+
|
13
|
+
def netuitivedServer
|
14
|
+
@@netuitivedServer
|
15
|
+
end
|
16
|
+
|
17
|
+
def send_metrics
|
18
|
+
server_interaction { netuitivedServer.sendMetrics }
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_sample(metric_id, val)
|
22
|
+
server_interaction { netuitivedServer.addSample(metric_id, val) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_counter_sample(metric_id, val)
|
26
|
+
server_interaction { netuitivedServer.addCounterSample(metric_id, val) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def aggregate_metric(metric_id, val)
|
30
|
+
server_interaction { netuitivedServer.aggregateMetric(metric_id, val) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def aggregate_counter_metric(metric_id, val)
|
34
|
+
server_interaction { netuitivedServer.aggregateCounterMetric(metric_id, val) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def clear_metrics
|
38
|
+
server_interaction { netuitivedServer.clearMetrics }
|
39
|
+
end
|
40
|
+
|
41
|
+
def interval
|
42
|
+
netuitivedServer.interval # synchronous for return value
|
43
|
+
end
|
44
|
+
|
45
|
+
def event(message, timestamp = Time.new, title = 'Ruby Event', level = 'Info', source = 'Ruby Agent', type = 'INFO', tags = nil)
|
46
|
+
server_interaction { netuitivedServer.event(message, timestamp, title, level, source, type, tags) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def exception_event(exception, klass = nil, tags = nil)
|
50
|
+
server_interaction do
|
51
|
+
hash = { message: exception.message }
|
52
|
+
hash[:backtrace] = exception.backtrace.join("\n\t") if (defined? exception.backtrace) && !exception.backtrace.nil?
|
53
|
+
netuitivedServer.exceptionEvent(hash, klass, tags)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def stop_server
|
58
|
+
server_interaction { netuitivedServer.stopServer }
|
59
|
+
end
|
60
|
+
|
61
|
+
def server_interaction
|
62
|
+
Thread.new do
|
63
|
+
begin
|
64
|
+
yield
|
65
|
+
rescue => e
|
66
|
+
NetuitiveRubyApi::NetuitiveLogger.log.error "unable to connect to netuitived: message:#{e.message} backtrace:#{e.backtrace}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
13
71
|
end
|
14
|
-
|
15
|
-
|
72
|
+
|
73
|
+
NetuitiveRubyApi::ConfigManager.load_config
|
74
|
+
NetuitiveRubyApi::NetuitiveLogger.setup
|
75
|
+
NetuitiveRubyApi::ConfigManager.read_config
|
76
|
+
SERVER_URI = "druby://#{NetuitiveRubyApi::ConfigManager.netuitivedAddr}:#{NetuitiveRubyApi::ConfigManager.netuitivedPort}".freeze
|
16
77
|
DRb.start_service
|
17
|
-
NetuitiveRubyAPI.setup(DRbObject.new_with_uri(SERVER_URI))
|
78
|
+
NetuitiveRubyAPI.setup(DRbObject.new_with_uri(SERVER_URI))
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module NetuitiveRubyApi
|
2
|
+
class ConfigManager
|
3
|
+
class << self
|
4
|
+
attr_reader :netuitivedAddr
|
5
|
+
|
6
|
+
attr_reader :netuitivedPort
|
7
|
+
|
8
|
+
attr_reader :data
|
9
|
+
|
10
|
+
def property(name, var, default = nil)
|
11
|
+
prop = ENV[var]
|
12
|
+
prop = data[name] if prop.nil? || (prop == '')
|
13
|
+
return prop unless prop.nil? || (prop == '')
|
14
|
+
default
|
15
|
+
end
|
16
|
+
|
17
|
+
def boolean_property(name, var)
|
18
|
+
prop = ENV[var].nil? ? nil : ENV[var].dup
|
19
|
+
if prop.nil? || (prop == '')
|
20
|
+
prop = data[name]
|
21
|
+
else
|
22
|
+
prop.strip!
|
23
|
+
prop = prop.casecmp('true').zero?
|
24
|
+
end
|
25
|
+
prop
|
26
|
+
end
|
27
|
+
|
28
|
+
def float_property(name, var)
|
29
|
+
prop = ENV[var].nil? ? nil : ENV[var]
|
30
|
+
if prop.nil? || (prop == '')
|
31
|
+
data[name].to_f
|
32
|
+
else
|
33
|
+
prop.to_f
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def string_list_property(name, var)
|
38
|
+
list = []
|
39
|
+
prop = ENV[var].nil? ? nil : ENV[var].dup
|
40
|
+
if prop.nil? || (prop == '')
|
41
|
+
list = data[name] if !data[name].nil? && data[name].is_a?(Array)
|
42
|
+
else
|
43
|
+
list = prop.split(',')
|
44
|
+
end
|
45
|
+
list.each(&:strip!) unless list.empty?
|
46
|
+
list
|
47
|
+
end
|
48
|
+
|
49
|
+
def load_config
|
50
|
+
gem_root = File.expand_path('../../..', __FILE__)
|
51
|
+
@data = YAML.load_file "#{gem_root}/config/agent.yml"
|
52
|
+
end
|
53
|
+
|
54
|
+
def read_config
|
55
|
+
@netuitivedAddr = property('netuitivedAddr', 'NETUITIVE_RUBY_NETUITIVED_ADDR')
|
56
|
+
@netuitivedPort = property('netuitivedPort', 'NETUITIVE_RUBY_NETUITIVED_PORT')
|
57
|
+
debugLevelString = property('debugLevel', 'NETUITIVE_RUBY_DEBUG_LEVEL')
|
58
|
+
NetuitiveRubyApi::NetuitiveLogger.log.level = if debugLevelString == 'error'
|
59
|
+
Logger::ERROR
|
60
|
+
elsif debugLevelString == 'info'
|
61
|
+
Logger::INFO
|
62
|
+
elsif debugLevelString == 'debug'
|
63
|
+
Logger::DEBUG
|
64
|
+
else
|
65
|
+
Logger::ERROR
|
66
|
+
end
|
67
|
+
NetuitiveRubyApi::NetuitiveLogger.log.info "port: #{@netuitivedPort}"
|
68
|
+
NetuitiveRubyApi::NetuitiveLogger.log.info "addr: #{@netuitivedAddr}"
|
69
|
+
NetuitiveRubyApi::NetuitiveLogger.log.debug "read config file. Results:
|
70
|
+
netuitivedAddr: #{@netuitivedAddr}
|
71
|
+
netuitivedPort: #{@netuitivedPort}
|
72
|
+
debugLevel: #{debugLevelString}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'logger'
|
2
|
+
module NetuitiveRubyApi
|
3
|
+
class CheaterLogger
|
4
|
+
attr_accessor :level
|
5
|
+
def debug(message)
|
6
|
+
end
|
7
|
+
|
8
|
+
def error(message)
|
9
|
+
end
|
10
|
+
|
11
|
+
def info(message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class NetuitiveLogger
|
16
|
+
class << self
|
17
|
+
attr_reader :log
|
18
|
+
def setup
|
19
|
+
file = NetuitiveRubyApi::ConfigManager.property('logLocation', 'NETUITIVE_RUBY_LOG_LOCATION', "#{File.expand_path('../../..', __FILE__)}/log/netuitive.log")
|
20
|
+
age = NetuitiveRubyApi::ConfigManager.property('logAge', 'NETUITIVE_RUBY_LOG_AGE', 'daily')
|
21
|
+
age = format_age(age)
|
22
|
+
size = NetuitiveRubyApi::ConfigManager.property('logSize', 'NETUITIVE_RUBY_LOG_SIZE', 1_000_000)
|
23
|
+
size = format_size(size)
|
24
|
+
@log = Logger.new(file, age, size)
|
25
|
+
rescue => e
|
26
|
+
puts "netuitive unable to open log file. error: #{e.message}, backtrace: #{e.backtrace}"
|
27
|
+
@log = NetuitiveRubyApi::CheaterLogger.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def format_age(age)
|
31
|
+
return 'daily' if age.nil?
|
32
|
+
begin
|
33
|
+
Integer(age)
|
34
|
+
rescue
|
35
|
+
age
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def format_size(size)
|
40
|
+
return 1_000_000 if size.nil?
|
41
|
+
begin
|
42
|
+
Integer(size)
|
43
|
+
rescue
|
44
|
+
size
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netuitive_ruby_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Allows for easy submittion of metrics to Netuitive
|
15
15
|
email: jking@netuitive.com
|
@@ -17,8 +17,8 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- lib/
|
21
|
-
- lib/
|
20
|
+
- lib/netuitive_ruby_api/netuitive_logger.rb
|
21
|
+
- lib/netuitive_ruby_api/config_manager.rb
|
22
22
|
- lib/netuitive_ruby_api.rb
|
23
23
|
- config/agent.yml
|
24
24
|
- ./LICENSE
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
class CheaterLogger
|
3
|
-
attr_accessor :level
|
4
|
-
def debug(message)
|
5
|
-
end
|
6
|
-
def error(message)
|
7
|
-
end
|
8
|
-
def info(message)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class NetuitiveLogger
|
13
|
-
begin
|
14
|
-
@@log = Logger.new("#{File.expand_path("../../..", __FILE__)}/log/netuitive.log",'daily', 10)
|
15
|
-
rescue
|
16
|
-
puts "netuitive unable to open log file"
|
17
|
-
@@log = CheaterLogger.new
|
18
|
-
end
|
19
|
-
class << self
|
20
|
-
def log
|
21
|
-
return @@log
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'netuitive/netuitive_ruby_logger'
|
2
|
-
require 'yaml'
|
3
|
-
class ConfigManager
|
4
|
-
|
5
|
-
class << self
|
6
|
-
def setup()
|
7
|
-
readConfig()
|
8
|
-
end
|
9
|
-
|
10
|
-
def netuitivedAddr
|
11
|
-
@@netuitivedAddr
|
12
|
-
end
|
13
|
-
|
14
|
-
def netuitivedPort
|
15
|
-
@@netuitivedPort
|
16
|
-
end
|
17
|
-
|
18
|
-
def readConfig()
|
19
|
-
gem_root= File.expand_path("../../..", __FILE__)
|
20
|
-
data=YAML.load_file "#{gem_root}/config/agent.yml"
|
21
|
-
@@netuitivedAddr=ENV["NETUITIVE_RUBY_NETUITIVED_ADDR"]
|
22
|
-
if(@@netuitivedAddr == nil or @@netuitivedAddr == "")
|
23
|
-
@@netuitivedAddr=data["netuitivedAddr"]
|
24
|
-
end
|
25
|
-
@@netuitivedPort=ENV["NETUITIVE_RUBY_NETUITIVED_PORT"]
|
26
|
-
if(@@netuitivedPort == nil or @@netuitivedPort == "")
|
27
|
-
@@netuitivedPort=data["netuitivedPort"]
|
28
|
-
end
|
29
|
-
debugLevelString=ENV["NETUITIVE_RUBY_DEBUG_LEVEL"]
|
30
|
-
if(debugLevelString == nil or debugLevelString == "")
|
31
|
-
debugLevelString=data["debugLevel"]
|
32
|
-
end
|
33
|
-
NetuitiveLogger.log.info "port: #{@@netuitivedPort}"
|
34
|
-
NetuitiveLogger.log.info "addr: #{@@netuitivedAddr}"
|
35
|
-
if debugLevelString == "error"
|
36
|
-
NetuitiveLogger.log.level = Logger::ERROR
|
37
|
-
elsif debugLevelString == "info"
|
38
|
-
NetuitiveLogger.log.level = Logger::INFO
|
39
|
-
elsif debugLevelString == "debug"
|
40
|
-
NetuitiveLogger.log.level = Logger::DEBUG
|
41
|
-
else
|
42
|
-
NetuitiveLogger.log.level = Logger::ERROR
|
43
|
-
end
|
44
|
-
NetuitiveLogger.log.debug "read config file. Results:
|
45
|
-
netuitivedAddr: #{@@netuitivedAddr}
|
46
|
-
netuitivedPort: #{@@netuitivedPort}
|
47
|
-
debugLevel: #{debugLevelString}"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|