pimon 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,35 +10,38 @@ It uses redis lists to keep the latest observed statistics and also uses
10
10
  highcharts to display some nice charts on your web browser.
11
11
 
12
12
  ## What do I need to get it to work?
13
- 1. Install redis an configure it to run on a socket on /tmp/redis.sock
14
- 2. bundle
15
- 3. bin/pimon start # run the sinatra app
16
- 4. go to http://localhost:3000 and PROFIT!
13
+ 1. Clone this repo: git clone git://github.com/pedrocarrico/pimon.git
14
+ 2. Install redis an configure it to run on a socket on /tmp/redis.sock
15
+ 3. bundle
16
+ 4. bin/pimon start # run the sinatra app
17
+ 5. go to http://localhost:3000 and PROFIT!
17
18
  Optionally you may install it as a gem and run it, please check "Installing as a gem" further down.
18
19
 
19
20
  ## Configuration
21
+ Configuration is done through a YAML file, you may check some examples on the config directory.
22
+
20
23
  1. basic_auth - enable or disable, configure username and password
21
24
  2. redis - location of the redis socket
22
25
  3. chart - colors for each chart
23
26
  4. queues - redis list names for the series in the charts
24
- 5. stats - configure number of stats and time period between them
27
+ 5. stats_collector - configure number of stats and time period between them
25
28
 
26
- ## Deployment
27
- To deploy on your raspberry pi you just have to have ssh enabled and your keys authorized.
28
- Then you can deploy with capistrano using:
29
+ ## Installing as a gem
29
30
  ```
30
- cap deploy:setup
31
- cap deploy:cold
31
+ gem install pimon
32
32
  ```
33
-
34
- This will setup your raspberry pi and deploy the application.
35
- The username and password for the basic_auth in the production environment will be asked in the
36
- first deploy.
37
- To start and stop the application you have the usual:
33
+ After installation just do _pimon start_ and go to http://localhost:3000 and check your stats.
34
+ If you want you may run Pimon with other options:
38
35
  ```
39
- cap deploy:start
40
- cap deploy:stop
36
+ Usage: pimon start|stop [options]
37
+ Options:
38
+ -c, --config CONFIG YAML configuration file for pimon
39
+ -d, --daemonize Run Pimon daemonized in the background
40
+ -e, --environment ENVIRONMENT Application environment (default: "development", options: "development", "production")
41
+ -p, --port PORT Port to use (default: 3000)
42
+ -P, --pid PIDFILE File to store PID (default: /tmp/pimon.pid)
41
43
  ```
44
+ (This will only work on your Raspberry Pi and perhaps some other linux distros, check the quirks section for more info).
42
45
 
43
46
  ## Running tests
44
47
  To run the coverage suite:
