ffwd-datadog 0.3.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3ac8883cc23aee7e9afc72675e6906ef184052a9
4
+ data.tar.gz: 2d22a7dd23cf7938601d6122f2602091e6d2611d
5
+ SHA512:
6
+ metadata.gz: f35d75a9df67c1dfc1f374f5ac845407387678ef755caf476c900d2384770b74bad4be45259a5f99de9b2b92225855ce8832070dace91bac46aa0081c429abe4
7
+ data.tar.gz: 6e51afa47104fa67bd73b1acf259518d3db9d18655b92a1e4e8155928c979192944dfd6daf5d8793df1992d95e1405295e46163da3980172970753e13b4116e1
@@ -0,0 +1,49 @@
1
+ # $LICENSE
2
+ # Copyright 2013-2014 Spotify AB. All rights reserved.
3
+ #
4
+ # The contents of this file are licensed under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require 'eventmachine'
17
+ require 'em-http'
18
+
19
+ require 'ffwd/logging'
20
+ require 'ffwd/plugin'
21
+ require 'ffwd/reporter'
22
+ require 'ffwd/flushing_output'
23
+
24
+ require_relative 'datadog/hook'
25
+
26
+ module FFWD::Plugin::Datadog
27
+ include FFWD::Plugin
28
+ include FFWD::Logging
29
+
30
+ register_plugin "datadog"
31
+
32
+ DEFAULT_URL = "https://app.datadoghq.com"
33
+ DEFAULT_FLUSH_INTERVAL = 10
34
+ DEFAULT_BUFFER_LIMIT = 100000
35
+
36
+ def self.setup_output config
37
+ config[:url] ||= DEFAULT_URL
38
+ config[:flush_interval] ||= DEFAULT_FLUSH_INTERVAL
39
+ config[:buffer_limit] ||= DEFAULT_BUFFER_LIMIT
40
+
41
+ unless config[:datadog_key]
42
+ raise "datadog_key: must be specified"
43
+ end
44
+
45
+ hook = Hook.new(config[:url], config[:datadog_key])
46
+
47
+ FFWD.flushing_output log, hook, config
48
+ end
49
+ end
@@ -0,0 +1,63 @@
1
+ # $LICENSE
2
+ # Copyright 2013-2014 Spotify AB. All rights reserved.
3
+ #
4
+ # The contents of this file are licensed under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require 'json'
17
+
18
+ require_relative 'utils'
19
+
20
+ require 'ffwd/flushing_output_hook'
21
+
22
+ module FFWD::Plugin::Datadog
23
+ class Hook < FFWD::FlushingOutputHook
24
+ HEADER = {
25
+ "Content-Type" => "application/json"
26
+ }
27
+
28
+ API_PATH = "/api/v1/series"
29
+
30
+ def initialize url, datadog_key
31
+ @c = nil
32
+ @url = url
33
+ @datadog_key = datadog_key
34
+ end
35
+
36
+ def active?
37
+ not @c.nil?
38
+ end
39
+
40
+ def connect
41
+ @c = EM::HttpRequest.new(@url)
42
+ end
43
+
44
+ def close
45
+ @c.close
46
+ @c = nil
47
+ end
48
+
49
+ def send metrics
50
+ metrics = Utils.make_metrics(metrics)
51
+ metrics = JSON.dump(metrics)
52
+
53
+ @c.post(:path => API_PATH,
54
+ :query => {'api_key' => @datadog_key },
55
+ :head => HEADER,
56
+ :body => metrics)
57
+ end
58
+
59
+ def reporter_meta
60
+ {:component => :datadog}
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,62 @@
1
+ # $LICENSE
2
+ # Copyright 2013-2014 Spotify AB. All rights reserved.
3
+ #
4
+ # The contents of this file are licensed under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ module FFWD::Plugin::Datadog
17
+ module Utils
18
+ # groups similar metadata and escapes them using the suite of safe_*
19
+ # functions available.
20
+ #
21
+ # Should prevent unecessary invocations of safe_entry by only adding new
22
+ # groups of the source metric differs (||=).
23
+ def self.make_metrics buffer
24
+ groups = {}
25
+
26
+ buffer.each do |m|
27
+ entry = {:host => m.host, :name => m.key, :attributes => m.attributes}
28
+ group = (groups[entry] ||= safe_entry(entry).merge(:points => []))
29
+ group[:points] << [m.time.to_i, m.value]
30
+ end
31
+
32
+ return {:series => groups.values}
33
+ end
34
+
35
+ # make safe entry out of available information.
36
+ def self.safe_entry entry
37
+ host = entry[:host]
38
+ metric = entry[:name]
39
+ tags = entry[:attributes]
40
+ {:host => host, :metric => safe_string(metric), :tags => safe_tags(tags)}
41
+ end
42
+
43
+ def self.safe_string string
44
+ string = string.to_s
45
+ string = string.gsub " ", "_"
46
+ string.gsub ":", "_"
47
+ end
48
+
49
+ def self.safe_tags tags
50
+ safe = []
51
+
52
+ tags.each do |key, value|
53
+ safe_key = safe_string(key)
54
+ safe_value = safe_string(value)
55
+ safe << "#{safe_key}:#{safe_value}"
56
+ end
57
+
58
+ return safe
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,22 @@
1
+ # $LICENSE
2
+ # Copyright 2013-2014 Spotify AB. All rights reserved.
3
+ #
4
+ # The contents of this file are licensed under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ module FFWD
17
+ module Plugin
18
+ module Datadog
19
+ VERSION = "0.3.0"
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffwd-datadog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Rohan Singh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: em-http-request
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ffwd
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-mocks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - rohan@spotify.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/ffwd/plugin/datadog.rb
77
+ - lib/ffwd/plugin/datadog/hook.rb
78
+ - lib/ffwd/plugin/datadog/utils.rb
79
+ - lib/ffwd/plugin/datadog/version.rb
80
+ homepage: https://github.com/spotify/ffwd
81
+ licenses:
82
+ - Apache 2.0
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.0.14
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Datadog support for FFWD.
104
+ test_files: []