nephelae 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,10 +2,8 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
- .yardoc
6
5
  Gemfile.lock
7
6
  InstalledFiles
8
- _yardoc
9
7
  coverage
10
8
  doc/
11
9
  lib/bundler/man
@@ -15,3 +13,7 @@ spec/reports
15
13
  test/tmp
16
14
  test/version_tmp
17
15
  tmp
16
+
17
+ # YARD artifacts
18
+ .yardoc
19
+ _yardoc
@@ -3,57 +3,60 @@ require 'rubygems'
3
3
  require 'daemons'
4
4
  require 'nephelae'
5
5
  require 'optparse'
6
+ require 'yaml'
6
7
 
7
8
  settings = {}
8
9
  logfile = ""
9
10
  loglevel = nil
10
11
 
12
+ cmd = ARGV.first
13
+
14
+ file = '/etc/nephelae.yml'
15
+ logfile = STDOUT
16
+ loglevel = Logger::WARN
17
+ logdir = '/var/log'
18
+ piddir = '/var/run'
19
+
11
20
  OptionParser.new do |o|
12
21
  o.banner << " command"
13
- o.on("-k", "--aws-access-key-id ACCESSKEY", "AWS Access Key to use for cloudwatch") do |v|
14
- settings[:aws_access_key_id] = v
15
- end
16
- o.on("-s", "--aws-secret-access-key SECRETKEY", "AWS Secret Access Key to use for cloudwatch") do |v|
17
- settings[:aws_secret_access_key] = v
22
+
23
+ o.on("--config CONFIGFILE", "The config file to use for plugins (and aws settin3yygs)") do |v|
24
+ file = v
18
25
  end
19
26
 
20
- o.on("-r", "--region REGION", "The region to use for cloudwatch") do |v|
21
- settings[:region] = v
27
+ o.on("--logdir LOGDIR", "The directory to put log files") do |v|
28
+ logdir = v
22
29
  end
23
30
 
24
- o.on("-lf", "--logfile [FILEPATH]", "The filepath to log to") do |v|
25
- logfile = v || STDOUT
31
+ o.on("--piddir PIDDIR", "The directory to put pid files") do |v|
32
+ piddir = v
26
33
  end
27
34
 
28
- o.on("-ll", "--loglevel [LOGLEVEL]", "The level to log to") do |v|
29
- unless v.nil?
30
- DEBUG < INFO < WARN < ERROR < FATAL
31
- case v
32
- when "debug"
33
- loglevel = Logger::DEBUG
34
- when "info"
35
- loglevel = Logger::INFO
36
- when "warn"
37
- loglevel = Logger::WARN
38
- when "error"
39
- loglevel = Logger::ERROR
40
- when "fatal"
41
- loglevel = Logger::FATAL
42
- else
43
- loglevel = Logger::WARN
44
- end
35
+ o.on("--loglevel LOGLEVEL", "The level to log to") do |v|
36
+ case v.downcase
37
+ when "debug"
38
+ loglevel = Logger::DEBUG
39
+ when "info"
40
+ loglevel = Logger::INFO
41
+ when "warn"
42
+ loglevel = Logger::WARN
43
+ when "error"
44
+ loglevel = Logger::ERROR
45
+ when "fatal"
46
+ loglevel = Logger::FATAL
45
47
  else
46
48
  loglevel = Logger::WARN
47
- end
49
+ end unless v.nil?
48
50
  end
49
51
  end.parse!
50
52
 
51
53
  log = Logger.new(logfile)
52
54
  log.level = loglevel
53
55
  Nephelae::Logging.logger = log
56
+ File.open( file ) { |yf| settings = YAML::load( yf ) }
54
57
 
55
- new_argv = [ARGV.first]
56
- Daemons.run_proc('nephelae', {ARGV: new_argv}) do
58
+ new_argv = [cmd]
59
+ Daemons.run_proc('nephelae', {ARGV: new_argv, log_dir: logdir, dir_mode: :normal, dir: piddir, log_output: true}) do
57
60
  r = Nephelae::Runner.new(settings)
58
61
  r.run
59
62
  end
@@ -4,6 +4,7 @@ require "nephelae/cloud_watch/simple_aws"
4
4
  require "nephelae/cloud_watch/cloud_watch"
