finch 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) chatgris <jboyer@af83.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # finch
2
+
3
+ finch is a barebone monitoring dashboard.
4
+
5
+ ## Installation
6
+
7
+ Ruby 1.9.2 is required.
8
+
9
+ Install it with rubygems:
10
+
11
+ ``` shell
12
+ gem install finch
13
+ ```
14
+
15
+ With bundler, add it to your `Gemfile`:
16
+
17
+ ``` ruby
18
+ gem "finch"
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Configure a `config.ru` file:
24
+
25
+ ``` ruby
26
+ require "finch"
27
+
28
+ Finch.declare do |declarator|
29
+ declarator.ping name: "Redis", host: "localhost", port: 6379, id: "redis"
30
+ declarator.ping name: "Mongo", host: "localhost", port: 27017, id: "mongo"
31
+ declarator.ping name: "ElasticSearch", host: "localhost", port: 9200, id: "es"
32
+ end
33
+
34
+ run Finch::App
35
+ ```
36
+
37
+ And run `rackup`, and you're done.
38
+
39
+
40
+ ## Copyright
41
+
42
+ MIT. See LICENSE for further details.
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+ require 'celluloid'
3
+ require 'net/ping/tcp'
4
+ require "sinatra/base"
5
+ require "slim"
6
+
7
+ module Finch
8
+ class App < Sinatra::Base
9
+ helpers do
10
+ def class_for_status(state)
11
+ state == :ok ? "success" : "error"
12
+ end
13
+ end
14
+ get "/" do
15
+ slim :ping, locals: {pings: settings.declarator_ids.map do |id|
16
+ Celluloid::Actor[id]
17
+ end
18
+ }
19
+ end
20
+ end
21
+
22
+ class Pinger
23
+ include Celluloid
24
+ attr_reader :timer, :host, :port
25
+ attr_accessor :last_success, :state, :name
26
+
27
+ def initialize(opts = {})
28
+ @name = opts.fetch(:name, "Unkown")
29
+ @host = opts.fetch(:host, "localhost")
30
+ @port = opts[:port]
31
+ @timer = every(opts.fetch(:frequency, 30)) { ping }
32
+ ping
33
+ end
34
+
35
+ def ping
36
+ ping_accessor.ping ? success : error
37
+ end
38
+
39
+ private
40
+
41
+ def success
42
+ self.state = :ok
43
+ self.last_success = Time.now.utc
44
+ end
45
+
46
+ def error
47
+ self.state = :ko
48
+ end
49
+
50
+ def ping_accessor
51
+ @ping_accessor ||= Net::Ping::TCP.new(host, port)
52
+ end
53
+ end
54
+
55
+ class Declator
56
+ attr_reader :ids
57
+
58
+ def initialize
59
+ @ids = []
60
+ end
61
+
62
+ def ping(opts)
63
+ ids << id = opts.delete(:id)
64
+ Pinger.supervise_as(id, opts)
65
+ end
66
+ end
67
+
68
+ def declare
69
+ yield declarator = Declator.new
70
+ App.set :declarator_ids, declarator.ids
71
+ end
72
+
73
+ module_function :declare
74
+ end
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ module Finch
3
+ VERSION = "0.0.1"
4
+ end
@@ -0,0 +1,21 @@
1
+ doctype
2
+ html
3
+ head
4
+ meta charset="utf-8"
5
+ title Pings
6
+ link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet"
7
+ body
8
+ .container
9
+ header class="jumbotron subhead" id="overview"
10
+ .container
11
+ h1 Finch
12
+ table.table.table-bordered
13
+ tr
14
+ th Name
15
+ th State
16
+ th Last success
17
+ - pings.each do |ping|
18
+ tr class="#{class_for_status(ping.state)}"
19
+ td= ping.name
20
+ td= ping.state
21
+ td= ping.last_success
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: finch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - chatgris
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: celluloid
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: net-ping
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sinatra
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: slim
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Finch provides an easy to setup dashboard for ping monitoring.
79
+ email:
80
+ - jboyer@af83.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - LICENSE
86
+ - README.md
87
+ - lib/finch.rb
88
+ - lib/finch/version.rb
89
+ - lib/views/ping.slim
90
+ homepage: https://github.com/chatgris/finch
91
+ licenses: []
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.24
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Barebone Ping dashboard
114
+ test_files: []