gesund 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +37 -2
- data/lib/gesund/cli.rb +7 -5
- data/lib/gesund/dsl.rb +8 -2
- data/lib/gesund/output/rack.rb +26 -0
- data/lib/gesund/output/text.rb +2 -1
- data/lib/gesund/output.rb +1 -0
- data/lib/gesund/version.rb +1 -1
- data/lib/gesund.rb +0 -1
- data/spec/lib/gesund/version_spec.rb +1 -1
- metadata +5 -6
- data/lib/gesund/output/test.rb +0 -8
- data/lib/gesund/rack_application.rb +0 -14
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Gesund
|
2
2
|
|
3
|
-
|
3
|
+
To have healthy servers, it is important to have an automated check that can tell you if something is wrong. Gesund for the rescue!
|
4
|
+
|
5
|
+
Gesund is a simple health checker that provides ready classes to do various checks against running services, filesystem state and more. Currently the ```gesund``` gem itself only has a small number of file system checks, and several additional gems provide checks for redis, mysql, mongodb and http.
|
6
|
+
|
7
|
+
This project is early alpha - you are welcome to help out and make it shine.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
@@ -18,7 +22,38 @@ Or install it yourself as:
|
|
18
22
|
|
19
23
|
## Usage
|
20
24
|
|
21
|
-
|
25
|
+
First create a ```Gesundfile``` that will list the required checks, for example:
|
26
|
+
|
27
|
+
require "gesund/redis"
|
28
|
+
require "gesund/mysql"
|
29
|
+
require "gesund/mongo"
|
30
|
+
require "gesund/http"
|
31
|
+
|
32
|
+
check :file, "/tmp/testfile"
|
33
|
+
check :link, "/tmp/testlink"
|
34
|
+
check :directory, "/tmp"
|
35
|
+
check :redis_connection
|
36
|
+
check :mysql_connection
|
37
|
+
check :mongo_connection
|
38
|
+
check :http_status, url: "http://www.google.com/"
|
39
|
+
|
40
|
+
# vi: set ft=ruby ai ts=2 sw=2 et sts=2
|
41
|
+
|
42
|
+
Then you can either run it on the command line, or start a Rack server that will answer to requests with the results of the required checks.
|
43
|
+
|
44
|
+
Running on the command line -
|
45
|
+
|
46
|
+
$ gesund
|
47
|
+
200: File /tmp/testfile is a file
|
48
|
+
200: Symbolic link /tmp/testlink is a symlink
|
49
|
+
200: Directory /tmp is a directory
|
50
|
+
200: Redis PING = PONG
|
51
|
+
500: Mysql::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
|
52
|
+
200: Mongo PING = OK
|
53
|
+
500: HTTP GET request to http://www.google.com/ status is 302
|
54
|
+
|
55
|
+
RESULT: Health check failed!
|
56
|
+
|
22
57
|
|
23
58
|
## Contributing
|
24
59
|
|
data/lib/gesund/cli.rb
CHANGED
@@ -3,19 +3,21 @@ require "thor"
|
|
3
3
|
module Gesund
|
4
4
|
class CLI < ::Thor
|
5
5
|
include ::Thor::Actions
|
6
|
+
class_option :gesundfile, :banner => '<gesundfile>', :type => :string, :default => "Gesundfile", :aliases => [:"-c"]
|
6
7
|
|
7
8
|
default_task :check
|
8
9
|
desc "check", "Executes the list of checks found in Gesundfile"
|
9
|
-
option :gesundfile, :type => :string, :default => "Gesundfile"
|
10
10
|
def check
|
11
|
-
|
12
|
-
checks = Gesund::Dsl.evaluate(
|
13
|
-
Gesund::Output::Text.new
|
11
|
+
gesundfile = File.expand_path(options[:gesundfile]) if options[:gesundfile]
|
12
|
+
checks = Gesund::Dsl.evaluate(gesundfile)
|
13
|
+
Gesund::Output::Text.new(checks)
|
14
14
|
end
|
15
15
|
|
16
16
|
desc "http", "Starts a web server that answers to requests with results of checks from Gesundfile"
|
17
17
|
def http
|
18
|
-
|
18
|
+
gesundfile = File.expand_path(options[:gesundfile]) if options[:gesundfile]
|
19
|
+
checks = Gesund::Dsl.evaluate(gesundfile)
|
20
|
+
Gesund::Output::Rack.start(checks)
|
19
21
|
end
|
20
22
|
|
21
23
|
end
|
data/lib/gesund/dsl.rb
CHANGED
@@ -7,7 +7,12 @@ class Gesund::Dsl
|
|
7
7
|
|
8
8
|
def eval_gesundfile(gesundfile)
|
9
9
|
@checks = []
|
10
|
-
|
10
|
+
begin
|
11
|
+
contents = File.read(gesundfile.to_s)
|
12
|
+
rescue => e
|
13
|
+
puts "ERROR reading Gesundfile: #{e.message}"
|
14
|
+
exit 1
|
15
|
+
end
|
11
16
|
instance_eval(contents, gesundfile.to_s, 1)
|
12
17
|
return @checks
|
13
18
|
end
|
@@ -18,7 +23,8 @@ class Gesund::Dsl
|
|
18
23
|
check_class = Gesund::Checks.const_get(camel_name)
|
19
24
|
rescue NameError => e
|
20
25
|
e.backtrace.join =~ /Gesundfile:(\d+)/
|
21
|
-
|
26
|
+
print "ERROR Gesundfile:#{$1}: "
|
27
|
+
puts "#{e.message}"
|
22
28
|
exit 1
|
23
29
|
end
|
24
30
|
raise Gesund::Errors::CheckNotFound unless check_class
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "rack"
|
2
|
+
|
3
|
+
module Gesund::Output
|
4
|
+
class Rack
|
5
|
+
def self.start(checks)
|
6
|
+
app = self.new
|
7
|
+
app.checks = checks
|
8
|
+
::Rack::Server.start app: app
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :checks
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
results = Gesund::CheckRunner.run(self.checks)
|
15
|
+
body = []
|
16
|
+
failflag = false
|
17
|
+
results.each do |check|
|
18
|
+
failflag = true if check.first.to_i != 200
|
19
|
+
body << "#{check.first}: #{check.last.join}\n"
|
20
|
+
end
|
21
|
+
status = failflag ? 500 : 200
|
22
|
+
header = { "Content-Type" => "text/plain" }
|
23
|
+
[status, header, body]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/gesund/output/text.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Gesund::Output
|
2
2
|
class Text
|
3
3
|
def initialize(checks)
|
4
|
+
results = Gesund::CheckRunner.run(checks)
|
4
5
|
failflag = false
|
5
|
-
|
6
|
+
results.each do |check|
|
6
7
|
failflag = true if check.first.to_i != 200
|
7
8
|
puts "#{check.first}: #{check.last.join}"
|
8
9
|
end
|
data/lib/gesund/output.rb
CHANGED
data/lib/gesund/version.rb
CHANGED
data/lib/gesund.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gesund
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.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: 2013-05-
|
12
|
+
date: 2013-05-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -120,9 +120,8 @@ files:
|
|
120
120
|
- lib/gesund/dsl.rb
|
121
121
|
- lib/gesund/errors.rb
|
122
122
|
- lib/gesund/output.rb
|
123
|
-
- lib/gesund/output/
|
123
|
+
- lib/gesund/output/rack.rb
|
124
124
|
- lib/gesund/output/text.rb
|
125
|
-
- lib/gesund/rack_application.rb
|
126
125
|
- lib/gesund/version.rb
|
127
126
|
- spec/lib/gesund/check_spec.rb
|
128
127
|
- spec/lib/gesund/checks/directory_spec.rb
|
@@ -145,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
144
|
version: '0'
|
146
145
|
segments:
|
147
146
|
- 0
|
148
|
-
hash:
|
147
|
+
hash: -1461887031316332670
|
149
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
149
|
none: false
|
151
150
|
requirements:
|
@@ -154,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
153
|
version: '0'
|
155
154
|
segments:
|
156
155
|
- 0
|
157
|
-
hash:
|
156
|
+
hash: -1461887031316332670
|
158
157
|
requirements: []
|
159
158
|
rubyforge_project:
|
160
159
|
rubygems_version: 1.8.25
|
data/lib/gesund/output/test.rb
DELETED