@@ -47,13 +50,6 @@ rake coverage:spec
47
50
  ```
48
51
  Results will be in coverage/index.html directory.
49
52
 
50
- ## Installing as a gem
51
- ```
52
- gem install pimon
53
- ```
54
- After installation just do _pimon start_ and go to http://localhost:3000 and check your stats
55
- (This will only work on your Raspberry Pi and perhaps some other linux distros, check the quirks section for more info).
56
-
57
53
  ## Quirks
58
54
  Pimon uses _vmstat_ and _free_ to collect it's stats from the operating system and these are only
59
55
  available on operating systems that have the /proc filesystem.
@@ -64,14 +60,32 @@ To use them you must first compile them using _make_ and then include the bin di
64
60
  in your $PATH to have them available when you run the sinatra application.
65
61
  The temperature stat is only available with the latest Raspbian distro (2012-09-18) on your Raspberry Pi and will (may)
66
62
  not work if you're developing on other systems.
63
+ Pimon only works with Ruby 1.9+, please refer to [my blog](http://blog.pedrocarrico.net/post/29478085586/compiling-and-installing-ruby-on-the-raspberry-pi-using "Compiling and installing ruby on the raspberry pi using rbenv…") for a way to install Ruby 1.9.3 on your Raspberry Pi.
64
+
65
+ ## Deployment with capistrano
66
+ To deploy on your raspberry pi you just have to have ssh enabled and your keys authorized.
67
+ Then you can deploy with capistrano using:
68
+ ```
69
+ cap deploy:setup
70
+ cap deploy:cold
71
+ ```
72
+
73
+ This will setup your raspberry pi and deploy the application.
74
+ The username and password for the basic_auth in the production environment will be asked in the
75
+ first deploy.
76
+ To start and stop the application you have the usual:
77
+ ```
78
+ cap deploy:start
79
+ cap deploy:stop
80
+ ```
81
+ I would recommend installing as a gem and tweak your own configuration file instead of deploying with capistrano as
82
+ this feature will probably be discontinued in the future.
67
83
 
68
84
  ## TODO
69
85
  1. Improve disk stats, have a way of having custom mount points
70
86
  2. Capistrano task to reset production basic_auth username and password
71
87
  3. Show uptime
72
88
  4. Change configuration in realtime
73
- 5. Daemonize if running in production through bin/pimon (usefull for production environments without deploying through
74
- capistrano)
75
89
 
76
90
  ## Copyright
77
91
  Licensed under the [WTFPL](http://en.wikipedia.org/wiki/WTFPL "Do What The Fuck You Want To Public License") license.
data/bin/pimon CHANGED
@@ -1,19 +1,79 @@
1
1
  #!/usr/bin/env ruby
2
- action = ARGV[0]
3
- environment = ARGV[1]
2
+ require 'optparse'
4
3
 
5
- case action
6
- when "start"
7
- require 'rack'
4
+ options = {}
5
+ option_parser = OptionParser.new do |opts|
6
+ executable_name = File.basename($PROGRAM_NAME)
7
+ opts.banner = "Usage: #{executable_name} start|stop [options]
8
+ Options:
9
+ "
10
+ opts.on('-c CONFIG',
11
+ '--config CONFIG',
12
+ 'YAML configuration file for pimon') do |config|
13
+ options[:pimon_config] = config
14
+ end
15
+
16
+ opts.on('-d',
17
+ '--daemonize',
18
+ 'Run Pimon daemonized in the background') do
19
+ options[:daemonize] = true
20
+ end
21
+
22
+ opts.on('-e ENVIRONMENT',
23
+ '--environment ENVIRONMENT',
24
+ 'Application environment (default: "development", options: "development", "production")',
25
+ /^development|production$/) do |environment|
26
+ options[:environment] = environment
27
+ end
28
+
29
+ opts.on('-p PORT',
30
+ '--port PORT',
31
+ 'Port to use (default: 3000)') do |port|
32
+ options[:port] = port
33
+ end
34
+
35
+ opts.on('-P PIDFILE',
36
+ '--pid PIDFILE',
37
+ 'File to store PID (default: /tmp/pimon.pid)') do |pid_file|
38
+ options[:pid_file] = pid_file
39
+ end
40
+ end
8
41
 
9
- puts 'Pimon is starting at http://localhost:3000'
10
- config = "#{File.dirname(__FILE__)}/../config/config.ru"
42
+ begin
43
+ option_parser.parse!
44
+ if ARGV.empty?
45
+ puts "error: you must supply an action"
46
+ puts option_parser.help
47
+ exit 1
48
+ end
11
49
 
12
- ARGV[1] ? ENV['RACK_ENV'] = environment : ENV['RACK_ENV'] = 'development'
50
+ pid_file = options[:pid_file] || '/tmp/pimon.pid'
13
51
 
14
- puts "Running in #{ENV['RACK_ENV']} mode."
15
- server = Rack::Server.new(:config => config, :Port => 3000, :server => 'thin')
16
- server.start
17
- else
18
- puts "Usage: pimon start <environment>"
52
+ case ARGV[0]
53
+ when 'start'
54
+ require 'thin'
55
+ port = options[:port] || 3000
56
+ options[:environment] ? ENV['RACK_ENV'] = options[:environment] : ENV['RACK_ENV'] = 'development'
57
+ config = "#{File.dirname(__FILE__)}/../config/config.ru"
58
+ ENV['PIMON_CONFIG'] = options[:pimon_config] if options[:pimon_config]
59
+
60
+ puts "Pimon is starting at http://localhost:#{port}"
61
+ puts "Running in #{ENV['RACK_ENV']} mode."
62
+ puts "Using configuration file #{ENV['PIMON_CONFIG']}" if ENV['PIMON_CONFIG']
63
+ server = Rack::Server.new(:config => config, :daemonize => options[:daemonize], :pid => pid_file, :Port => port, :server => 'thin')
64
+ server.start
65
+ when 'stop'
66
+ if File.file?(pid_file)
67
+ pid = `cat #{pid_file}`.to_i
68
+ Process.kill("KILL", pid)
69
+ puts 'Pimon stopped...'
70
+ else
71
+ puts "Pid file not found at #{pid_file}, please supply a valid pid_file using -p or --pid"
72
+ end
73
+ else
74
+ STDERR.puts option_parser
75
+ end
76
+ rescue OptionParser::InvalidArgument => ex
77
+ STDERR.puts ex.message
78
+ STDERR.puts option_parser
19
79
  end
