Skip to content

Commit

Permalink
Merge branch 'v2'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/pimon/stats_collector.rb
  • Loading branch information
pedrocarrico committed Sep 17, 2015
2 parents c8f9bd6 + e81b63b commit 68cb4ba
Show file tree
Hide file tree
Showing 42 changed files with 1,204 additions and 598 deletions.
14 changes: 14 additions & 0 deletions .rubocop.yml
@@ -0,0 +1,14 @@
AbcSize:
Enabled: false

Documentation:
Enabled: false

LineLength:
Max: 120

MethodLength:
Max: 15

SpaceAfterControlKeyword:
Enabled: true
1 change: 1 addition & 0 deletions .ruby-version
@@ -0,0 +1 @@
2.1.2
15 changes: 13 additions & 2 deletions .travis.yml
@@ -1,7 +1,18 @@
language: ruby
rvm:
- 1.9.3
- 2.1.2
script: "bundle exec rspec spec"

matrix:
allow_failures:
- rvm: jruby-19mode
- rvm: rbx-2
- rvm: jruby-head

before_install:
- gem update --system
- gem install bundler -v 1.8.2
install: 'bundle'
script: 'bundle exec rspec && bundle exec rubocop'
notifications:
email:
- pedro.carrico@gmail.com
25 changes: 20 additions & 5 deletions Gemfile.lock
@@ -1,16 +1,19 @@
PATH
remote: .
specs:
pimon (0.1.11)
pimon (0.2.0)
faye-websocket (= 0.10.0)
haml (= 4.0.6)
haml (= 4.0.7)
sinatra (= 1.4.6)
sys-uptime (= 0.6.2)
thin (= 1.6.3)

GEM
remote: https://rubygems.org/
specs:
ast (2.1.0)
astrolabe (1.3.1)
parser (~> 2.2)
coderay (1.1.0)
coveralls (0.8.2)
json (~> 1.8)
Expand All @@ -23,19 +26,22 @@ GEM
docile (1.1.5)
domain_name (0.5.24)
unf (>= 0.0.5, < 1.0.0)
eventmachine (1.0.7)
eventmachine (1.0.8)
faye-websocket (0.10.0)
eventmachine (>= 0.12.0)
websocket-driver (>= 0.5.1)
ffi (1.9.10)
haml (4.0.6)
haml (4.0.7)
tilt
http-cookie (1.0.2)
domain_name (~> 0.5)
json (1.8.3)
method_source (0.8.2)
mime-types (2.6.1)
netrc (0.10.3)
parser (2.2.2.6)
ast (>= 1.1, < 3.0)
powerpack (0.1.1)
pry (0.10.0)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
Expand All @@ -45,6 +51,7 @@ GEM
rack
rack-test (0.6.2)
rack (>= 1.0)
rainbow (2.0.0)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
Expand All @@ -61,6 +68,13 @@ GEM
rspec-mocks (3.0.2)
rspec-support (~> 3.0.0)
rspec-support (3.0.2)
rubocop (0.33.0)
astrolabe (~> 1.3)
parser (>= 2.2.2.5, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.7.5)
simplecov (0.10.0)
docile (~> 1.1.0)
json (~> 1.8)
Expand Down Expand Up @@ -98,9 +112,10 @@ PLATFORMS
DEPENDENCIES
coveralls (= 0.8.2)
pimon!
pry (>= 0.10.0)
pry (= 0.10.0)
rack-test (= 0.6.2)
rspec (= 3.0.0)
rubocop (= 0.33.0)
simplecov (= 0.10.0)
simplecov-rcov (= 0.2.3)
timecop (= 0.7.1)
15 changes: 3 additions & 12 deletions README.md
Expand Up @@ -2,10 +2,11 @@

