forked from kcampos/sonar_data_publish
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatatarget.rb
More file actions
70 lines (57 loc) · 1.87 KB
/
datatarget.rb
File metadata and controls
70 lines (57 loc) · 1.87 KB
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
#!/usr/bin/env ruby
class Datatarget
attr_reader :client, :env_token, :options
def initialize(env_token, opts={})
@env_token = env_token
@options = {
:verbose => false,
:enabled => true,
:submit_time => Time.now.utc.strftime("%Y-%m-%d %H:%M:%S")
}.merge(opts)
init_client
end
def init_client
end
def verbose?
options[:verbose]
end
def enabled?
options[:enabled]
end
end
class DataboxTarget < Datatarget
def init_client
puts "env_token: #{ENV[env_token]}" if verbose?
Databox.configure do |c|
c.push_token = ENV[env_token]
end
@client = Databox::Client.new
end
def publish(project_key, metrics, opts={})
additional_attributes = opts[:attributes] || {}
attributes = { project: project_key }.merge(additional_attributes)
if enabled?
metrics.each_pair { |metric, value| puts "client.push(key: #{metric.to_s}, value: #{value}, date: #{options[:submit_time]}, attributes: #{attributes})" } if verbose?
metrics.each_pair { |metric, value| client.push(key: metric.to_s, value: value, date: options[:submit_time], attributes: attributes) }
end
end
end
class DatadogTarget < Datatarget
def init_client
@client = Dogapi::Client.new(ENV[env_token])
end
def publish(collection, project_key, metrics)
if enabled?
metrics.each_pair { |metric, value| puts "client.emit_point \"#{collection.to_s}.#{metric.to_s}\", #{value}, :tags => [\"project:#{project_key}\"]" } if verbose?
metrics.each_pair { |metric, value| client.emit_point "#{collection.to_s}.#{metric.to_s}", value, :tags => ["project:#{project_key}"] }
end
end
end
class KeenTarget < Datatarget
def publish(collection, data)
if enabled?
puts "keen_data: #{keen_data.inspect}\nkeen_data.class -> #{keen_data.class}" if verbose?
::Keen.publish_batch(collection => keen_data)
end
end
end