ffwd-kairosdb 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ffwd/plugin/kairosdb/hook.rb +58 -0
- data/lib/ffwd/plugin/kairosdb/version.rb +1 -1
- data/lib/ffwd/plugin/kairosdb.rb +9 -16
- metadata +5 -5
- data/lib/ffwd/plugin/kairosdb/output.rb +0 -130
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c847b7694b20491e0e5cec03e920d9fd6ac66168
|
4
|
+
data.tar.gz: 1111fea050eb39e19862d215fec95e303ba822fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c8208441ea471b67df9561fea1d2ed88ef47e2fb7bdcd9e617539fe3d6bee0ee3c950e40cac68ba4e82f1edcc091d6a476c6395ec9e19161d681e6e6d717e3d
|
7
|
+
data.tar.gz: 27d981894adbc070241496b20ad4a81292d8ada16f70d30af967bc5e7bb54415957e91b486a267a59c2231842e61eba5ee172ff0ae699b19d2b4b27d9387a13c
|
@@ -0,0 +1,58 @@
|
|
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::KairosDB
|
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
|
31
|
+
@c = nil
|
32
|
+
@url = url
|
33
|
+
end
|
34
|
+
|
35
|
+
def active?
|
36
|
+
not @c.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
def connect
|
40
|
+
@c = EM::HttpRequest.new(@url)
|
41
|
+
end
|
42
|
+
|
43
|
+
def close
|
44
|
+
@c.close
|
45
|
+
@c = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def send metrics
|
49
|
+
metrics = Utils.make_metrics(metrics)
|
50
|
+
metrics = JSON.dump(metrics)
|
51
|
+
@c.post(:path => API_PATH, :head => HEADER, :body => metrics)
|
52
|
+
end
|
53
|
+
|
54
|
+
def reporter_meta
|
55
|
+
{:component => :datadog}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/ffwd/plugin/kairosdb.rb
CHANGED
@@ -19,8 +19,9 @@ require 'em-http'
|
|
19
19
|
require 'ffwd/logging'
|
20
20
|
require 'ffwd/plugin'
|
21
21
|
require 'ffwd/reporter'
|
22
|
+
require 'ffwd/flushing_output'
|
22
23
|
|
23
|
-
require_relative 'kairosdb/
|
24
|
+
require_relative 'kairosdb/hook'
|
24
25
|
|
25
26
|
module FFWD::Plugin::KairosDB
|
26
27
|
include FFWD::Plugin
|
@@ -32,21 +33,13 @@ module FFWD::Plugin::KairosDB
|
|
32
33
|
DEFAULT_FLUSH_INTERVAL = 10
|
33
34
|
DEFAULT_BUFFER_LIMIT = 100000
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
def connect core
|
42
|
-
url = @opts[:url] || DEFAULT_URL
|
43
|
-
flush_interval = @opts[:flush_interval] || DEFAULT_FLUSH_INTERVAL
|
44
|
-
buffer_limit = @opts[:buffer_limit] || DEFAULT_BUFFER_LIMIT
|
45
|
-
Output.new core, @log, url, flush_interval, buffer_limit
|
46
|
-
end
|
47
|
-
end
|
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
|
+
hook = Hook.new(config[:url])
|
48
42
|
|
49
|
-
|
50
|
-
Setup.new log, opts
|
43
|
+
FFWD.flushing_output log, hook, config
|
51
44
|
end
|
52
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffwd-kairosdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John-John Tedro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.3.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.3.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- lib/ffwd/plugin/kairosdb.rb
|
77
|
-
- lib/ffwd/plugin/kairosdb/
|
77
|
+
- lib/ffwd/plugin/kairosdb/hook.rb
|
78
78
|
- lib/ffwd/plugin/kairosdb/utils.rb
|
79
79
|
- lib/ffwd/plugin/kairosdb/version.rb
|
80
80
|
homepage: https://github.com/spotify/ffwd
|
@@ -1,130 +0,0 @@
|
|
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 'ffwd/reporter'
|
17
|
-
|
18
|
-
require_relative 'utils'
|
19
|
-
|
20
|
-
module FFWD::Plugin::KairosDB
|
21
|
-
class Output
|
22
|
-
include FFWD::Reporter
|
23
|
-
setup_reporter :keys => [:dropped_metrics, :sent_metrics, :failed_metrics]
|
24
|
-
|
25
|
-
attr_reader :log, :reporter_meta
|
26
|
-
|
27
|
-
HEADER = {
|
28
|
-
"Content-Type" => "application/json"
|
29
|
-
}
|
30
|
-
|
31
|
-
API_PATH = "/api/v1/datapoints"
|
32
|
-
|
33
|
-
def initialize core, log, url, flush_interval, buffer_limit
|
34
|
-
@log = log
|
35
|
-
@url = url
|
36
|
-
@flush_interval = flush_interval
|
37
|
-
@buffer_limit = buffer_limit
|
38
|
-
@reporter_meta = {:type => "kairosdb_out", :url => @url}
|
39
|
-
|
40
|
-
@buffer = []
|
41
|
-
@pending = nil
|
42
|
-
@c = nil
|
43
|
-
|
44
|
-
@sub = nil
|
45
|
-
|
46
|
-
core.starting do
|
47
|
-
log.info "Will send events to #{@url}"
|
48
|
-
|
49
|
-
@c = EM::HttpRequest.new(@url)
|
50
|
-
|
51
|
-
@sub = core.output.metric_subscribe do |metric|
|
52
|
-
if @buffer.size >= @buffer_limit
|
53
|
-
increment :dropped_metrics, 1
|
54
|
-
next
|
55
|
-
end
|
56
|
-
|
57
|
-
@buffer << metric
|
58
|
-
check_timer!
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
core.stopping do
|
63
|
-
# Close is buggy, don.
|
64
|
-
#@c.close
|
65
|
-
|
66
|
-
log.info "Closing connection to #{@url}"
|
67
|
-
|
68
|
-
if @sub
|
69
|
-
@sub.unsubscribe
|
70
|
-
@sub = nil
|
71
|
-
end
|
72
|
-
|
73
|
-
if @timer
|
74
|
-
@timer.cancel
|
75
|
-
@timer = nil
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def flush!
|
81
|
-
if @timer
|
82
|
-
@timer.cancel
|
83
|
-
@timer = nil
|
84
|
-
end
|
85
|
-
|
86
|
-
if @pending
|
87
|
-
log.info "Request already in progress, dropping metrics"
|
88
|
-
increment :dropped_metrics, @buffer.size
|
89
|
-
@buffer.clear
|
90
|
-
return
|
91
|
-
end
|
92
|
-
|
93
|
-
unless @c
|
94
|
-
log.error "Dropping metrics, no active connection available"
|
95
|
-
increment :dropped_metrics, @buffer.size
|
96
|
-
@buffer.clear
|
97
|
-
return
|
98
|
-
end
|
99
|
-
|
100
|
-
buffer_size = @buffer.size
|
101
|
-
metrics = Utils.make_metrics(@buffer)
|
102
|
-
metrics = JSON.dump(metrics)
|
103
|
-
@buffer.clear
|
104
|
-
|
105
|
-
log.info "Sending #{buffer_size} metric(s) to #{@url}"
|
106
|
-
@pending = @c.post(:path => API_PATH, :head => HEADER, :body => metrics)
|
107
|
-
|
108
|
-
@pending.callback do
|
109
|
-
increment :sent_metrics, buffer_size
|
110
|
-
@pending = nil
|
111
|
-
end
|
112
|
-
|
113
|
-
@pending.errback do
|
114
|
-
log.error "Failed to submit events: #{@pending.error}"
|
115
|
-
increment :failed_metrics, buffer_size
|
116
|
-
@pending = nil
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def check_timer!
|
121
|
-
return if @timer
|
122
|
-
|
123
|
-
log.debug "Setting timer to #{@flush_interval}s"
|
124
|
-
|
125
|
-
@timer = EM::Timer.new(@flush_interval) do
|
126
|
-
flush!
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|