slurry 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/slurry +8 -1
- data/etc/slurry.yaml.sample +2 -0
- data/lib/slurry/graphite.rb +31 -0
- data/lib/slurry.rb +19 -29
- metadata +3 -2
data/bin/slurry
CHANGED
@@ -17,7 +17,7 @@ OptionParser.new do |opts|
|
|
17
17
|
options[:configfile] = conf
|
18
18
|
end
|
19
19
|
|
20
|
-
opts.on("-t", "--type [clean|report]", "The type of run to perform") do |t|
|
20
|
+
opts.on("-t", "--type [clean|report|runonce|post]", "The type of run to perform") do |t|
|
21
21
|
options[:type] = t
|
22
22
|
end
|
23
23
|
|
@@ -52,6 +52,13 @@ def run(options)
|
|
52
52
|
config = loadconf(configfile)
|
53
53
|
report = JSON.parse(Slurry.runonce(config[:server],config[:port]))
|
54
54
|
puts report.to_json
|
55
|
+
when "post"
|
56
|
+
config = loadconf(configfile)
|
57
|
+
if config[:post]
|
58
|
+
Slurry.post(config[:post])
|
59
|
+
else
|
60
|
+
raise("you need a :post secton in your config file before you use this runtype")
|
61
|
+
end
|
55
62
|
else # Load json data from stdin
|
56
63
|
Slurry.funnel
|
57
64
|
end
|
data/etc/slurry.yaml.sample
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Slurry
|
2
|
+
# Handles connection details to the graphite server.
|
3
|
+
class Graphite
|
4
|
+
|
5
|
+
# Opens a socket with the specified graphite server.
|
6
|
+
#
|
7
|
+
# @param [String] server
|
8
|
+
# @param [String] port
|
9
|
+
def initialize(server,port)
|
10
|
+
@server, @port = server, port
|
11
|
+
@s = TCPSocket.open(server,port)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Puts the graphite formatted string into the open socket.
|
15
|
+
#
|
16
|
+
# @param [String] target the graphite formatted target in dotted notion
|
17
|
+
# @param [String] value the value of the target
|
18
|
+
# @param [String] time the time that the sample was taken
|
19
|
+
def send (target,value,time)
|
20
|
+
line = [target,value,time].join(" ")
|
21
|
+
@s.puts(line)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Close the open socket to the graphite server.
|
25
|
+
def close
|
26
|
+
@s.close
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/lib/slurry.rb
CHANGED
@@ -1,41 +1,16 @@
|
|
1
|
+
require 'slurry/graphite'
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require "redis"
|
3
5
|
require 'json2graphite'
|
6
|
+
require 'net/http'
|
7
|
+
require 'rest_client'
|
4
8
|
|
5
9
|
# @author Zach Leslie <zach@puppetlabs.com>
|
6
10
|
#
|
7
11
|
module Slurry
|
8
12
|
module_function
|
9
13
|
|
10
|
-
# Handles connection details to the graphite server.
|
11
|
-
class Graphite
|
12
|
-
|
13
|
-
# Opens a socket with the specified graphite server.
|
14
|
-
#
|
15
|
-
# @param [String] server
|
16
|
-
# @param [String] port
|
17
|
-
def initialize(server,port)
|
18
|
-
@server, @port = server, port
|
19
|
-
@s = TCPSocket.open(server,port)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Puts the graphite formatted string into the open socket.
|
23
|
-
#
|
24
|
-
# @param [String] target the graphite formatted target in dotted notion
|
25
|
-
# @param [String] value the value of the target
|
26
|
-
# @param [String] time the time that the sample was taken
|
27
|
-
def send (target,value,time)
|
28
|
-
line = [target,value,time].join(" ")
|
29
|
-
@s.puts(line)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Close the open socket to the graphite server.
|
33
|
-
def close
|
34
|
-
@s.close
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
14
|
|
40
15
|
# Wraps received hash in new hash with timestamp applied.
|
41
16
|
#
|
@@ -65,6 +40,21 @@ module Slurry
|
|
65
40
|
pipe(timestamp(jsondata))
|
66
41
|
end
|
67
42
|
|
43
|
+
# Post the json received on STDIN to a webserver
|
44
|
+
def post(postconfig)
|
45
|
+
body = ''
|
46
|
+
body += STDIN.read
|
47
|
+
jsondata = JSON.parse(body)
|
48
|
+
begin
|
49
|
+
raise "jsondata is not of class Hash. Is #{jsondata.class}" unless jsondata.is_a? Hash
|
50
|
+
RestClient.post(postconfig[:url], jsondata.to_json, :content_type => :json, :accept => :json )
|
51
|
+
rescue => e
|
52
|
+
puts "something broke:"
|
53
|
+
puts e.message
|
54
|
+
puts e.backtrace.inspect
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
68
58
|
# Receives a hash formatted like so
|
69
59
|
# {:time=>1345411779,
|
70
60
|
# :collectd=>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slurry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
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-
|
12
|
+
date: 2012-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- Rakefile
|
70
70
|
- bin/liaise
|
71
71
|
- bin/slurry
|
72
|
+
- lib/slurry/graphite.rb
|
72
73
|
- lib/slurry.rb
|
73
74
|
- etc/slurry.yaml.sample
|
74
75
|
- README.md
|