data/lib/pimon.rb CHANGED
@@ -24,12 +24,13 @@ class Pimon < Sinatra::Base
24
24
 
25
25
  configure :development, :production do
26
26
  require 'redis'
27
-
28
- config = PimonConfig.create_new(ENV['RACK_ENV'])
27
+ filename = "#{File.dirname(__FILE__)}/../config/#{ ENV['RACK_ENV'] || 'development' }.yml"
28
+ config = PimonConfig.create_new(ENV['PIMON_CONFIG'] || filename)
29
29
 
30
30
  EventMachine::next_tick do
31
31
  settings.timer = EventMachine::add_periodic_timer(config.stats[:time_period_in_min] * 60) do
32
32
  settings.stats_checker.collect_stats
33
+ @o = settings.stats_checker.show_stats
33
34
  end
34
35
  end
35
36
 
@@ -43,7 +44,7 @@ class Pimon < Sinatra::Base
43
44
  configure :test do
44
45
  require 'mock_redis'
45
46
 
46
- config = PimonConfig.create_new('test')
47
+ config = PimonConfig.create_new("#{File.dirname(__FILE__)}/../config/test.yml")
47
48
 
48
49
  set :config, config
49
50
  set :stats_checker, StatsCollector.new(config, MockRedis.new)
@@ -56,7 +57,7 @@ class Pimon < Sinatra::Base
56
57
  last_update = settings.stats_checker.last_update
57
58
  last_modified(last_update) if ENV['RACK_ENV'] != 'development' && last_update
58
59
 
59
- @o = settings.stats_checker.show_stats
60
+ @o ||= settings.stats_checker.show_stats
60
61
 
61
62
  haml :index
62
63
  end
@@ -2,8 +2,8 @@ require 'pimon/hash_extensions'
2
2
  require 'yaml'
3
3
 
4
4
  class PimonConfig
5
- def self.create_new(environment = nil)
6
- config = self.new(environment)
5
+ def self.create_new(filename)
6
+ config = self.new(filename)
7
7
 
8
8
  return config if config.valid?
9
9
  end
@@ -20,10 +20,6 @@ class PimonConfig
20
20
  @config[:chart]
21
21
  end
22
22
 
23
- def environment
24
- @config[:environment]
25
- end
26
-
27
23
  def is_basic_auth_enabled?
28
24
  @config[:basic_auth][:enabled]
29
25
  end
@@ -48,11 +44,9 @@ class PimonConfig
48
44
 
49
45
  private