5
5
  require "nephelae/cloud_watch/metrics"
6
6
 
7
+ require "nephelae/plugins/plugin"
7
8
  require "nephelae/plugins/disk_space"
8
9
  require "nephelae/plugins/mem_usage"
9
10
  require "nephelae/plugins/nephelae_process"
@@ -1,18 +1,9 @@
1
1
  module Nephelae
2
2
 
3
- class DiskSpace
4
- attr_accessor :path
5
-
6
- def initialize(params = {})
7
- @path = params[:path] || '/'
8
- end
9
-
10
- def command
11
- "/bin/df -k -l -P #{@path}"
12
- end
3
+ class DiskSpace < Plugin
13
4
 
14
5
  def get_metrics
15
- metrics = Metrics.new('Nephelae/Linux')
6
+ metrics = Metrics.new(namespace)
16
7
  output = `#{command}`
17
8
  stats = output.split(/\n/).last.split(/\s+/)
18
9
 
@@ -25,6 +16,17 @@ module Nephelae
25
16
 
26
17
  end
27
18
 
19
+ private
20
+
21
+ def default_namespace
22
+ 'Nephelae/Linux'
23
+ end
24
+
25
+ def command
26
+ path = config[:path] || '/'
27
+ "/bin/df -k -l -P #{path}"
28
+ end
29
+
28
30
  end
29
31
 
30
32
  end
@@ -1,16 +1,9 @@
1
1
  module Nephelae
2
2
 
3
- class MemUsage
4
-
5
- def initialize(params = {})
6
- end
7
-
8
- def command
9
- "cat /proc/meminfo"
10
- end
3
+ class MemUsage < Plugin
11
4
 
12
5
  def get_metrics
13
- metrics = Metrics.new('Nephelae/Linux')
6
+ metrics = Metrics.new(namespace)
14
7
  output = `#{command}`
15
8
 
16
9
  if $?.success?
@@ -58,6 +51,14 @@ module Nephelae
58
51
  }
59
52
  end
60
53
 
54
+ def default_namespace
55
+ 'Nephelae/Linux'
56
+ end
57
+
58
+ def command
59
+ "cat /proc/meminfo"
60
+ end
61
+
61
62
  end
62
63
 
63
64
  end
@@ -1,12 +1,9 @@
1
1
  module Nephelae
2
2
 
3
- class NephelaeProcess
4
-
5
- def initialize(params = {})
6
- end
3
+ class NephelaeProcess < Plugin
7
4
 
8
5
  def get_metrics
9
- metrics = Metrics.new('Nephelae/Process')
6
+ metrics = Metrics.new(namespace)
10
7
 
11
8
  #if we are doing this we are up
12
9
  metrics.append_metric('Up', 1)
@@ -15,6 +12,12 @@ module Nephelae
15
12
 
16
13
  end
17
14
 
15
+ private
16
+
17
+ def default_namespace
18
+ 'Nephelae/Linux'
19
+ end
20
+
18
21
  end
19
22
 
20
23
  end
@@ -1,16 +1,9 @@
1
1
  module Nephelae
2
2
 
3
- class PassengerStatus
4
-
5
- def initialize(params = {})
6
- end
7
-
8
- def command
9
- "passenger-status"
10
- end
3
+ class PassengerStatus < Plugin
11
4
 
12
5
  def get_metrics
13
- metrics = Metrics.new('Nephelae/Passenger')
6
+ metrics = Metrics.new(namespace)
14
7
  output = `#{command}`
15
8
 
16
9
  if $?.success?
@@ -37,6 +30,15 @@ module Nephelae
37
30
  }
38
31
  end
39
32
 
33
+ def default_namespace
34
+ 'Nephelae/Passenger'
35
+ end
36
+
37
+ def command
38
+ "passenger-status"
39
+ end
40
+
41
+
40
42
  end
41
43
 
42
44
  end
