mn_utils_gem 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mn_utils_gem/site_action.rb +36 -35
- data/lib/mn_utils_gem/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70ae8ad27e749906b14ea11635f92fb244ced2c217b1822324451a825d765545
|
4
|
+
data.tar.gz: 5154105cc37031f73afe04ecb954c244f524c79279c2e29ddf60c1fd23e68cd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b93c8badd0cb3c373be3418645654a43a641a2d6af90d550b8edca06ab65538b355c2f610f983e648edad43f6f41430c9a91589b7293d75d2d172892b92f54d
|
7
|
+
data.tar.gz: 593601ff2eccbf62105eb83418bdc1628987213e5b89484ef840a64895cd7a4b458044a1ff40906846a349bcdc6e542810f71ebc8f8df52f8cfd73b39a9c98f3
|
@@ -53,7 +53,7 @@ module MnUtils
|
|
53
53
|
|
54
54
|
# this creates a reverse map of all site actions and their corresponding group
|
55
55
|
# for quick lookups by the code
|
56
|
-
@_site_action_group_map = Hash[*(@_site_actions_and_groups.map {|k,v| v.map {|x| [x, k]}}.flatten)].freeze
|
56
|
+
@_site_action_group_map = Hash[*(@_site_actions_and_groups.map {|k, v| v.map {|x| [x, k]}}.flatten)].freeze
|
57
57
|
end
|
58
58
|
|
59
59
|
def log(message, site_action, payload = {})
|
@@ -103,42 +103,43 @@ module MnUtils
|
|
103
103
|
send_to_graylog full_payload
|
104
104
|
send_to_cloudwatch full_payload
|
105
105
|
end
|
106
|
-
end
|
107
106
|
|
108
|
-
|
107
|
+
private
|
109
108
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
109
|
+
def send_to_graylog(payload)
|
110
|
+
if ENV.key?('GRAYLOG_GELF_UDP_HOST') && ENV.key?('GRAYLOG_GELF_UDP_PORT')
|
111
|
+
n = GELF::Notifier.new(ENV['GRAYLOG_GELF_UDP_HOST'], ENV['GRAYLOG_GELF_UDP_PORT'])
|
112
|
+
n.notify! payload
|
113
|
+
else
|
114
|
+
Rails.logger.debug("Payload for Graylog: #{payload}")
|
115
|
+
end
|
116
|
+
rescue Exception => e
|
117
|
+
Rails.logger.error e
|
116
118
|
end
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
Rails.logger.
|
119
|
+
|
120
|
+
def send_to_cloudwatch(payload)
|
121
|
+
metric_name = payload[:_site_action]
|
122
|
+
metric_data = [{
|
123
|
+
metric_name: metric_name,
|
124
|
+
value: 1,
|
125
|
+
unit: "Count"
|
126
|
+
}]
|
127
|
+
if ENV.key? 'CLOUDWATCH_ROOT_NAMESPACE'
|
128
|
+
root_namespace = ENV['CLOUDWATCH_ROOT_NAMESPACE']
|
129
|
+
second_namespace = payload[:_site_action_group]
|
130
|
+
namespace = "#{root_namespace}/#{second_namespace}"
|
131
|
+
cw = Aws::CloudWatch::Client.new
|
132
|
+
cw.put_metric_data({
|
133
|
+
namespace: namespace,
|
134
|
+
metric_data: metric_data
|
135
|
+
})
|
136
|
+
else
|
137
|
+
Rails.logger.debug("Payload for Cloudwatch: #{metric_data}")
|
138
|
+
end
|
139
|
+
rescue Exception => e
|
140
|
+
Rails.logger.error e
|
139
141
|
end
|
140
|
-
rescue Exception => e
|
141
|
-
Rails.logger.error e
|
142
|
-
end
|
143
142
|
|
144
|
-
end
|
143
|
+
end # of class SiteAction
|
144
|
+
|
145
|
+
end # of module MnUtils
|
data/lib/mn_utils_gem/version.rb
CHANGED