observed 0.1.1 → 0.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +9 -9
  2. data/.travis.yml +4 -0
  3. data/README.md +53 -78
  4. data/examples/observed.rb +1 -1
  5. data/exe/observed-oneshot +3 -1
  6. data/features/explicit_routing.feature +33 -0
  7. data/features/oneshot.feature +4 -0
  8. data/features/test_in_single_ruby_source.feature +4 -0
  9. data/integrations/observed-clockwork/features/run_observed_inside_clockwork.feature +6 -7
  10. data/integrations/observed-clockwork/lib/observed/clockwork/version.rb +1 -1
  11. data/integrations/observed-clockwork/lib/observed/clockwork.rb +0 -1
  12. data/integrations/observed-clockwork/observed-clockwork.gemspec +1 -1
  13. data/integrations/observed-eventmachine/.gitignore +17 -0
  14. data/integrations/observed-eventmachine/Gemfile +8 -0
  15. data/integrations/observed-eventmachine/LICENSE.txt +22 -0
  16. data/integrations/observed-eventmachine/README.md +29 -0
  17. data/integrations/observed-eventmachine/Rakefile +1 -0
  18. data/integrations/observed-eventmachine/examples/observed.rb +30 -0
  19. data/integrations/observed-eventmachine/features/integration_via_single_ruby_source.feature +48 -0
  20. data/integrations/observed-eventmachine/features/support/env.rb +8 -0
  21. data/integrations/observed-eventmachine/lib/observed/eventmachine/version.rb +5 -0
  22. data/integrations/observed-eventmachine/lib/observed/eventmachine.rb +70 -0
  23. data/integrations/observed-eventmachine/observed-eventmachine.gemspec +28 -0
  24. data/lib/observed/application/oneshot.rb +14 -37
  25. data/lib/observed/builtin_plugins/file.rb +5 -14
  26. data/lib/observed/builtin_plugins/stdout.rb +7 -14
  27. data/lib/observed/config.rb +4 -4
  28. data/lib/observed/config_builder.rb +154 -87
  29. data/lib/observed/config_dsl.rb +2 -8
  30. data/lib/observed/configurable.rb +61 -3
  31. data/lib/observed/context.rb +90 -0
  32. data/lib/observed/default/observer.rb +2 -5
  33. data/lib/observed/default.rb +0 -1
  34. data/lib/observed/event_bus.rb +31 -0
  35. data/lib/observed/execution_job_factory.rb +95 -0
  36. data/lib/observed/job.rb +163 -0
  37. data/lib/observed/jobbed_event_bus.rb +33 -0
  38. data/lib/observed/logging.rb +40 -0
  39. data/lib/observed/observer.rb +1 -0
  40. data/lib/observed/observer_helpers/timer.rb +13 -5
  41. data/lib/observed/pluggable.rb +11 -0
  42. data/lib/observed/reporter/regexp_matching.rb +2 -1
  43. data/lib/observed/reporter/report_formatting.rb +57 -0
  44. data/lib/observed/reporter.rb +0 -2
  45. data/lib/observed/system.rb +11 -78
  46. data/lib/observed/translator.rb +22 -0
  47. data/lib/observed/version.rb +1 -1
  48. data/lib/observed.rb +10 -12
  49. data/omnibus-observed/.gitignore +9 -0
  50. data/omnibus-observed/Berksfile +3 -0
  51. data/omnibus-observed/Berksfile.lock +52 -0
  52. data/omnibus-observed/Gemfile +4 -0
  53. data/omnibus-observed/README.md +102 -0
  54. data/omnibus-observed/Vagrantfile +93 -0
  55. data/omnibus-observed/config/projects/observed.rb +20 -0
  56. data/omnibus-observed/config/software/observed.rb +19 -0
  57. data/omnibus-observed/package-scripts/observed/makeselfinst +27 -0
  58. data/omnibus-observed/package-scripts/observed/postinst +17 -0
  59. data/omnibus-observed/package-scripts/observed/postrm +9 -0
  60. data/plugins/observed-fluentd/lib/observed/fluentd/version.rb +1 -1
  61. data/plugins/observed-gauge/README.md +5 -0
  62. data/plugins/observed-gauge/lib/observed/gauge/version.rb +1 -1
  63. data/plugins/observed-gauge/lib/observed/gauge.rb +11 -13
  64. data/plugins/observed-gauge/observed-gauge.gemspec +1 -1
  65. data/plugins/observed-gauge/spec/gauge_spec.rb +7 -7
  66. data/plugins/observed-growl/Gemfile +6 -0
  67. data/plugins/observed-growl/lib/observed/growl.rb +80 -0
  68. data/plugins/observed-http/lib/observed/http/version.rb +1 -1
  69. data/plugins/observed-http/lib/observed/http.rb +10 -8
  70. data/plugins/observed-http/observed-http.gemspec +1 -1
  71. data/plugins/observed-http/spec/http_spec.rb +62 -7
  72. data/plugins/observed-http/spec/integration_spec.rb +14 -0
  73. data/plugins/observed-shell/Gemfile +5 -0
  74. data/plugins/observed-shell/lib/observed/shell.rb +54 -0
  75. data/run-integration-tests +81 -0
  76. data/spec/builtin_plugins/stdout_spec.rb +7 -3
  77. data/spec/config_builder_spec.rb +42 -59
  78. data/spec/config_dsl_spec.rb +4 -0
  79. data/spec/configurable_spec.rb +141 -31
  80. data/spec/event_bus_spec.rb +16 -0
  81. data/spec/execution_job_factory_spec.rb +35 -0
  82. data/spec/job_factory_spec.rb +16 -0
  83. data/spec/job_spec.rb +228 -0
  84. data/spec/jobbed_event_bus_spec.rb +38 -0
  85. data/spec/observed_spec.rb +203 -0
  86. data/spec/observer_helpers/timer_spec.rb +187 -0
  87. data/spec/oneshot_spec.rb +7 -2
  88. data/spec/system_spec.rb +5 -39
  89. metadata +55 -12
  90. data/lib/observed/default/reporter.rb +0 -17
  91. data/lib/observed/reader.rb +0 -14
  92. data/lib/observed/writer.rb +0 -14
  93. data/spec/reader_spec.rb +0 -15
  94. data/spec/writer_spec.rb +0 -16
