appmonitor 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/appmonitor/event_notifier.rb +120 -0
- data/lib/appmonitor/rake.rb +10 -0
- data/lib/appmonitor/rake_patch.rb +33 -0
- data/lib/appmonitor.rb +3 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fb9475dc2e370f599c06c6289db239812e94656b
|
4
|
+
data.tar.gz: 07f3188c7274c48d82761318390a474ba3dcb053
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7695bc7a5262dda6aeca0da08ef17f7c62b45cfe3884f6e9835700be3c04128fd67ad1e9c31389ed838b2c432ded6b7a36d030d63dbc53ca237ce811568a97e5
|
7
|
+
data.tar.gz: 9d1dc4ddcb409e0e7df3ded382884bf2b2025f7943fa43080db54c589bd00da483dd7e4bd80f825d8ab06ef64d32af6da39a190e105bddab30f8b67765d2dfae
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require "active_support/core_ext"
|
4
|
+
require 'action_dispatch'
|
5
|
+
|
6
|
+
module AppMonitor
|
7
|
+
class EventNotifier
|
8
|
+
|
9
|
+
def initialize(app)
|
10
|
+
@app = app
|
11
|
+
configure
|
12
|
+
@config[:ignore_exceptions] ||= self.class.default_ignore_exceptions
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure(opts = {} )
|
16
|
+
@config = {
|
17
|
+
api_key: '',
|
18
|
+
uri: '',
|
19
|
+
project_id: '',
|
20
|
+
monitoring: {development: '', staging: '', production: ''}
|
21
|
+
}
|
22
|
+
@valid_config_keys = @config.keys
|
23
|
+
path_to_yaml_file = "#{Rails.root}/config/appmonitor.yml"
|
24
|
+
begin
|
25
|
+
config = YAML::load(IO.read(path_to_yaml_file))
|
26
|
+
Rails.logger.info(config)
|
27
|
+
rescue Errno::ENOENT
|
28
|
+
return
|
29
|
+
rescue Psych::SyntaxError
|
30
|
+
return
|
31
|
+
end
|
32
|
+
config.each { |k, v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym }
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def self.default_ignore_exceptions
|
37
|
+
[].tap do |exceptions|
|
38
|
+
exceptions << 'ActionController::RoutingError'
|
39
|
+
exceptions << 'ActionController::InvalidAuthenticityToken'
|
40
|
+
exceptions << 'CGI::Session::CookieStore::TamperedWithCookie'
|
41
|
+
exceptions << 'ActionController::UnknownAction'
|
42
|
+
exceptions << 'ActionController::UnknownHttpMethod'
|
43
|
+
exceptions << 'Mongoid::Errors::DocumentNotFound'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def ignored_exception(ignore_array, exception)
|
48
|
+
Array.wrap(ignore_array).map(&:to_s).include?(exception.class.name)
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def build_exception_hash(exception, request)
|
53
|
+
params = request.params
|
54
|
+
{:klass => params[:controller], :method => params[:action], :message => exception.message.inspect,
|
55
|
+
:session => request.session.to_hash, :stack_trace => exception.backtrace.join("\n"),
|
56
|
+
:params => request.filtered_parameters,
|
57
|
+
:url => request.original_url, :ip_address => request.remote_ip, :timestamp => Time.now.to_i,
|
58
|
+
:environment => Rails.env}
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_rake_event(exception,options)
|
62
|
+
{timestamp: Time.now.to_i, message: exception.message.inspect, stack_trace: exception.backtrace.join("\n"),
|
63
|
+
klass: options[:rake_command_line], environment: Rails.env || ''}
|
64
|
+
end
|
65
|
+
|
66
|
+
def call(env)
|
67
|
+
@app.call(env)
|
68
|
+
rescue Exception => exception
|
69
|
+
puts @config
|
70
|
+
if @config[:monitoring]["#{Rails.env.to_s.downcase}"]
|
71
|
+
@request = ActionDispatch::Request.new(env)
|
72
|
+
send_exception(exception)
|
73
|
+
end
|
74
|
+
raise exception
|
75
|
+
end
|
76
|
+
|
77
|
+
def send_exception(exception)
|
78
|
+
unless ignored_exception(@config[:ignore_exceptions], exception)
|
79
|
+
event = build_exception_hash(exception, @request)
|
80
|
+
@event = event.to_json
|
81
|
+
notify_on_event("Error")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def send_rake_event(exception, options = {})
|
86
|
+
configure
|
87
|
+
unless ignored_exception(@config[:ignore_exceptions], exception)
|
88
|
+
event = build_rake_event(exception, options)
|
89
|
+
@event = event.to_json
|
90
|
+
notify_on_event("RakeError")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def notify_on_event(type)
|
95
|
+
uri = URI.parse(@config[:uri])
|
96
|
+
|
97
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
98
|
+
https.use_ssl = false
|
99
|
+
request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' => "application/json",
|
100
|
+
'appm_apiKey' => @config[:api_key],
|
101
|
+
'appm_projectId' => @config[:project_id],
|
102
|
+
'appm_type' => type}
|
103
|
+
)
|
104
|
+
|
105
|
+
request.body = "#@event"
|
106
|
+
response = https.request(request)
|
107
|
+
|
108
|
+
Rails.logger.info ("Appmonitor: Event has been sent")
|
109
|
+
puts 'Appmonitor: Event has been sent'
|
110
|
+
|
111
|
+
unless response.kind_of? Net::HTTPSuccess
|
112
|
+
Rails.logger.info('Appmonitor WARNING: Something went wrong, please check your config')
|
113
|
+
Rails.logger.info("AppMonitor WARNING: Response #{response.inspect}")
|
114
|
+
puts 'Appmonitor WARNING: Something went wrong, please check your config'
|
115
|
+
puts "AppMonitor WARNING: Response #{response.inspect}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Monkey patching patterns lifted from
|
2
|
+
# https://github.com/thoughtbot/airbrake/blob/master/lib/airbrake/rake_handler.rb
|
3
|
+
|
4
|
+
module AppMonitor
|
5
|
+
module RakePatch
|
6
|
+
def self.included(klass)
|
7
|
+
klass.class_eval do
|
8
|
+
alias_method :display_error_message_without_notifications, :display_error_message
|
9
|
+
alias_method :display_error_message, :display_error_message_with_notifications
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def display_error_message_with_notifications(ex)
|
14
|
+
display_error_message_without_notifications(ex)
|
15
|
+
en = AppMonitor::EventNotifier.new(nil)
|
16
|
+
en.send_rake_event(ex,:rake_command_line => reconstruct_command_line)
|
17
|
+
end
|
18
|
+
|
19
|
+
def reconstruct_command_line
|
20
|
+
"rake #{ARGV.join(' ')}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Only do this if we're actually in a Rake context. In some contexts (e.g.,
|
26
|
+
# in the Rails console) Rake might not be defined.
|
27
|
+
if Object.const_defined? :Rake
|
28
|
+
Rake.application.instance_eval do
|
29
|
+
class << self
|
30
|
+
include AppMonitor::RakePatch
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/appmonitor.rb
ADDED
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: appmonitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Team Gappers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2010-10-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: AppMonitor agent for ruby language
|
14
|
+
email: gappers-tip-fiit@googlegroups.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/appmonitor.rb
|
20
|
+
- lib/appmonitor/event_notifier.rb
|
21
|
+
- lib/appmonitor/rake.rb
|
22
|
+
- lib/appmonitor/rake_patch.rb
|
23
|
+
homepage: http://rubygems.org/gems/appmonitor
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.2.2
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: AppMonitor agent for ruby language
|
47
|
+
test_files: []
|