50
46
 
51
- def initialize(environment)
47
+ def initialize(filename)
52
48
  begin
53
- filename = "#{File.dirname(__FILE__)}/../../config/#{ environment || 'development' }.yml"
54
49
  @config = YAML.load_file(filename).symbolize_keys
55
- @config.merge!({ :environment => "#{ environment || 'development'}"})
56
50
  @config.freeze
57
51
  rescue Exception => e
58
52
  puts "Error while loading config file: #{filename}"
data/lib/pimon/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pimon
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/pimon.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = [ 'Pedro Carriço' ]
10
10
  s.email = [ 'pedro.carrico@gmail.com' ]
11
- s.homepage = 'https://github.com/pedrocarrico/pimon'
11
+ s.homepage = 'http://pimon.pedrocarrico.net/'
12
12
  s.summary = 'Pimon - Raspberry Pi server monitor'
13
13
  s.description = 'Pimon is a simple server monitor designed for the Raspberry Pi. It uses redis lists to keep the latest observed statistics and also uses highcharts to display some nice charts on your web browser.'
14
14
 
@@ -1,19 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'PimonConfig' do
4
- context 'when created with no arguments' do
5
- subject { PimonConfig.create_new }
6
-
7
- its(:environment) { should == 'development' }
8
- end
9
-
10
4
  context 'when created for the test environment' do
11
- subject { PimonConfig.create_new('test') }
5
+ subject { PimonConfig.create_new("#{File.dirname(__FILE__)}/../config/test.yml") }
12
6
 
13
7
  its(:basic_auth) { should == ['pimon', 'pimon'] }
14
8
  its(:chart) { should == { :cpu => { :color => '#D2691E' }, :disk => { :color => '#CDC673' }, :mem => { :color => '#87CEFA' }, :temp => {:color=>"#FF9B04"}, :swap => { :color => '#3CB371' } } }
15
9
  its(:is_basic_auth_enabled?) { should be_true }
16
- its(:environment) { should == 'test' }
17
10
  its(:queues) { should == { :time => 'pimon_time', :cpu => 'pimon_cpu', :disk => 'pimon_disk', :mem => 'pimon_mem', :temp => 'pimon_temp', :swap => 'pimon_swap' } }
18
11
  its(:redis) { should == { :socket => '/thou/shalt/not/use/redis/on/test/environment' } }
19
12
  its(:stats) { should == { :number_of_stats => 6, :time_period_in_min => 10 } }
@@ -28,7 +21,7 @@ describe 'PimonConfig' do
28
21
 
29
22
  context 'when created with a broken environment configuration with basic_auth enabled but no username/password' do
30
23
  it 'should raise an error' do
31
- expect{ PimonConfig.create_new('test_broken') }.to raise_error(RuntimeError)
24
+ expect{ PimonConfig.create_new("#{File.dirname(__FILE__)}/../config/test_broken.yml") }.to raise_error(RuntimeError)
32
25
  end
33
26
  end
34
27
  end
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  describe 'StatsCollector' do
6
6
  context 'when new with a valid config and redis' do
7
7
  before do
8
- @stats_collector = StatsCollector.new(PimonConfig.create_new('test'), MockRedis.new)
8
+ @stats_collector = StatsCollector.new(PimonConfig.create_new("#{File.dirname(__FILE__)}/../config/test.yml"), MockRedis.new)
9
9
  end
10
10
  subject { @stats_collector }
11
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pimon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-09-30 00:00:00.000000000 Z
12
+ date: 2012-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -240,7 +240,7 @@ files:
240
240
  - spec/pimon_spec.rb
241
241
  - spec/spec_helper.rb
242
242
  - spec/stats_collector_spec.rb
243
- homepage: https://github.com/pedrocarrico/pimon
243
+ homepage: http://pimon.pedrocarrico.net/
244
244
  licenses: []
245
245
  post_install_message:
246
246
  rdoc_options: []