@@ -7,6 +7,7 @@ module Observed
7
7
  def initialize(args={})
8
8
  @config = args[:config] if args[:config]
9
9
  @logger = args[:logger] if args[:logger]
10
+ @context = args[:context]
10
11
  end
11
12
 
12
13
  def config=(config)
@@ -17,93 +18,25 @@ module Observed
17
18
  @config
18
19
  end
19
20
 
20
- def report(tag, time, data=nil)
21
- if data.nil?
22
- data = time
23
- time = self.now
24
- end
25
- reporters.each do |reporter|
26
- if reporter.match(tag)
27
- reporter.report(tag, time, data)
28
- end
29
- end
30
- end
31
-
32
- def run(observation_name=nil)
33
-
21
+ def run(observation_name=nil, data=nil, options=nil)
22
+ options = { tag: (options && options[:tag]) || observation_name, time: now }.merge(options || {})
23
+ params = [data, options]
34
24
  if observation_name
35
- observers_to_run = observers.reject { |o| o.tag != observation_name }
36
- fail "No configuration found for observation name '#{observation_name}'" if observers_to_run.empty?
25
+ fail "No configuration found for observation name '#{observation_name}'" if @context.config_builder.group(observation_name).empty?
26
+ @context.config_builder.run_group(observation_name).send :now, *params
37
27
  else
38
- observers_to_run = observers
39
- end
40
-
41
- observers_to_run.map do |input|
42
- input.observe
28
+ observers_to_run = @context.config_builder.observers
29
+ fail "No configuration found for observation name '#{observation_name}'" if observers_to_run.empty?
30
+ observers_to_run.each do |o|
31
+ o.send :now, *params
32
+ end
43
33
  end
44
-
45
34
  end
46
35
 
47
36
  def now
48
37
  Time.now
49
38
  end
50
39
 
51
- def logger
52
- @logger ||= Logger.new(STDOUT)
53
- end
54
-
55
- private
56
-
57
- def observers
58
- config.observers
59
- end
60
-
61
- def reporters
62
- config.reporters
63
- end
64
-
65
40
  end
66
41
 
