observed 0.1.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 +15 -0
- data/.gitignore +20 -0
- data/.travis.yml +11 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +204 -0
- data/Rakefile +4 -0
- data/examples/00readme/Gemfile +5 -0
- data/examples/00readme/clockwork.rb +16 -0
- data/examples/00readme/observed.rb +17 -0
- data/examples/observed.rb +10 -0
- data/exe/observed-oneshot +11 -0
- data/features/oneshot.feature +24 -0
- data/features/support/env.rb +8 -0
- data/features/test_in_single_ruby_source.feature +32 -0
- data/integrations/observed-clockwork/.gitignore +17 -0
- data/integrations/observed-clockwork/Gemfile +4 -0
- data/integrations/observed-clockwork/LICENSE.txt +22 -0
- data/integrations/observed-clockwork/README.md +53 -0
- data/integrations/observed-clockwork/Rakefile +1 -0
- data/integrations/observed-clockwork/bin/clockwork +16 -0
- data/integrations/observed-clockwork/bin/clockworkd +16 -0
- data/integrations/observed-clockwork/bin/observed-clockwork +16 -0
- data/integrations/observed-clockwork/bin/rake +16 -0
- data/integrations/observed-clockwork/examples/clockwork/clockwork.rb +9 -0
- data/integrations/observed-clockwork/examples/clockwork/foo_plugin.rb +19 -0
- data/integrations/observed-clockwork/examples/clockwork/observed.conf +6 -0
- data/integrations/observed-clockwork/features/run_observed_inside_clockwork.feature +59 -0
- data/integrations/observed-clockwork/features/support/env.rb +8 -0
- data/integrations/observed-clockwork/lib/observed/clockwork/version.rb +5 -0
- data/integrations/observed-clockwork/lib/observed/clockwork.rb +20 -0
- data/integrations/observed-clockwork/observed-clockwork.gemspec +29 -0
- data/lib/observed/application/oneshot.rb +114 -0
- data/lib/observed/application.rb +1 -0
- data/lib/observed/builtin_plugins/file.rb +49 -0
- data/lib/observed/builtin_plugins/stdout.rb +35 -0
- data/lib/observed/builtin_plugins.rb +2 -0
- data/lib/observed/config.rb +27 -0
- data/lib/observed/config_builder.rb +167 -0
- data/lib/observed/config_dsl.rb +77 -0
- data/lib/observed/configurable.rb +56 -0
- data/lib/observed/default/observer.rb +16 -0
- data/lib/observed/default/reporter.rb +17 -0
- data/lib/observed/default.rb +2 -0
- data/lib/observed/hash/builder.rb +24 -0
- data/lib/observed/hash/fetcher.rb +19 -0
- data/lib/observed/hash/key_path_encoding.rb +62 -0
- data/lib/observed/hash.rb +3 -0
- data/lib/observed/observer.rb +18 -0
- data/lib/observed/observer_helpers/timer.rb +37 -0
- data/lib/observed/pluggable.rb +34 -0
- data/lib/observed/reader.rb +14 -0
- data/lib/observed/reporter/regexp_matching.rb +11 -0
- data/lib/observed/reporter.rb +25 -0
- data/lib/observed/system.rb +109 -0
- data/lib/observed/version.rb +3 -0
- data/lib/observed/writer.rb +14 -0
- data/lib/observed.rb +77 -0
- data/observed.gemspec +30 -0
- data/plugins/observed-fluentd/.gitignore +20 -0
- data/plugins/observed-fluentd/Gemfile +12 -0
- data/plugins/observed-fluentd/LICENSE.txt +22 -0
- data/plugins/observed-fluentd/README.md +99 -0
- data/plugins/observed-fluentd/Rakefile +1 -0
- data/plugins/observed-fluentd/features/plugin.feature +61 -0
- data/plugins/observed-fluentd/features/support/env.rb +32 -0
- data/plugins/observed-fluentd/fluent.d/fluent.conf +93 -0
- data/plugins/observed-fluentd/fluentd.pid +1 -0
- data/plugins/observed-fluentd/lib/observed/fluentd/version.rb +5 -0
- data/plugins/observed-fluentd/lib/observed/fluentd.rb +30 -0
- data/plugins/observed-fluentd/observe.d/clockwork.rb +9 -0
- data/plugins/observed-fluentd/observe.d/observed.conf +17 -0
- data/plugins/observed-fluentd/observed-fluentd.gemspec +26 -0
- data/plugins/observed-gauge/.gitignore +18 -0
- data/plugins/observed-gauge/Gemfile +4 -0
- data/plugins/observed-gauge/LICENSE.txt +22 -0
- data/plugins/observed-gauge/README.md +29 -0
- data/plugins/observed-gauge/Rakefile +1 -0
- data/plugins/observed-gauge/lib/observed/gauge/version.rb +5 -0
- data/plugins/observed-gauge/lib/observed/gauge.rb +117 -0
- data/plugins/observed-gauge/observed-gauge.gemspec +30 -0
- data/plugins/observed-gauge/spec/gauge_spec.rb +195 -0
- data/plugins/observed-gauge/spec/spec_helper.rb +25 -0
- data/plugins/observed-http/.gitignore +17 -0
- data/plugins/observed-http/Gemfile +4 -0
- data/plugins/observed-http/LICENSE.txt +22 -0
- data/plugins/observed-http/README.md +37 -0
- data/plugins/observed-http/Rakefile +1 -0
- data/plugins/observed-http/features/observe_web_services_via_http.feature +32 -0
- data/plugins/observed-http/features/support/env.rb +8 -0
- data/plugins/observed-http/lib/observed/http/version.rb +5 -0
- data/plugins/observed-http/lib/observed/http.rb +60 -0
- data/plugins/observed-http/observed-http.gemspec +31 -0
- data/plugins/observed-http/spec/fixtures/observed.conf +10 -0
- data/plugins/observed-http/spec/http_spec.rb +14 -0
- data/plugins/observed-http/spec/spec_helper.rb +25 -0
- data/spec/builtin_plugins/file_spec.rb +145 -0
- data/spec/builtin_plugins/stdout_spec.rb +56 -0
- data/spec/config_builder_spec.rb +146 -0
- data/spec/config_dsl_spec.rb +50 -0
- data/spec/configurable_spec.rb +65 -0
- data/spec/fixtures/configure_by_conf/foo_plugin.rb +12 -0
- data/spec/fixtures/configure_by_conf/observed.conf +6 -0
- data/spec/fixtures/configure_by_conf_dot_d/foo_plugin.rb +18 -0
- data/spec/fixtures/configure_by_conf_dot_d/observed.conf.d/check_foo_1.rb +1 -0
- data/spec/fixtures/configure_by_conf_dot_d/observed.conf.d/plugins.rb +1 -0
- data/spec/fixtures/configure_by_require/observed_conf.rb +6 -0
- data/spec/hash/builder_spec.rb +36 -0
- data/spec/hash/fetcher_spec.rb +29 -0
- data/spec/input_helpers/timer_spec.rb +54 -0
- data/spec/observed_spec.rb +79 -0
- data/spec/observer_spec.rb +123 -0
- data/spec/oneshot_spec.rb +58 -0
- data/spec/reader_spec.rb +15 -0
- data/spec/reporter_spec.rb +19 -0
- data/spec/spec_helper.rb +65 -0
- data/spec/system_spec.rb +75 -0
- data/spec/writer_spec.rb +16 -0
- metadata +299 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Feature: Receives Observed's input and send it to Fluentd
|
|
2
|
+
|
|
3
|
+
In order to pass data from Observed to Fluentd
|
|
4
|
+
|
|
5
|
+
I want to configure Observed to use observed-fluentd plugin
|
|
6
|
+
|
|
7
|
+
Scenario: Write configuration files for Observed and Fluentd, then run Fluentd, and then run Observed
|
|
8
|
+
Given a file named "test.rb" with:
|
|
9
|
+
"""
|
|
10
|
+
require 'observed'
|
|
11
|
+
require 'observed/http'
|
|
12
|
+
require 'observed/fluentd'
|
|
13
|
+
|
|
14
|
+
include Observed
|
|
15
|
+
|
|
16
|
+
observe 'myservice', via: 'http', with: {
|
|
17
|
+
method: 'get',
|
|
18
|
+
url: 'http://google.com/',
|
|
19
|
+
timeout_in_milliseconds: 3000,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
report /myservice.*/, via: 'fluentd', with: {
|
|
23
|
+
host: 'localhost',
|
|
24
|
+
port: 24224,
|
|
25
|
+
tag: 'debug.myservice'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
run 'myservice'
|
|
29
|
+
"""
|
|
30
|
+
Given a file named "fluent.conf" with:
|
|
31
|
+
"""
|
|
32
|
+
<source>
|
|
33
|
+
type forward
|
|
34
|
+
</source>
|
|
35
|
+
|
|
36
|
+
<match debug.**>
|
|
37
|
+
type file
|
|
38
|
+
path fluent.out
|
|
39
|
+
time_slice_format foo
|
|
40
|
+
utc
|
|
41
|
+
flush_interval 1s
|
|
42
|
+
</match>
|
|
43
|
+
"""
|
|
44
|
+
When I run `pwd`
|
|
45
|
+
When I run `fluentd -d pid_file -c fluent.conf`
|
|
46
|
+
# When I start my daemon with "fluentd -c tmp/aruba/fluent.conf"
|
|
47
|
+
When I run `sleep 3`
|
|
48
|
+
When I run `ruby test.rb`
|
|
49
|
+
#Then a daemon called "fluentd" should be running
|
|
50
|
+
When I run `sleep 3`
|
|
51
|
+
When I run the command "kill $(cat tmp/aruba/pid_file)"
|
|
52
|
+
When I run `cat fluent.out.foo_0.log`
|
|
53
|
+
Then the output should contain:
|
|
54
|
+
"""
|
|
55
|
+
elapsed_time
|
|
56
|
+
"""
|
|
57
|
+
Then the output should contain:
|
|
58
|
+
"""
|
|
59
|
+
debug.myservice
|
|
60
|
+
"""
|
|
61
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
|
|
2
|
+
require 'aruba/cucumber'
|
|
3
|
+
|
|
4
|
+
World(Aruba::Api)
|
|
5
|
+
|
|
6
|
+
Before do
|
|
7
|
+
@aruba_timeout_seconds = 120
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
When /^I run the command "([^"]+)"$/ do |cmd|
|
|
11
|
+
system cmd
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
When /^I start my daemon with "([^"]*)"$/ do |cmd|
|
|
15
|
+
@root = Pathname.new(File.dirname(__FILE__)).parent.parent.expand_path
|
|
16
|
+
command = "#{@root.join('bin')}/#{cmd}"
|
|
17
|
+
|
|
18
|
+
puts "In the working directory: #{Dir.pwd}"
|
|
19
|
+
puts "Running #{command}"
|
|
20
|
+
|
|
21
|
+
@pipe = IO.popen(command, "r")
|
|
22
|
+
sleep 2 # so the daemon has a chance to boot
|
|
23
|
+
|
|
24
|
+
# clean up the daemon when the tests finish
|
|
25
|
+
at_exit do
|
|
26
|
+
Process.kill("KILL", @pipe.pid)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Then /^a daemon called "([^"]*)" should be running$/ do |daemon|
|
|
31
|
+
`ps -eo command |grep #{daemon}`.size.should > 0
|
|
32
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
|
|
2
|
+
## built-in TCP input
|
|
3
|
+
## $ echo <json> | fluent-cat <tag>
|
|
4
|
+
<source>
|
|
5
|
+
type forward
|
|
6
|
+
</source>
|
|
7
|
+
|
|
8
|
+
## built-in UNIX socket input
|
|
9
|
+
#<source>
|
|
10
|
+
# type unix
|
|
11
|
+
#</source>
|
|
12
|
+
|
|
13
|
+
# HTTP input
|
|
14
|
+
# http://localhost:8888/<tag>?json=<json>
|
|
15
|
+
<source>
|
|
16
|
+
type http
|
|
17
|
+
port 8888
|
|
18
|
+
</source>
|
|
19
|
+
|
|
20
|
+
## File input
|
|
21
|
+
## read apache logs with tag=apache.access
|
|
22
|
+
#<source>
|
|
23
|
+
# type tail
|
|
24
|
+
# format apache
|
|
25
|
+
# path /var/log/httpd-access.log
|
|
26
|
+
# tag apache.access
|
|
27
|
+
#</source>
|
|
28
|
+
|
|
29
|
+
# Listen HTTP for monitoring
|
|
30
|
+
# http://localhost:24220/api/plugins
|
|
31
|
+
# http://localhost:24220/api/plugins?type=TYPE
|
|
32
|
+
# http://localhost:24220/api/plugins?tag=MYTAG
|
|
33
|
+
<source>
|
|
34
|
+
type monitor_agent
|
|
35
|
+
port 24220
|
|
36
|
+
</source>
|
|
37
|
+
|
|
38
|
+
# Listen DRb for debug
|
|
39
|
+
<source>
|
|
40
|
+
type debug_agent
|
|
41
|
+
port 24230
|
|
42
|
+
</source>
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## match tag=apache.access and write to file
|
|
46
|
+
#<match apache.access>
|
|
47
|
+
# type file
|
|
48
|
+
# path /var/log/fluent/access
|
|
49
|
+
#</match>
|
|
50
|
+
|
|
51
|
+
## match tag=debug.** and dump to console
|
|
52
|
+
<match debug.**>
|
|
53
|
+
type stdout
|
|
54
|
+
</match>
|
|
55
|
+
|
|
56
|
+
# match tag=system.** and forward to another fluent server
|
|
57
|
+
<match system.**>
|
|
58
|
+
type forward
|
|
59
|
+
host 192.168.0.11
|
|
60
|
+
<secondary>
|
|
61
|
+
host 192.168.0.12
|
|
62
|
+
</secondary>
|
|
63
|
+
</match>
|
|
64
|
+
|
|
65
|
+
## match tag=myapp.** and forward and write to file
|
|
66
|
+
#<match myapp.**>
|
|
67
|
+
# type copy
|
|
68
|
+
# <store>
|
|
69
|
+
# type forward
|
|
70
|
+
# host 192.168.0.13
|
|
71
|
+
# buffer_type file
|
|
72
|
+
# buffer_path /var/log/fluent/myapp-forward
|
|
73
|
+
# retry_limit 50
|
|
74
|
+
# flush_interval 10s
|
|
75
|
+
# </store>
|
|
76
|
+
# <store>
|
|
77
|
+
# type file
|
|
78
|
+
# path /var/log/fluent/myapp
|
|
79
|
+
# </store>
|
|
80
|
+
#</match>
|
|
81
|
+
|
|
82
|
+
## match fluent's internal events
|
|
83
|
+
#<match fluent.**>
|
|
84
|
+
# type null
|
|
85
|
+
#</match>
|
|
86
|
+
|
|
87
|
+
## match not matched logs and write to file
|
|
88
|
+
#<match **>
|
|
89
|
+
# type file
|
|
90
|
+
# path /var/log/fluent/else
|
|
91
|
+
# compress gz
|
|
92
|
+
#</match>
|
|
93
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3921
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'observed/fluentd/version'
|
|
2
|
+
require 'observed/reporter'
|
|
3
|
+
require 'observed/reporter/regexp_matching'
|
|
4
|
+
require 'fluent-logger'
|
|
5
|
+
|
|
6
|
+
module Observed
|
|
7
|
+
module Plugins
|
|
8
|
+
class Fluentd < Observed::Reporter
|
|
9
|
+
|
|
10
|
+
include Observed::Reporter::RegexpMatching
|
|
11
|
+
|
|
12
|
+
plugin_name 'fluentd'
|
|
13
|
+
|
|
14
|
+
attribute :tag
|
|
15
|
+
attribute :host
|
|
16
|
+
attribute :port, default: 24224
|
|
17
|
+
attribute :transform, default: ->(data){ data }
|
|
18
|
+
|
|
19
|
+
def report(tag, time, data)
|
|
20
|
+
fluent_logger.post(self.tag, transform.call(data))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def fluent_logger
|
|
26
|
+
@fluent_logger ||= Fluent::Logger::FluentLogger.new(nil, host: host, port: port)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'observed/builtin_plugins'
|
|
2
|
+
require 'observed/http'
|
|
3
|
+
require 'observed/fluentd'
|
|
4
|
+
|
|
5
|
+
observe 'myservice', {
|
|
6
|
+
plugin: 'http',
|
|
7
|
+
method: 'get',
|
|
8
|
+
url: 'http://localhost/',
|
|
9
|
+
timeout_in_milliseconds: 3000,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
match /myservice.*/, {
|
|
13
|
+
plugin: 'fluentd',
|
|
14
|
+
host: 'localhost',
|
|
15
|
+
port: 24224,
|
|
16
|
+
tag: 'debug.myservice'
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'observed/fluentd/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'observed-fluentd'
|
|
8
|
+
spec.version = Observed::Fluentd::VERSION
|
|
9
|
+
spec.authors = ['KUOKA Yusuke']
|
|
10
|
+
spec.email = %w(yusuke.kuoka@gree.net)
|
|
11
|
+
spec.description = %q{Observed Fluentd Output Plugin}
|
|
12
|
+
spec.summary = %q{observed-fluentd is an Observed output plugin for sending observed data to Fluentd}
|
|
13
|
+
spec.homepage = ''
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = %w(lib)
|
|
20
|
+
|
|
21
|
+
spec.add_dependency 'fluent-logger', '~> 0.4.6'
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
|
24
|
+
spec.add_development_dependency 'rake'
|
|
25
|
+
spec.add_development_dependency 'rspec'
|
|
26
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 GREE, Inc.
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Observed::Gauge
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'observed-gauge'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install observed-gauge
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
1. Fork it
|
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
+
5. Create new Pull Request
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
require 'observed/reporter'
|
|
2
|
+
require 'observed/reporter/regexp_matching'
|
|
3
|
+
require 'observed/gauge/version'
|
|
4
|
+
require 'logger'
|
|
5
|
+
require 'rrd'
|
|
6
|
+
|
|
7
|
+
module Observed
|
|
8
|
+
module Plugins
|
|
9
|
+
class Gauge < Observed::Reporter
|
|
10
|
+
|
|
11
|
+
plugin_name 'gauge'
|
|
12
|
+
|
|
13
|
+
include Observed::Reporter::RegexpMatching
|
|
14
|
+
|
|
15
|
+
attribute :tag
|
|
16
|
+
attribute :key_path
|
|
17
|
+
attribute :coerce, default: ->(data){ data }
|
|
18
|
+
attribute :rrd
|
|
19
|
+
attribute :step
|
|
20
|
+
attribute :period
|
|
21
|
+
|
|
22
|
+
def report(tag, time, data)
|
|
23
|
+
rewrote = update_value_for_key_path(data, key_path) do |v|
|
|
24
|
+
sample = coerce.call(v)
|
|
25
|
+
average = get_cdp_updated_with(time, sample)
|
|
26
|
+
average
|
|
27
|
+
end
|
|
28
|
+
unless fetch_value_for_key_path(rewrote, key_path).nan?
|
|
29
|
+
system.report(self.tag, rewrote)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def prepare_rrd(args)
|
|
34
|
+
start = args[:start]
|
|
35
|
+
logger.debug "Creating a rrd file named '#{args[:rrd]}' with options {:start => #{start}}"
|
|
36
|
+
result = RRD::Builder.new(args[:rrd], start: start, step: step.seconds).tap do |builder|
|
|
37
|
+
builder.datasource data_source, :type => :gauge, :heartbeat => period.seconds, :min => 0, :max => :unlimited
|
|
38
|
+
builder.archive :average, :every => period.seconds, :during => period.seconds
|
|
39
|
+
builder.save
|
|
40
|
+
end
|
|
41
|
+
logger.debug "Builder#save returned: #{result.inspect}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def update_value_for_key_path(data, key_path, &block)
|
|
47
|
+
first, *rest = split_key_path(key_path)
|
|
48
|
+
data = data.dup
|
|
49
|
+
dug_data = data[first] || data[first.intern]
|
|
50
|
+
|
|
51
|
+
if rest.empty?
|
|
52
|
+
hash_update(data, first, block.call(dug_data))
|
|
53
|
+
else
|
|
54
|
+
hash_update(data, first, update_value_for_key_path(dug_data, rest, &block))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
data
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def hash_update(hash, key, value)
|
|
61
|
+
if hash[key]
|
|
62
|
+
hash[key] = value
|
|
63
|
+
else
|
|
64
|
+
hash[key.intern] = value
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def fetch_value_for_key_path(data, key_path)
|
|
69
|
+
first, *rest = split_key_path(key_path)
|
|
70
|
+
dug_data = data[first] || data[first.intern]
|
|
71
|
+
if rest.empty?
|
|
72
|
+
dug_data
|
|
73
|
+
else
|
|
74
|
+
fetch_value_for_key_path(dug_data, rest)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def split_key_path(key_path)
|
|
79
|
+
case key_path
|
|
80
|
+
when Array
|
|
81
|
+
key_path
|
|
82
|
+
when String
|
|
83
|
+
key_path.split('.')
|
|
84
|
+
else
|
|
85
|
+
fail "Unexpected type of key_path met. Expected an Array or a String, but it was a(n) #{key_path.class}"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def data_source
|
|
90
|
+
self.key_path.gsub('.', '_')
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# @param [Time] time
|
|
94
|
+
def get_cdp_updated_with(time, value)
|
|
95
|
+
rrd_path = self.rrd
|
|
96
|
+
t = time.to_i
|
|
97
|
+
|
|
98
|
+
rrd = RRD::Base.new(rrd_path)
|
|
99
|
+
|
|
100
|
+
unless File.exist? rrd_path
|
|
101
|
+
prepare_rrd(rrd: rrd_path, start: t)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
logger.debug "Updating the data source '#{data_source}' with the value #{value} with timestamp #{t}"
|
|
105
|
+
rrd.update t, value
|
|
106
|
+
|
|
107
|
+
logger.debug rrd.fetch!(:average)[-2..-1]
|
|
108
|
+
|
|
109
|
+
rrd.fetch(:average)[-2..-1].first.last
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def logger
|
|
113
|
+
@logger ||= Logger.new(STDOUT)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'observed/gauge/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'observed-gauge'
|
|
8
|
+
spec.version = Observed::Gauge::VERSION
|
|
9
|
+
spec.authors = ['KUOKA Yusuke']
|
|
10
|
+
spec.email = ['yusuke.kuoka@gree.net']
|
|
11
|
+
spec.description = %q{Gauge plugin for Observed}
|
|
12
|
+
spec.summary = %q{A plugin to consolidate outputs from other Observed output plugins by averaging values by averaging them over configured periods}
|
|
13
|
+
spec.homepage = ''
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ['lib']
|
|
20
|
+
|
|
21
|
+
spec.add_dependency 'observed', '~> 0.1.0'
|
|
22
|
+
spec.add_dependency 'rrd-ffi', '~> 0.2.14'
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
|
25
|
+
spec.add_development_dependency 'rake'
|
|
26
|
+
spec.add_development_dependency 'rspec'
|
|
27
|
+
spec.add_development_dependency 'mocha'
|
|
28
|
+
spec.add_development_dependency 'fakefs'
|
|
29
|
+
spec.add_development_dependency 'simplecov'
|
|
30
|
+
end
|