json2graphite 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/json2graphite.rb +11 -6
- metadata +3 -3
data/lib/json2graphite.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
module Json2Graphite
|
3
3
|
module_function
|
4
4
|
|
5
|
+
# DOCUMENT THIS!!!
|
5
6
|
def walk_the_forrest (obj=self, path=[], &blk)
|
6
7
|
obj.each do |key,value|
|
7
8
|
case value
|
@@ -13,18 +14,22 @@ module Json2Graphite
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
#
|
17
|
-
|
17
|
+
# Converts a hash of hashes into dot notaion used by graphite targets and
|
18
|
+
# outputs to STDOUT. Takes optional time argument, defaulting to now.
|
19
|
+
|
20
|
+
def to_graphite (hash, time=Time.now.to_i)
|
21
|
+
raise "Hash was not received" unless hash.is_a? Hash
|
18
22
|
walk_the_forrest(hash) {|target, value|
|
19
|
-
puts "#{target} #{value} #{
|
23
|
+
puts "#{target} #{value} #{time}"
|
20
24
|
}
|
21
25
|
end
|
22
26
|
|
23
|
-
# Return an array, each
|
24
|
-
def get_graphite (hash,
|
27
|
+
# Return an array of hashes, each hash a single graphite target, value, and time
|
28
|
+
def get_graphite (hash, time=Time.now.to_i)
|
29
|
+
raise "Hash was not received" unless hash.is_a? Hash
|
25
30
|
data = []
|
26
31
|
walk_the_forrest(hash) {|target, value|
|
27
|
-
data <<
|
32
|
+
data << { :target => target, :value => value, :time => time }
|
28
33
|
}
|
29
34
|
data
|
30
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json2graphite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
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-08-
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
60
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.8.
|
61
|
+
rubygems_version: 1.8.23
|
62
62
|
signing_key:
|
63
63
|
specification_version: 3
|
64
64
|
summary: Convert json hash tree to graphite format
|