67
- class YAML
68
- def observers
69
- config.observers
70
- @observers ||= begin
71
-
72
- observer_configs = config.observers
73
-
74
- observers = {}
75
-
76
- observer_configs.each do |tag, input_config|
77
- plugin_name = input_config[:plugin] || fail(RuntimeError, %Q|Missing plugin name for the tag "#{tag}" in "#{input_config}" in "#{config}".|)
78
- plugin = observer_plugins[plugin_name] || fail(RuntimeError, %Q|The plugin named "#{plugin_name}" is not found in plugins list "#{observer_plugins}".|)
79
- updated_config = input_config.merge(tag: tag)
80
- observer = plugin.new(updated_config)
81
- observer.configure(system: self, logger: logger)
82
- observers[tag] = observer
83
- end
84
-
85
- observers
86
- end
87
- end
88
-
89
- def reporters
90
- @reporters ||= begin
91
-
92
- reporter_configs = config.reporters
93
-
94
- reporters = {}
95
-
96
- reporter_configs.each do |tag_pattern, output_config|
97
- plugin_name = output_config[:plugin] || fail(RuntimeError, %Q|Missing plugin name for the output for "#{tag_pattern}" in "#{output_config}" in #{config}.|)
98
- plugin = reporter_plugins[plugin_name] || fail(RuntimeError, %Q|The plugin named "#{plugin_name}" is not found in plugins list "#{reporter_plugins}".|)
99
- updated_config = output_config.merge(tag_pattern: Regexp.new(tag_pattern))
100
- reporter = plugin.new(updated_config)
101
- reporter.configure(system: self, logger: logger)
102
- reporters[tag_pattern] = reporter
103
- end
104
-
105
- reporters
106
- end
107
- end
108
- end
109
42
  end
@@ -0,0 +1,22 @@
1
+ require 'observed/configurable'
2
+ require 'observed/logging'
3
+ require 'observed/pluggable'
4
+
5
+ module Observed
6
+ class Translator
7
+
8
+ include Observed::Configurable
9
+ include Observed::Logging
10
+ include Observed::Pluggable
11
+
12
+ attribute :tag_pattern
13
+
14
+ def match(tag)
15
+ tag_pattern.match(tag)
16
+ end
17
+
18
+ def translate(tag, time, data)
19
+ fail RuntimeError, 'Not implemented method: Observed#translate'
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Observed
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0.rc1'
3
3
  end
data/lib/observed.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  require 'observed/version'
2
- require 'observed/config_builder'
3
- require 'observed/system'
4
- require 'observed/config_dsl'
2
+ require 'observed/context'
5
3
  require 'observed/builtin_plugins'
6
4
  require 'forwardable'
7
5
 
@@ -28,24 +26,24 @@ module Observed
28
26
  class Singleton
29
27
  extend Forwardable
30
28
 
31
- def_delegators :@observed, :require_relative, :observe, :report, :write, :read, :config, :load!, :working_directory
29
+ def_delegators :@observed, :require_relative, :observe, :translate, :report, :write, :read, :emit, :receive, :group, :run_group, :config, :load!, :working_directory
32
30
 
33
31
  # Call this method before you are going to build 2nd or later Observed configuration using this module.
34
32
  # Refrain that `Observed` object is a builder for Observed configuration and it has global state.
35
33
  # We have to reset its state via this `init!` method before building next configurations after the first one.
36
34
  def init!
37
- @sys = Observed::System.new
38
- config_builder = Observed::ConfigBuilder.new(system: @sys)
39
- @observed = Observed::ConfigDSL.new(builder: config_builder)
35
+ @context = Observed::Context.new
36
+ @observed = @context.config_dsl
40
37
  end
41
38
 
42
- def run(tag=nil)
43
- @sys.config = self.config
44
- @sys.run(tag)
39
+ def run(tag=nil, data=nil, options=nil)
40
+ sys = @context.system
41
+ sys.config = @observed.config
42
+ sys.send :run, *[tag, data, options].take_while { |a| a != nil }
45
43
  end
46
44
 
47
45
  def configure(*args)
48
- @observed.send :configure, *args
46
+ @context.configure *args
49
47
  end
50
48
  end
51
49
 
@@ -69,7 +67,7 @@ module Observed
69
67
 
70
68
  extend Forwardable
71
69
 
72
- def_delegators :@@singleton, :run, :init!, :configure, :require_relative, :observe, :report, :write, :read, :config,
70
+ def_delegators :@@singleton, :run, :init!, :configure, :require_relative, :observe, :translate, :report, :write, :read, :emit, :receive, :group, :run_group, :config,
73
71
  :load!, :working_directory
74
72
 
75
73
  extend self
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle
3
+ vendor/bundle
4
+ pkg/*
5
+ .vagrant
6
+ bin/*
7
+ files/**/cache/
8
+ vendor/cookbooks
9
+ *~
@@ -0,0 +1,3 @@
1
+ site :opscode
2
+
3
+ cookbook "omnibus"
@@ -0,0 +1,52 @@
1
+ {
2
+ "sources": {
3
+ "omnibus": {
4
+ "locked_version": "1.2.0"
5
+ },
6
+ "apt": {
7
+ "locked_version": "1.9.2"
8
+ },
9
+ "build-essential": {
10
+ "locked_version": "1.4.2"
11
+ },
12
+ "git": {
13
+ "locked_version": "2.3.0"
14
+ },
15
+ "dmg": {
16
+ "locked_version": "2.0.8"
17
+ },
18
+ "yum": {
19
+ "locked_version": "2.4.2"
20
+ },
21
+ "windows": {
22
+ "locked_version": "1.11.0"
23
+ },
24
+ "chef_handler": {
25
+ "locked_version": "1.1.4"
26
+ },
27
+ "runit": {
28
+ "locked_version": "1.4.0"
29
+ },
30
+ "homebrew": {
31
+ "locked_version": "1.3.2"
32
+ },
33
+ "pkgin": {
34
+ "locked_version": "0.4.0"
35
+ },
36
+ "pkgutil": {
37
+ "locked_version": "0.0.3"
38
+ },
39
+ "rbenv": {
40
+ "locked_version": "1.6.5"
41
+ },
42
+ "ohai": {
43
+ "locked_version": "1.1.12"
44
+ },
45
+ "wix": {
46
+ "locked_version": "1.1.0"
47
+ },
48
+ "7-zip": {
49
+ "locked_version": "1.0.2"
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'omnibus', '~> 1.2.0'
4
+ gem 'omnibus-software', :git => 'git://github.com/opscode/omnibus-software.git', :branch => 'master'
@@ -0,0 +1,102 @@
1
+ # observed Omnibus project
2
+
3
+ This project creates full-stack platform-specific packages for
4
+ `observed`!
5
+
6
+ ## Installation
7
+
8
+ We'll assume you have Ruby 1.9+ and Bundler installed. First ensure all
9
+ required gems are installed and ready to use:
10
+
11
+ ```shell
12
+ $ bundle install --binstubs
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Build
18
+
19
+ You create a platform-specific package using the `build project` command:
20
+
21
+ ```shell
22
+ $ bin/omnibus build project observed
23
+ ```
24
+
25
+ The platform/architecture type of the package created will match the platform
26
+ where the `build project` command is invoked. So running this command on say a
27
+ MacBook Pro will generate a Mac OS X specific package. After the build
28
+ completes packages will be available in `pkg/`.
29
+
30
+ ### Clean
31
+
32
+ You can clean up all temporary files generated during the build process with
33
+ the `clean` command:
34
+
35
+ ```shell
36
+ $ bin/omnibus clean
37
+ ```
38
+
39
+ Adding the `--purge` purge option removes __ALL__ files generated during the
40
+ build including the project install directory (`/opt/observed`) and
41
+ the package cache directory (`/var/cache/omnibus/pkg`):
42
+
43
+ ```shell
44
+ $ bin/omnibus clean --purge
45
+ ```
46
+
47
+ ### Help
48
+
49
+ Full help for the Omnibus command line interface can be accessed with the
50
+ `help` command:
51
+
52
+ ```shell
53
+ $ bin/omnibus help
54
+ ```
55
+
56
+ ## Vagrant-based Virtualized Build Lab
57
+
58
+ Every Omnibus project ships will a project-specific
59
+ [Berksfile](http://berkshelf.com/) and [Vagrantfile](http://www.vagrantup.com/)
60
+ that will allow you to build your projects on the following platforms:
61
+
62
+ * CentOS 5 64-bit
63
+ * CentOS 6 64-bit
64
+ * Ubuntu 10.04 64-bit
65
+ * Ubuntu 11.04 64-bit
66
+ * Ubuntu 12.04 64-bit
67
+
68
+ Please note this build-lab is only meant to get you up and running quickly;
69
+ there's nothing inherent in Omnibus that restricts you to just building CentOS
70
+ or Ubuntu packages. See the Vagrantfile to add new platforms to your build lab.
71
+
72
+ The only requirements for standing up this virtualized build lab are:
73
+
74
+ * VirtualBox - native packages exist for most platforms and can be downloaded
75
+ from the [VirtualBox downloads page](https://www.virtualbox.org/wiki/Downloads).
76
+ * Vagrant 1.2.1+ - native packages exist for most platforms and can be downloaded
77
+ from the [Vagrant downloads page](http://downloads.vagrantup.com/).
78
+
79
+ The [vagrant-berkshelf](https://github.com/RiotGames/vagrant-berkshelf) and
80
+ [vagrant-omnibus](https://github.com/schisamo/vagrant-omnibus) Vagrant plugins
81
+ are also required and can be installed easily with the following commands:
82
+
83
+ ```shell
84
+ $ vagrant plugin install vagrant-berkshelf
85
+ $ vagrant plugin install vagrant-omnibus
86
+ ```
87
+
88
+ Once the pre-requisites are installed you can build your package across all
89
+ platforms with the following command:
90
+
91
+ ```shell
92
+ $ vagrant up
93
+ ```
94
+
95
+ If you would like to build a package for a single platform the command looks like this:
96
+
97
+ ```shell
98
+ $ vagrant up PLATFORM
99
+ ```
100
+
101
+ The complete list of valid platform names can be viewed with the
102
+ `vagrant status` command.
@@ -0,0 +1,93 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ require "vagrant"
5
+
6
+ if Vagrant::VERSION < "1.2.1"
7
+ raise "The Omnibus Build Lab is only compatible with Vagrant 1.2.1+"
8
+ end
9
+
10
+ host_project_path = File.expand_path("..", __FILE__)
11
+ guest_project_path = "/home/vagrant/#{File.basename(host_project_path)}"
12
+ project_name = "observed"
13
+
14
+ Vagrant.configure("2") do |config|
15
+
16
+ config.vm.hostname = "#{project_name}-omnibus-build-lab"
17
+
18
+ config.vm.define 'ubuntu-10.04' do |c|
19
+ c.berkshelf.berksfile_path = "./Berksfile"
20
+ c.vm.box = "opscode-ubuntu-10.04"
21
+ c.vm.box_url = "http://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_chef-11.2.0.box"
22
+ end
23
+
24
+ config.vm.define 'ubuntu-11.04' do |c|
25
+ c.berkshelf.berksfile_path = "./Berksfile"
26
+ c.vm.box = "opscode-ubuntu-11.04"
27
+ c.vm.box_url = "http://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-ubuntu-11.04.box"
28
+ end
29
+
30
+ config.vm.define 'ubuntu-12.04' do |c|
31
+ c.berkshelf.berksfile_path = "./Berksfile"
32
+ c.vm.box = "canonical-ubuntu-12.04"
33
+ c.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box"
34
+ end
35
+
36
+ config.vm.define 'centos-5' do |c|
37
+ c.berkshelf.berksfile_path = "./Berksfile"
38
+ c.vm.box = "opscode-centos-5.8"
39
+ c.vm.box_url = "http://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-5.8_chef-11.2.0.box"
40
+ end
41
+
42
+ config.vm.define 'centos-6' do |c|
43
+ c.berkshelf.berksfile_path = "./Berksfile"
44
+ c.vm.box = "opscode-centos-6.3"
45
+ c.vm.box_url = "http://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-6.3_chef-11.2.0.box"
46
+ end
47
+
48
+ config.vm.provider :virtualbox do |vb|
49
+ # Give enough horsepower to build without taking all day.
50
+ vb.customize [
51
+ "modifyvm", :id,
52
+ "--memory", "1536",
53
+ "--cpus", "2"
54
+ ]
55
+ end
56
+
57
+ # Ensure a recent version of the Chef Omnibus packages are installed
58
+ config.omnibus.chef_version = :latest
59
+
60
+ # Enable the berkshelf-vagrant plugin
61
+ config.berkshelf.enabled = true
62
+ # The path to the Berksfile to use with Vagrant Berkshelf
63
+ config.berkshelf.berksfile_path = "./Berksfile"
64
+
65
+ config.ssh.forward_agent = true
66
+
67
+ host_project_path = File.expand_path("..", __FILE__)
68
+ guest_project_path = "/home/vagrant/#{File.basename(host_project_path)}"
69
+
70
+ config.vm.synced_folder host_project_path, guest_project_path
71
+
72
+ # prepare VM to be an Omnibus builder
73
+ config.vm.provision :chef_solo do |chef|
74
+ chef.json = {
75
+ "omnibus" => {
76
+ "build_user" => "vagrant",
77
+ "build_dir" => guest_project_path,
78
+ "install_dir" => "/opt/#{project_name}"
79
+ }
80
+ }
81
+
82
+ chef.run_list = [
83
+ "recipe[omnibus::default]"
84
+ ]
85
+ end
86
+
87
+ config.vm.provision :shell, :inline => <<-OMNIBUS_BUILD
88
+ export PATH=/usr/local/bin:$PATH
89
+ cd #{guest_project_path}
90
+ su vagrant -c "bundle install --binstubs"
91
+ su vagrant -c "bin/omnibus build project #{project_name}"
92
+ OMNIBUS_BUILD
93
+ end
@@ -0,0 +1,20 @@
1
+
2
+ name "observed"
3
+ maintainer "KUOKA Yusuke"
4
+ homepage "https://github.com/gree/observed"
5
+
6
+ replaces "observed"
7
+ install_path "/opt/observed"
8
+ build_version Omnibus::BuildVersion.new.semver
9
+ build_iteration 1
10
+
11
+ # creates required build directories
12
+ dependency "preparation"
13
+
14
+ dependency "observed"
15
+
16
+ # version manifest file
17
+ dependency "version-manifest"
18
+
19
+ exclude "\.git*"
20
+ exclude "bundler\/git"
@@ -0,0 +1,19 @@
1
+ name "observed"
2
+ #version "0.1.1"
3
+ version "master"
4
+
5
+ dependency "ruby"
6
+ dependency "rubygems"
7
+ #dependency "bundler"
8
+ dependency "rsync"
9
+
10
+ source :git => "https://github.com/gree/observed.git"
11
+
12
+ relative_path "observed"
13
+
14
+ build do
15
+ gem "install bundler --no-rdoc --no-ri -v 1.3.0"
16
+ bundle "install --path=#{install_dir}/embedded/service/gem"
17
+ command "mkdir -p #{install_dir}/embedded/service/observed"
18
+ command "#{install_dir}/embedded/bin/rsync -a --delete --exclude=.git/*** --exclude=.gitignore ./ #{install_dir}/embedded/service/observed/"
19
+ end
@@ -0,0 +1,27 @@
1
+ #!/bin/bash
2
+ #
3
+ # Install a full observed
4
+ #
5
+
6
+ PROGNAME=`basename $0`
7
+ INSTALLER_DIR=`dirname $0`
8
+ DEST_DIR=/opt/observed
9
+ CONFIG_DIR=/etc/observed
10
+ USAGE="usage: $0"
11
+
12
+ error_exit()
13
+ {
14
+ echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
15
+ exit 1
16
+ }
17
+
18
+ # move the actual files into place
19
+ rm -rf $DEST_DIR/* || error_exit "Cannot remove contents of $DEST_DIR"
20
+ mkdir -p $DEST_DIR || error_exit "Cannot create $DEST_DIR"
21
+ cp -R $INSTALLER_DIR $DEST_DIR || error_exit "Cannot install to $DEST_DIR"
22
+ rm -f $DEST_DIR/$PROGNAME
23
+
24
+ # You may want to symlink your packages bin files into /usr/bin
25
+ # ln -sf $DEST_DIR/bin/observed /usr/bin || error_exit "Cannot link observed to /usr/bin"
26
+
27
+ exit 0
@@ -0,0 +1,17 @@
1
+ #!/bin/bash
2
+ #
3
+ # Perform necessary observed setup steps
4
+ # after package is installed.
5
+ #
6
+
7
+ PROGNAME=$(basename $0)
8
+
9
+ function error_exit
10
+ {
11
+ echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
12
+ exit 1
13
+ }
14
+
15
+ echo "Thank you for installing observed!"
16
+
17
+ exit 0
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+ #
3
+ # Perform necessary observed removal steps
4
+ # after package is uninstalled.
5
+ #
6
+
7
+ echo "observed has been uninstalled!"
8
+
9
+ exit 0
@@ -1,5 +1,5 @@
1
1
  module Observed
2
2
  class Fluentd
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0.rc1"
4
4
  end
5
5
  end
@@ -16,6 +16,11 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install observed-gauge
18
18
 
19
+ You might also need to install rrdtool:
20
+
21
+ (CentOS or Ubuntu)
22
+ $ sudo apt-get install librrd-dev
23
+
19
24
  ## Usage
20
25
 
21
26
  TODO: Write usage instructions here
@@ -1,5 +1,5 @@
1
1
  module Observed
2
2
  module Gauge
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0.rc1"
4
4
  end
5
5
  end
@@ -1,4 +1,5 @@
1
- require 'observed/reporter'
1
+ require 'observed/logging'
2
+ require 'observed/translator'
2
3
  require 'observed/reporter/regexp_matching'
3
4
  require 'observed/gauge/version'
4
5
  require 'logger'
@@ -6,39 +7,40 @@ require 'rrd'
6
7
 
7
8
  module Observed
8
9
  module Plugins
9
- class Gauge < Observed::Reporter
10
+ class Gauge < Observed::Translator
10
11
 
11
12
  plugin_name 'gauge'
12
13
 
14
+ include Observed::Logging
13
15
  include Observed::Reporter::RegexpMatching
14
16
 
15
- attribute :tag
16
17
  attribute :key_path
17
18
  attribute :coerce, default: ->(data){ data }
18
19
  attribute :rrd
19
20
  attribute :step
20
21
  attribute :period
21
22
 
22
- def report(tag, time, data)
23
+ def translate(data, options)
24
+ time = options[:time] || Time.now
23
25
  rewrote = update_value_for_key_path(data, key_path) do |v|
24
26
  sample = coerce.call(v)
25
27
  average = get_cdp_updated_with(time, sample)
26
28
  average
27
29
  end
28
30
  unless fetch_value_for_key_path(rewrote, key_path).nan?
29
- system.report(self.tag, rewrote)
31
+ rewrote
30
32
  end
31
33
  end
32
34
 
33
35
  def prepare_rrd(args)
34
36
  start = args[:start]
35
- logger.debug "Creating a rrd file named '#{args[:rrd]}' with options {:start => #{start}}"
37
+ log_debug "Creating a rrd file named '#{args[:rrd]}' with options {:start => #{start}}"
36
38
  result = RRD::Builder.new(args[:rrd], start: start, step: step.seconds).tap do |builder|
37
39
  builder.datasource data_source, :type => :gauge, :heartbeat => period.seconds, :min => 0, :max => :unlimited
38
40
  builder.archive :average, :every => period.seconds, :during => period.seconds
39
41
  builder.save
40
42
  end
41
- logger.debug "Builder#save returned: #{result.inspect}"
43
+ log_debug "Builder#save returned: #{result.inspect}"
42
44
  end
43
45
 
44
46
  private
@@ -101,17 +103,13 @@ module Observed
101
103
  prepare_rrd(rrd: rrd_path, start: t)
102
104
  end
103
105
 
104
- logger.debug "Updating the data source '#{data_source}' with the value #{value} with timestamp #{t}"
106
+ log_debug "Updating the data source '#{data_source}' with the value #{value} with timestamp #{t}"
105
107
  rrd.update t, value
106
108
 
107
- logger.debug rrd.fetch!(:average)[-2..-1]
109
+ log_debug rrd.fetch!(:average)[-2..-1]
108
110
 
109
111
  rrd.fetch(:average)[-2..-1].first.last
110
112
  end
111
-
112
- def logger
113
- @logger ||= Logger.new(STDOUT)
114
- end
115
113
  end
116
114
  end
117
115
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'observed', '~> 0.1.0'
21
+ spec.add_dependency 'observed', '~> 0.2.0.rc1'
22
22
  spec.add_dependency 'rrd-ffi', '~> 0.2.14'
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.3'