@@ -0,0 +1,26 @@
1
+ module Nephelae
2
+
3
+ class Plugin
4
+ attr_accessor :config
5
+
6
+ def initialize(config = {})
7
+ @config = config
8
+ end
9
+
10
+ def get_metrics
11
+ metrics = Metrics.new(namespace)
12
+ return metrics
13
+ end
14
+
15
+ def namespace
16
+ namespace = config[:namespace] || default_namespace
17
+ end
18
+
19
+ private
20
+ def default_namespace
21
+ "Nephelae/Plugin"
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -1,16 +1,9 @@
1
1
  module Nephelae
2
2
 
3
- class RedisStatus
4
-
5
- def initialize(params = {})
6
- end
7
-
8
- def command
9
- "/usr/local/bin/redis-cli info"
10
- end
3
+ class RedisStatus < Plugin
11
4
 
12
5
  def get_metrics
13
- metrics = Metrics.new('Nephelae/Redis')
6
+ metrics = Metrics.new(namespace)
14
7
  output = `#{command}`
15
8
 
16
9
  if $?.success?
@@ -47,6 +40,16 @@ module Nephelae
47
40
  })
48
41
  end
49
42
 
43
+ def command
44
+ port = config[:port].nil? ? "" : " -p #{config[:port]}"
45
+ password = config[:password].nil? ? "" : " -a #{config[:password]}"
46
+ "/usr/local/bin/redis-cli#{port}#{password} info"
47
+ end
48
+
49
+ def default_namespace
50
+ "Nephelae/Redis"
51
+ end
52
+
50
53
  end
51
54
 
52
55
  end
@@ -4,12 +4,13 @@ module Nephelae
4
4
  class Runner
5
5
  include Logging
6
6
 
7
- attr_accessor :aws_access_key_id, :aws_secret_access_key, :region
7
+ attr_accessor :aws_access_key_id, :aws_secret_access_key, :region, :plugins
8
8
 
9
9
  def initialize(config = {})
10
10
  @aws_access_key_id = config[:aws_access_key_id]
11
11
  @aws_secret_access_key = config[:aws_secret_access_key]
12
- @region = config[:region]
12
+ @region = config[:region] || 'us-east-1'
13
+ @plugins = config[:plugins] || default_plugins
13
14
  end
14
15
 
15
16
  def run
@@ -20,11 +21,14 @@ module Nephelae
20
21
  #make one request to put a cloud watch metric for nephelae being up. hopefully this can make it bork early if anything is wrong
21
22
  cloud.put_metric(NephelaeProcess.new.get_metrics)
22
23
 
23
- plugins = [DiskSpace.new, MemUsage.new, NephelaeProcess.new, PassengerStatus.new, RedisStatus.new]
24
24
  scheduler = Rufus::Scheduler::EmScheduler.start_new
25
25
 
26
- scheduler.every '5m' do
27
- plugins.each do |p|
26
+ plugins.each do |name, config|
27
+ schedule = config.delete(:schedule) || '5m'
28
+ klass_name = config.delete(:plugin_class)
29
+ klass = Object.const_get('Nephelae').const_get(klass_name)
30
+ p = klass.new(config)
31
+ scheduler.every schedule do
28
32
  begin
29
33
  cloud.put_metric(p.get_metrics)
30
34
  rescue StandardError => e
@@ -33,8 +37,17 @@ module Nephelae
33
37
  end
34
38
  end
35
39
  end
40
+
36
41
  }
37
42
  end
38
43
 
44
+ private
45
+ def default_plugins
46
+ plugins = {}
47
+ plugins[:disk_space] = {plugin_class: "DiskSpace", schedule: "5m", path: '/'}
48
+ plugins[:mem_usage] = {plugin_class: "MemUsage", schedule: "5m"}
49
+ plugins
50
+ end
51
+
39
52
  end
40
53
  end
@@ -1,3 +1,3 @@
1
1
  module Nephelae
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nephelae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-24 00:00:00.000000000 Z
12
+ date: 2012-08-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon
@@ -115,6 +115,7 @@ files:
115
115
  - lib/nephelae/plugins/mem_usage.rb
116
116
  - lib/nephelae/plugins/nephelae_process.rb
117
117
  - lib/nephelae/plugins/passenger_status.rb
118
+ - lib/nephelae/plugins/plugin.rb
118
119
  - lib/nephelae/plugins/redis.rb
119
120
  - lib/nephelae/runner.rb
120
121
  - lib/nephelae/version.rb