healthety 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +55 -14
- data/lib/healthety/healthety.rb +6 -0
- data/lib/healthety/version.rb +1 -1
- data/spec/unit/healthety_spec.rb +24 -4
- metadata +3 -31
data/README.md
CHANGED
@@ -4,24 +4,65 @@ The Ruby Worker sends JSON wrapped data via UDP packets to a given server at a d
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
```
|
8
|
+
$ gem install healthety
|
9
|
+
```
|
8
10
|
|
9
11
|
## Usage
|
10
12
|
|
11
|
-
|
13
|
+
``` ruby
|
14
|
+
require "healthety"
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
Healthety.workers do
|
17
|
+
server "127.0.0.1"
|
18
|
+
port 41234
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
worker :load_average do
|
21
|
+
interval 0.5
|
22
|
+
# Gets load average with a system call (Mac OS X)
|
23
|
+
value `w | head -n1 | cut -f4 -d":" | cut -f2 -d" "`.to_f
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
worker :random do
|
27
|
+
interval 2
|
28
|
+
value rand(10)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
### Defining helpers
|
34
|
+
|
35
|
+
If you want to define some helper methods create a new module first. Note the `helpers` method at the end to include your module into the workers. In this case a new file called `connection_helper.rb` contains the MySQL connection handling.
|
36
|
+
|
37
|
+
``` ruby
|
38
|
+
require "mysql2"
|
39
|
+
|
40
|
+
module Healthety
|
41
|
+
module ConnectionHelper
|
42
|
+
def mysql
|
43
|
+
@client ||= Mysql2::Client.new(:host => "localhost", :username => "root")
|
27
44
|
end
|
45
|
+
end
|
46
|
+
|
47
|
+
helpers ConnectionHelper
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
In your workers you can now use the helper method. Since the MySQL connection gets saved into a class instance variable the connection gets established only once.
|
52
|
+
|
53
|
+
``` ruby
|
54
|
+
$:.unshift File.dirname(__FILE__)
|
55
|
+
|
56
|
+
require "healthety"
|
57
|
+
require "connection_helper"
|
58
|
+
|
59
|
+
Healthety.workers do
|
60
|
+
server "127.0.0.1"
|
61
|
+
port 41234
|
62
|
+
|
63
|
+
worker :user_count do
|
64
|
+
interval 5
|
65
|
+
value mysql.query("SELECT COUNT(*) AS count FROM users").first["count"]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
data/lib/healthety/healthety.rb
CHANGED
@@ -22,6 +22,12 @@ module Healthety
|
|
22
22
|
@workers << Worker.new(name, &block)
|
23
23
|
end
|
24
24
|
|
25
|
+
# Makes the methods defined in the helper modules given in `extensions`
|
26
|
+
# available to the workers.
|
27
|
+
def helpers(*extensions)
|
28
|
+
Worker.class_eval { include(*extensions) } if extensions.any?
|
29
|
+
end
|
30
|
+
|
25
31
|
def start
|
26
32
|
puts message
|
27
33
|
transmission = Transmission.new(@server, @port)
|
data/lib/healthety/version.rb
CHANGED
data/spec/unit/healthety_spec.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
module Healthety
|
4
|
+
module TestHelper
|
5
|
+
def test; end
|
6
|
+
end
|
7
|
+
|
4
8
|
describe Healthety do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
UDPSocket.any_instance.stubs(:send)
|
9
|
+
$stdout = StringIO.new
|
10
|
+
Thread.any_instance.stubs(:join)
|
11
|
+
UDPSocket.any_instance.stubs(:send)
|
9
12
|
|
13
|
+
it "should start" do
|
10
14
|
expect do
|
11
15
|
Healthety.workers do
|
12
16
|
server "127.0.0.1"
|
@@ -19,5 +23,21 @@ module Healthety
|
|
19
23
|
end
|
20
24
|
end.to be_true
|
21
25
|
end
|
26
|
+
|
27
|
+
it "should inclde helpers" do
|
28
|
+
Healthety.helpers TestHelper
|
29
|
+
|
30
|
+
expect do
|
31
|
+
Healthety.workers do
|
32
|
+
server "127.0.0.1"
|
33
|
+
port 41234
|
34
|
+
|
35
|
+
worker :test do
|
36
|
+
interval 0.5
|
37
|
+
value test
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end.to be_true
|
41
|
+
end
|
22
42
|
end
|
23
43
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: healthety
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 0.0.4
|
5
|
+
version: 0.0.5
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Martin Jagusch
|
@@ -15,8 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-04-
|
19
|
-
default_executable:
|
13
|
+
date: 2011-04-28 00:00:00 Z
|
20
14
|
dependencies:
|
21
15
|
- !ruby/object:Gem::Dependency
|
22
16
|
name: json
|
@@ -26,11 +20,6 @@ dependencies:
|
|
26
20
|
requirements:
|
27
21
|
- - ~>
|
28
22
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 1
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 5
|
33
|
-
- 1
|
34
23
|
version: 1.5.1
|
35
24
|
type: :runtime
|
36
25
|
version_requirements: *id001
|
@@ -42,11 +31,6 @@ dependencies:
|
|
42
31
|
requirements:
|
43
32
|
- - ~>
|
44
33
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 27
|
46
|
-
segments:
|
47
|
-
- 2
|
48
|
-
- 5
|
49
|
-
- 0
|
50
34
|
version: 2.5.0
|
51
35
|
type: :development
|
52
36
|
version_requirements: *id002
|
@@ -58,11 +42,6 @@ dependencies:
|
|
58
42
|
requirements:
|
59
43
|
- - ~>
|
60
44
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 35
|
62
|
-
segments:
|
63
|
-
- 0
|
64
|
-
- 9
|
65
|
-
- 12
|
66
45
|
version: 0.9.12
|
67
46
|
type: :development
|
68
47
|
version_requirements: *id003
|
@@ -89,7 +68,6 @@ files:
|
|
89
68
|
- spec/unit/healthety_spec.rb
|
90
69
|
- spec/unit/transmission_spec.rb
|
91
70
|
- spec/unit/worker_spec.rb
|
92
|
-
has_rdoc: true
|
93
71
|
homepage: http://github.com/healthety/ruby_worker
|
94
72
|
licenses: []
|
95
73
|
|
@@ -103,23 +81,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
81
|
requirements:
|
104
82
|
- - ">="
|
105
83
|
- !ruby/object:Gem::Version
|
106
|
-
hash: 3
|
107
|
-
segments:
|
108
|
-
- 0
|
109
84
|
version: "0"
|
110
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
86
|
none: false
|
112
87
|
requirements:
|
113
88
|
- - ">="
|
114
89
|
- !ruby/object:Gem::Version
|
115
|
-
hash: 3
|
116
|
-
segments:
|
117
|
-
- 0
|
118
90
|
version: "0"
|
119
91
|
requirements: []
|
120
92
|
|
121
93
|
rubyforge_project:
|
122
|
-
rubygems_version: 1.
|
94
|
+
rubygems_version: 1.7.2
|
123
95
|
signing_key:
|
124
96
|
specification_version: 3
|
125
97
|
summary: The Ruby Worker sends JSON data via UDP packets to a given host.
|