[![Build Status](https://secure.travis-ci.org/pedrocarrico/pimon.png)](http://travis-ci.org/pedrocarrico/pimon) [![Dependency Status](https://gemnasium.com/pedrocarrico/pimon.png?travis)](https://gemnasium.com/pedrocarrico/pimon) [![Gem Version](https://badge.fury.io/rb/pimon.png)](http://badge.fury.io/rb/pimon) [![Code Climate](https://codeclimate.com/github/pedrocarrico/pimon.png)](https://codeclimate.com/github/pedrocarrico/pimon) [![Coverage Status](https://coveralls.io/repos/pedrocarrico/pimon/badge.png?branch=master)](https://coveralls.io/r/pedrocarrico/pimon)

![Pimon](http://pedrocarrico.net/pimon.jpg "Pimon")
![Pimon](http://pedrocarrico.net/pimonv2.png "Pimon")

## Description
Pimon is a simple server monitor designed for the Raspberry Pi.
Currently it only works with the Raspberry Pi 1 (256MB and 512MB versions).

## What do I need to get it to work?
1. Clone this repo: git clone git://github.com/pedrocarrico/pimon.git
Expand All @@ -17,10 +18,6 @@ Optionally you may install it as a gem and run it, please check "Installing as a
## Configuration
Configuration is done through a YAML file, you may check some examples on the config directory.

1. chart - colors for each chart
2. hostname - optional hostname to show on the chart subtitle, defaults to `hostname` if not set
3. stats_collector - configure number of stats and time period between them

## Installing as a gem
```
gem install pimon
Expand Down Expand Up @@ -56,13 +53,7 @@ To use them you must first compile them using _make_ and then include the bin di
in your $PATH to have them available when you run the sinatra application.
The temperature stat is available with the latest Raspbian and Arch Linux distros on your Raspberry Pi and will
(may) not work if you're developing on other systems.
Pimon only works with Ruby 1.9+.

## TODO
1. Improve disk stats, have a way of having custom mount points
2. Change configuration in realtime
3. Cpu frequency probe
4. Persist stats
Pimon only works with Ruby 2.0+.

## Copyright
Licensed under the [WTFPL](http://en.wikipedia.org/wiki/WTFPL "Do What The Fuck You Want To Public License") license.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -7,7 +7,7 @@ namespace :coverage do
desc 'run rspec code coverage'
task :spec do
ENV['COVERAGE'] = 'on'
FileUtils.rm_r 'coverage', :force => true
FileUtils.rm_r 'coverage', force: true
Rake::Task[:spec].execute
end
end
24 changes: 12 additions & 12 deletions bin/pimon
Expand Up @@ -46,15 +46,15 @@ Options:

opts.on('-v',
'--version',
'Display Pimon version') do |pid_file|
'Display Pimon version') do |_|
ARGV[0] = 'version'
end
end

begin
option_parser.parse!
if ARGV.empty?
puts "error: you must supply an action"
puts 'error: you must supply an action'
puts option_parser.help
exit 1
end
Expand All @@ -71,35 +71,35 @@ begin
ENV['PIMON_CONFIG'] = options[:pimon_config] if options[:pimon_config]
puts "Pimon is starting at http://#{interface}:#{port}"
puts "Running in #{ENV['RACK_ENV']} mode."

if ENV['PIMON_CONFIG']
puts "Using configuration file #{ENV['PIMON_CONFIG']}"
else
puts 'Using default configuration'
end

server_options = {
:config => config,
:daemonize => options[:daemonize],
:pid => pid_file,
:Port => port,
:server => 'thin',
:Host => interface
config: config,
daemonize: options[:daemonize],
pid: pid_file,
Port: port,
server: 'thin',
Host: interface
}

server = Rack::Server.new(server_options)
server.start
when 'stop'
if File.file?(pid_file)
pid = File.read(pid_file).to_i
Process.kill("KILL", pid)
File.delete(pid_file) if File.exists?(pid_file)
Process.kill('KILL', pid)
File.delete(pid_file) if File.exist?(pid_file)
puts 'Pimon stopped...'
else
puts "Pid file not found at #{pid_file}, please supply a valid pid_file using -p or --pid"
end
when 'version'
puts "Pimon version is #{Gem::Specification::load("#{File.dirname(__FILE__)}/../pimon.gemspec").version}"
puts "Pimon version is #{Gem::Specification.load("#{File.dirname(__FILE__)}/../pimon.gemspec").version}"
else
STDERR.puts option_parser
end
Expand Down
9 changes: 8 additions & 1 deletion config/config.ru
@@ -1,5 +1,12 @@
if ENV['RACK_ENV'] == 'development'
require 'rubygems'
require 'bundler'

Bundler.require
end

require_relative '../lib/pimon'

$PROGRAM_NAME = 'pimon'

run Pimon
run Pimon::App
20 changes: 7 additions & 13 deletions config/default.yml
@@ -1,14 +1,8 @@
chart:
cpu:
color: '#D2691E'
disk:
color: '#CDC673'
mem:
color: '#87CEFA'
temp:
color: '#FF9B04'
swap:
color: '#3CB371'
colors:
cpu: '#D2691E'
disk: '#CDC673'
mem: '#87CEFA'
temp: '#FF9B04'
swap: '#3CB371'
stats_collector:
number_of_stats: 6
time_period_in_secs: 30
time_period_in_secs: 10
18 changes: 6 additions & 12 deletions config/test.yml
@@ -1,15 +1,9 @@
chart:
cpu:
color: '#D2691E'
disk:
color: '#CDC673'
mem:
color: '#87CEFA'
temp:
color: '#FF9B04'
swap:
color: '#3CB371'
colors:
cpu: '#D2691E'
disk: '#CDC673'
mem: '#87CEFA'
temp: '#FF9B04'
swap: '#3CB371'
hostname: 'test_hostname'
stats_collector:
number_of_stats: 6
time_period_in_min: 10
1 change: 0 additions & 1 deletion config/test_broken.yml
Expand Up @@ -8,5 +8,4 @@ chart:
swap:
color: '#3CB371'
stats_collector:
number_of_stats: 6
time_period_in_min: 10
66 changes: 2 additions & 64 deletions lib/pimon.rb
@@ -1,66 +1,4 @@
require 'eventmachine'
require 'json'
require 'haml'
require 'sinatra'
require 'faye/websocket'
require 'pimon/app'

Faye::WebSocket.load_adapter('thin')

require_relative 'pimon/pimon_config'
require_relative 'pimon/stats_collector'

class Pimon < Sinatra::Base
set :public_folder, "#{File.dirname(__FILE__)}/pimon/public"
set :views, "#{File.dirname(__FILE__)}/pimon/views"
set :sockets, []

configure :development, :production do
filename = "#{File.dirname(__FILE__)}/../config/default.yml"
config = PimonConfig.create_new(ENV['PIMON_CONFIG'] || filename)

EventMachine::next_tick do
settings.timer = EventMachine::add_periodic_timer(config.stats[:time_period_in_secs]) do
settings.stats_checker.collect_stats
@stats = settings.stats_checker.show_stats
settings.sockets.each{ |s| s.send(@stats) }
end
end

set :config, config
set :stats_checker, StatsCollector.new(config)
set :timer, nil

settings.stats_checker.collect_stats
end

configure :test do
config = PimonConfig.create_new("#{File.dirname(__FILE__)}/../config/test.yml")

set :config, config
set :stats_checker, StatsCollector.new(config)
set :timer, nil
end

get '/' do
if Faye::WebSocket.websocket?(request.env)
ws = Faye::WebSocket.new(request.env)

ws.on(:open) do
settings.sockets << ws
@stats ||= settings.stats_checker.show_stats
ws.send(@stats)
end

ws.on(:close) do
settings.sockets.delete(ws)
end

ws.rack_response
else
last_update = settings.stats_checker.last_update
last_modified(last_update) if ENV['RACK_ENV'] != 'development' && last_update

haml :index
end
end
module Pimon
end

0 comments on commit 68cb4ba

Please sign in to comment.