rrd-ffi 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/CHANGELOG.rdoc +14 -3
- data/README.rdoc +40 -4
- data/Rakefile +10 -1
- data/lib/rrd.rb +1 -1
- data/lib/rrd/base.rb +9 -2
- data/lib/rrd/graph.rb +1 -1
- data/lib/rrd/version.rb +1 -1
- data/lib/rrd/wrapper.rb +72 -33
- data/rrd-ffi.gemspec +2 -2
- data/spec/rrd/base_spec.rb +9 -3
- data/spec/rrd/builder_spec.rb +1 -1
- data/spec/rrd/graph_spec.rb +5 -3
- data/spec/rrd/wrapper_spec.rb +64 -5
- data/spec/rrd_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- metadata +2 -2
data/.gitignore
CHANGED
data/CHANGELOG.rdoc
CHANGED
@@ -1,15 +1,26 @@
|
|
1
1
|
= Changelog
|
2
2
|
|
3
|
-
==
|
3
|
+
== TODO: version 0.2.2
|
4
|
+
|
5
|
+
* TODO: bang methods to base
|
6
|
+
* TODO: Improve documentation
|
7
|
+
* TODO: add more rrd functions (dump, tune, xport, resize)
|
8
|
+
|
9
|
+
== 2010-03-01 version 0.2.1
|
10
|
+
|
11
|
+
* Added bang methods to wrapper
|
12
|
+
* Added error method to wrapper
|
13
|
+
|
14
|
+
== 2010-02-25 version 0.2.0
|
4
15
|
|
5
16
|
* Fixed error message to be cleared before every call to wrapper. It was causing problems when doing a valid call after an invalid one
|
6
17
|
* Added advanced DSL for graphic building
|
7
18
|
* Added DSL for creating RRD file
|
8
19
|
* Added to RRD::Base methods create, update, fetch, info
|
20
|
+
* Released
|
9
21
|
|
10
|
-
== 2010-02-24
|
22
|
+
== 2010-02-24 version 0.1.0
|
11
23
|
|
12
|
-
* Released version 0.1.0
|
13
24
|
* Basic DSL for graphic building
|
14
25
|
* Added to RRD::Base methods first, last, restore
|
15
26
|
* Added bindings to librrd through RRD::Wrapper - create, update, fetch, info, first, last, restore, graph
|
data/README.rdoc
CHANGED
@@ -4,7 +4,9 @@ rrd-ffi is a gem for using rrd actions in your ruby code.
|
|
4
4
|
|
5
5
|
You may use it in the raw format, as many rrd libs in languages like perl or python, or you can use it through the dsl we provide.
|
6
6
|
|
7
|
-
rrd-ffi uses ffi to wrap the librrd C bindings, not system calls
|
7
|
+
rrd-ffi uses ffi to wrap the librrd C bindings, not system calls.
|
8
|
+
|
9
|
+
IMPORTANT: You need librrd installed in your system for this gem to work
|
8
10
|
|
9
11
|
= Basics
|
10
12
|
|
@@ -12,11 +14,13 @@ Here's what you need to know before starting.
|
|
12
14
|
|
13
15
|
== Installation
|
14
16
|
|
17
|
+
=== Notes
|
18
|
+
|
15
19
|
To install rrd-ffi, you will need to have librrd in your system.
|
16
20
|
|
17
21
|
Then, run <tt>sudo gem install rrd-ffi</tt>
|
18
22
|
|
19
|
-
If you are using Mac Ports you will have problems, so add the following to your .profile
|
23
|
+
If you are using Mac Ports you will have problems, so add the following to your .profile|.bashrc|.bash_profile file:
|
20
24
|
|
21
25
|
export RRD_LIB=/opt/local/lib/librrd.dylib
|
22
26
|
|
@@ -26,11 +30,19 @@ or
|
|
26
30
|
|
27
31
|
If you are not using MAC OS and still have problems, export the RRD_PATH variable with the path to your librrd file.
|
28
32
|
|
33
|
+
=== Installing librrd
|
34
|
+
|
35
|
+
Debian/Ubuntu: <tt>apt-get install librrd-dev</tt>
|
36
|
+
|
37
|
+
Fedora/Red Hat: <tt>yum install rrdtool-devel</tt>
|
38
|
+
|
39
|
+
Mac: <tt>port install rrdtool</tt>
|
40
|
+
|
29
41
|
== Example Usage
|
30
42
|
require "rrd"
|
31
43
|
rrd = RRD::Base.new("myrrd.rrd")
|
32
44
|
# Restoring a rrd file from xml
|
33
|
-
rrd.restore("myrrd.xml")
|
45
|
+
rrd.restore("myrrd.xml", :overwrite => true)
|
34
46
|
|
35
47
|
# Fetching data from rrd
|
36
48
|
rrd.fetch(:average).each {|line| puts line.inspect}
|
@@ -45,6 +57,10 @@ If you are not using MAC OS and still have problems, export the RRD_PATH variabl
|
|
45
57
|
puts rrd.starts_at
|
46
58
|
puts rrd.ends_at
|
47
59
|
|
60
|
+
# Error handling
|
61
|
+
rrd.fetch(:unknown_function) # should return false
|
62
|
+
puts rrd.error
|
63
|
+
|
48
64
|
=== DSLs
|
49
65
|
|
50
66
|
# Creating a new rrd
|
@@ -74,11 +90,31 @@ If you are not using MAC OS and still have problems, export the RRD_PATH variabl
|
|
74
90
|
|
75
91
|
== Raw API Usage
|
76
92
|
|
93
|
+
Normal methods return false on error, or the expected result otherwise.
|
94
|
+
|
95
|
+
Bang methods raise exception on error.
|
96
|
+
|
97
|
+
# Restoring a rrd file from xml
|
98
|
+
RRD::Wrapper.restore "myrrd.xml", "myrrd.rrd"
|
99
|
+
|
77
100
|
# Creating a rrd file
|
78
101
|
RRD::Wrapper.create "myrrd.rrd", "--step", "300", "DS:ifOutOctets:COUNTER:1800:0:4294967295", "RRA:AVERAGE:0.5:1:2016"
|
79
102
|
|
80
103
|
# Updating rrd with a new value
|
81
104
|
RRD::Wrapper.update "myrrd.rrd", "N:500000000"
|
82
105
|
|
106
|
+
# Fetching average data
|
107
|
+
RRD::Wrapper.fetch "myrrd.rrd", "AVERAGE"
|
108
|
+
|
109
|
+
# Looking for the first and last entered dates
|
110
|
+
RRD::Wrapper.first "myrrd.rrd"
|
111
|
+
RRD::Wrapper.last "myrrd.rrd"
|
112
|
+
|
83
113
|
# Creating a graph
|
84
|
-
RRD::Wrapper.graph("graph.png", "DEF:data=myrrd.rrd:ifOutOctets:AVERAGE", "LINE1:data#0000FF:Output bytes")
|
114
|
+
RRD::Wrapper.graph("graph.png", "DEF:data=myrrd.rrd:ifOutOctets:AVERAGE", "LINE1:data#0000FF:Output bytes")
|
115
|
+
|
116
|
+
# Getting the error happened
|
117
|
+
puts RRD::Wrapper.error
|
118
|
+
|
119
|
+
# Throwing the error if happens
|
120
|
+
RRD::Wrapper.fetch! "myrrd.rrd", "WRONG FUNCTION"
|
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
2
|
+
|
1
3
|
require "rake"
|
2
4
|
require "spec/rake/spectask"
|
3
|
-
require "
|
5
|
+
require "rrd/version"
|
4
6
|
|
5
7
|
begin
|
6
8
|
require "hanna/rdoctask"
|
@@ -32,6 +34,13 @@ Spec::Rake::SpecTask.new(:spec) do |t|
|
|
32
34
|
t.spec_files = FileList['spec/**/*_spec.rb']
|
33
35
|
end
|
34
36
|
|
37
|
+
desc "Rspec : run all with RCov"
|
38
|
+
Spec::Rake::SpecTask.new('spec:rcov') do |t|
|
39
|
+
t.spec_files = FileList['spec/**/*.rb']
|
40
|
+
t.rcov = true
|
41
|
+
t.rcov_opts = ['--exclude', 'gems', '--exclude', 'spec']
|
42
|
+
end
|
43
|
+
|
35
44
|
Rake::RDocTask.new do |rdoc|
|
36
45
|
rdoc.main = "README.rdoc"
|
37
46
|
rdoc.rdoc_dir = "doc"
|
data/lib/rrd.rb
CHANGED
data/lib/rrd/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module RRD
|
2
|
+
# TODO: add bang methods
|
2
3
|
class Base
|
3
4
|
attr_accessor :rrd_file
|
4
5
|
|
@@ -6,6 +7,10 @@ module RRD
|
|
6
7
|
@rrd_file = rrd_file
|
7
8
|
end
|
8
9
|
|
10
|
+
def error
|
11
|
+
Wrapper.error
|
12
|
+
end
|
13
|
+
|
9
14
|
def create(options = {}, &block)
|
10
15
|
builder = RRD::Builder.new(rrd_file, options)
|
11
16
|
builder.instance_eval(&block)
|
@@ -52,8 +57,10 @@ module RRD
|
|
52
57
|
alias :last :ends_at
|
53
58
|
|
54
59
|
# See RRD::Wrapper.restore
|
55
|
-
def restore(xml_file)
|
56
|
-
|
60
|
+
def restore(xml_file, options = {})
|
61
|
+
line_params = []
|
62
|
+
line_params << "--force-overwrite" if options[:overwrite]
|
63
|
+
Wrapper.restore(xml_file, rrd_file, *line_params)
|
57
64
|
end
|
58
65
|
|
59
66
|
end
|
data/lib/rrd/graph.rb
CHANGED
@@ -8,7 +8,7 @@ module RRD
|
|
8
8
|
def initialize(output, parameters = {})
|
9
9
|
@output = output
|
10
10
|
|
11
|
-
@parameters = {:start => Time.now - 1.day, :end => Time.now, :title => ""}
|
11
|
+
@parameters = {:start => Time.now - 1.day, :end => Time.now, :title => ""}.merge parameters
|
12
12
|
@parameters[:start] = @parameters[:start].to_i
|
13
13
|
@parameters[:end] = @parameters[:end].to_i
|
14
14
|
|
data/lib/rrd/version.rb
CHANGED
data/lib/rrd/wrapper.rb
CHANGED
@@ -4,6 +4,19 @@ module RRD
|
|
4
4
|
# See http://oss.oetiker.ch/rrdtool/doc/rrdtool.en.html for details on the parameters
|
5
5
|
class Wrapper
|
6
6
|
|
7
|
+
INFO_TYPE = { 0 => :u_val, 1 => :u_cnt, 2 => :u_str, 3 => :u_int, 4 => :u_blob}
|
8
|
+
BANG_METHODS = [:info!, :fetch!, :first!, :last!, :restore!, :graph!, :create!, :update!]
|
9
|
+
|
10
|
+
def self.detect_rrd_lib
|
11
|
+
if defined?(RRD_LIB)
|
12
|
+
RRD_LIB
|
13
|
+
elsif ENV["RRD_LIB"]
|
14
|
+
ENV["RRD_LIB"]
|
15
|
+
else
|
16
|
+
"rrd"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
class RRDBlob < FFI::Struct
|
8
21
|
layout :size, :ulong,
|
9
22
|
:ptr, :pointer
|
@@ -26,20 +39,8 @@ module RRD
|
|
26
39
|
|
27
40
|
class << self
|
28
41
|
extend FFI::Library
|
29
|
-
|
30
|
-
INFO_TYPE = { 0 => :u_val, 1 => :u_cnt, 2 => :u_str, 3 => :u_int, 4 => :u_blob}
|
31
|
-
|
32
|
-
def self.rrd_lib
|
33
|
-
if defined?(RRD_LIB)
|
34
|
-
RRD_LIB
|
35
|
-
elsif ENV["RRD_LIB"]
|
36
|
-
ENV["RRD_LIB"]
|
37
|
-
else
|
38
|
-
"rrd"
|
39
|
-
end
|
40
|
-
end
|
41
42
|
|
42
|
-
ffi_lib
|
43
|
+
ffi_lib RRD::Wrapper.detect_rrd_lib
|
43
44
|
attach_function :rrd_create, [:int, :pointer], :int
|
44
45
|
attach_function :rrd_update, [:int, :pointer], :int
|
45
46
|
attach_function :rrd_info, [:int, :pointer], :pointer
|
@@ -54,20 +55,24 @@ module RRD
|
|
54
55
|
# Set up a new Round Robin Database (RRD).
|
55
56
|
def create(*args)
|
56
57
|
argv = to_pointer(["create"] + args)
|
57
|
-
|
58
|
+
rrd_create(args.size+1, argv) == 0
|
58
59
|
true
|
59
60
|
end
|
60
61
|
|
61
62
|
# Store new data values into an RRD.
|
62
63
|
def update(*args)
|
63
64
|
argv = to_pointer(["update"] + args)
|
64
|
-
|
65
|
-
true
|
65
|
+
rrd_update(args.size+1, argv) == 0
|
66
66
|
end
|
67
67
|
|
68
68
|
# Get data for a certain time period from a RRD.
|
69
69
|
#
|
70
|
-
# Returns an array of arrays (which contains the date and values for all datasources)
|
70
|
+
# Returns an array of arrays (which contains the date and values for all datasources):
|
71
|
+
#
|
72
|
+
# [["time" , "cpu", "memory"],
|
73
|
+
# [1266933600, "0.5", "511" ],
|
74
|
+
# [1266933900, "0.9", "253" ]]
|
75
|
+
#
|
71
76
|
def fetch(*args)
|
72
77
|
#FIXME: Refactor this
|
73
78
|
start_time_ptr = empty_pointer
|
@@ -76,9 +81,9 @@ module RRD
|
|
76
81
|
ds_count_ptr = empty_pointer
|
77
82
|
ds_names_ptr = empty_pointer
|
78
83
|
|
79
|
-
|
84
|
+
values_ptr = FFI::MemoryPointer.new(:pointer)
|
80
85
|
argv = to_pointer(["fetch"] + args)
|
81
|
-
|
86
|
+
return false unless rrd_fetch(args.size+1, argv, start_time_ptr, end_time_ptr, step_ptr, ds_count_ptr, ds_names_ptr, values_ptr) == 0
|
82
87
|
|
83
88
|
ds_count = ds_count_ptr.get_int(0)
|
84
89
|
start_time = start_time_ptr.get_int(0)
|
@@ -86,14 +91,17 @@ module RRD
|
|
86
91
|
step = step_ptr.get_int(0)
|
87
92
|
|
88
93
|
result_lines = (end_time-start_time)/step
|
94
|
+
|
95
|
+
ds_names = ds_names_ptr.get_pointer(0).get_array_of_string(0, ds_count)
|
96
|
+
values = values_ptr.get_pointer(0).get_array_of_double(0, result_lines * ds_count)
|
97
|
+
|
89
98
|
result = []
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
result << data
|
99
|
+
result << ["time"] + ds_names
|
100
|
+
(0..result_lines-1).each do |line|
|
101
|
+
date = start_time + line*step
|
102
|
+
first = ds_count*line
|
103
|
+
last = ds_count*line + ds_count - 1
|
104
|
+
result << [date] + values[first..last]
|
97
105
|
end
|
98
106
|
|
99
107
|
result
|
@@ -113,6 +121,7 @@ module RRD
|
|
113
121
|
result = item[:next]
|
114
122
|
end
|
115
123
|
|
124
|
+
return false if info.empty?
|
116
125
|
info
|
117
126
|
end
|
118
127
|
|
@@ -122,7 +131,7 @@ module RRD
|
|
122
131
|
def first(*args)
|
123
132
|
argv = to_pointer(["first"] + args)
|
124
133
|
date = rrd_first(args.size+1, argv)
|
125
|
-
|
134
|
+
return false if date == -1
|
126
135
|
date
|
127
136
|
end
|
128
137
|
|
@@ -132,31 +141,61 @@ module RRD
|
|
132
141
|
def last(*args)
|
133
142
|
argv = to_pointer(["last"] + args)
|
134
143
|
date = rrd_last(args.size+1, argv)
|
135
|
-
|
144
|
+
return false if date == -1
|
136
145
|
date
|
137
146
|
end
|
138
147
|
|
139
148
|
# Restore an RRD in XML format to a binary RRD.
|
140
149
|
def restore(*args)
|
141
150
|
argv = to_pointer(["restore"] + args)
|
142
|
-
|
143
|
-
true
|
151
|
+
rrd_restore(args.size+1, argv) == 0
|
144
152
|
end
|
145
153
|
|
146
154
|
# Create a graph from data stored in one or several RRDs.
|
147
155
|
def graph(*args)
|
148
156
|
argv = to_pointer(["graph"] + args)
|
149
|
-
|
150
|
-
|
157
|
+
xsize_ptr = empty_pointer
|
158
|
+
ysize_ptr = empty_pointer
|
159
|
+
ymin_ptr = empty_pointer
|
160
|
+
ymax_ptr = empty_pointer
|
161
|
+
rrd_graph(args.size+1, argv, empty_pointer, xsize_ptr, ysize_ptr, empty_pointer, ymin_ptr, ymax_ptr) == 0
|
162
|
+
end
|
163
|
+
|
164
|
+
def error
|
165
|
+
rrd_get_error
|
166
|
+
end
|
167
|
+
|
168
|
+
def clear_error
|
169
|
+
rrd_clear_error
|
170
|
+
end
|
171
|
+
|
172
|
+
def methods
|
173
|
+
super + BANG_METHODS
|
174
|
+
end
|
175
|
+
|
176
|
+
def respond_to?(method, include_private = false)
|
177
|
+
super || BANG_METHODS.include?(method.to_sym)
|
178
|
+
end
|
179
|
+
|
180
|
+
def method_missing(method, *args)
|
181
|
+
return bang($1, *args) if method.to_s =~ /^(.+)!$/ && BANG_METHODS.include?(method.to_sym)
|
182
|
+
super
|
151
183
|
end
|
152
184
|
|
185
|
+
def bang(method, *args)
|
186
|
+
result = send(method, *args)
|
187
|
+
raise error unless result
|
188
|
+
result
|
189
|
+
end
|
190
|
+
|
153
191
|
private
|
154
192
|
def empty_pointer
|
155
193
|
FFI::MemoryPointer.new(:pointer)
|
156
194
|
end
|
157
195
|
|
196
|
+
# FIXME: remove clear_error from here
|
158
197
|
def to_pointer(array_of_strings)
|
159
|
-
|
198
|
+
clear_error
|
160
199
|
strptrs = []
|
161
200
|
array_of_strings.each {|item| strptrs << FFI::MemoryPointer.from_string(item)}
|
162
201
|
|
data/rrd-ffi.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rrd-ffi}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["morellon", "fnando", "rafaelrosafu", "dalcico"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-01}
|
13
13
|
s.description = %q{Provides bindings for many RRD functions (using ffi gem and librrd), as well as DSLs for graphic and rrd building. You must have librrd in your system!}
|
14
14
|
s.email = %q{morellon@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/rrd/base_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe RRD::Base do
|
4
4
|
|
@@ -41,8 +41,8 @@ describe RRD::Base do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should restore a rrd from xml" do
|
44
|
-
RRD::Wrapper.should_receive(:restore).with(XML_FILE, RRD_FILE).and_return(true)
|
45
|
-
@rrd.restore(XML_FILE).should be_true
|
44
|
+
RRD::Wrapper.should_receive(:restore).with(XML_FILE, RRD_FILE, "--force-overwrite").and_return(true)
|
45
|
+
@rrd.restore(XML_FILE, :overwrite => true).should be_true
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should return the starting date" do
|
@@ -55,6 +55,12 @@ describe RRD::Base do
|
|
55
55
|
@rrd.ends_at.should be_a(Time)
|
56
56
|
end
|
57
57
|
|
58
|
+
it "should return the error" do
|
59
|
+
@rrd.error.should be_empty
|
60
|
+
@rrd.restore("unknown file").should be_false
|
61
|
+
@rrd.error.should_not be_empty
|
62
|
+
end
|
63
|
+
|
58
64
|
it "should respond to first"
|
59
65
|
it "should respond to last"
|
60
66
|
end
|
data/spec/rrd/builder_spec.rb
CHANGED
data/spec/rrd/graph_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe RRD::Graph do
|
4
4
|
|
5
5
|
before do
|
6
6
|
RRD::Base.new(RRD_FILE).restore(XML_FILE)
|
7
|
-
@graph = RRD::Graph.new IMG_FILE
|
7
|
+
@graph = RRD::Graph.new IMG_FILE, :title => "Title", :width => 800, :height => 200
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should store definition for rrd data" do
|
@@ -58,8 +58,10 @@ describe RRD::Graph do
|
|
58
58
|
@graph.line RRD_FILE, :memory => :average, :color => "#0000FF", :label => "Memory Avg"
|
59
59
|
RRD::Wrapper.should_receive(:graph).with(IMG_FILE,
|
60
60
|
"--end", anything(),
|
61
|
+
"--height", "200",
|
61
62
|
"--start", anything(),
|
62
|
-
"--title", "",
|
63
|
+
"--title", "Title",
|
64
|
+
"--width", "800",
|
63
65
|
"DEF:memory_average=#{RRD_FILE}:memory:AVERAGE",
|
64
66
|
"LINE1:memory_average#0000FF:Memory Avg").and_return true
|
65
67
|
@graph.save
|
data/spec/rrd/wrapper_spec.rb
CHANGED
@@ -1,8 +1,31 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe RRD::Wrapper do
|
4
4
|
|
5
|
+
context "when looking for librrd path" do
|
6
|
+
before :each do
|
7
|
+
Object.send(:remove_const, :RRD_LIB) if defined?(::RRD_LIB)
|
8
|
+
ENV["RRD_LIB"] = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should look on RRD_LIB constant first" do
|
12
|
+
::RRD_LIB = "first"
|
13
|
+
ENV["RRD_LIB"] = "second"
|
14
|
+
RRD::Wrapper.detect_rrd_lib.should == "first"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should look on ENV if RRD_LIB is not defined" do
|
18
|
+
ENV["RRD_LIB"] = "second"
|
19
|
+
RRD::Wrapper.detect_rrd_lib.should == "second"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return 'rrd' for FFI to look up if can't use RRD_LIB or ENV" do
|
23
|
+
RRD::Wrapper.detect_rrd_lib.should == "rrd"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
5
27
|
context "when no rrd file exists" do
|
28
|
+
|
6
29
|
it "should restore a rrd from xml" do
|
7
30
|
RRD::Wrapper.restore(XML_FILE, RRD_FILE).should be_true
|
8
31
|
end
|
@@ -27,9 +50,11 @@ describe RRD::Wrapper do
|
|
27
50
|
|
28
51
|
it "should fetch values" do
|
29
52
|
values = RRD::Wrapper.fetch(RRD_FILE, "AVERAGE", "--start", "1266933600", "--end", "1267020000")
|
30
|
-
values.should have(
|
31
|
-
values[0][0].should ==
|
32
|
-
values[
|
53
|
+
values.should have(26).lines
|
54
|
+
values[0][0].should == "time"
|
55
|
+
values[1][0].should == 1266933600
|
56
|
+
values[1][1].should == 0.0008
|
57
|
+
values.last[0].should == 1267020000
|
33
58
|
end
|
34
59
|
|
35
60
|
it "should return info data about this file" do
|
@@ -46,9 +71,43 @@ describe RRD::Wrapper do
|
|
46
71
|
end
|
47
72
|
|
48
73
|
it "should create a graph correctly" do
|
49
|
-
RRD::Wrapper.graph(IMG_FILE, "DEF:data=#{RRD_FILE}:memory:AVERAGE", "LINE1:data#0000FF:Memory Avg")
|
74
|
+
RRD::Wrapper.graph(IMG_FILE, "--width", "1000", "--height", "300", "DEF:data=#{RRD_FILE}:memory:AVERAGE", "LINE1:data#0000FF:Memory Avg")
|
50
75
|
File.should be_file(IMG_FILE)
|
51
76
|
end
|
77
|
+
|
78
|
+
it "should return the error correctly, cleaning the error var" do
|
79
|
+
RRD::Wrapper.error.should be_empty
|
80
|
+
RRD::Wrapper.fetch("error").should be_false
|
81
|
+
RRD::Wrapper.error.should_not be_empty
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when using bang methods" do
|
86
|
+
|
87
|
+
it "should respond to them" do
|
88
|
+
RRD::Wrapper::BANG_METHODS.each do |method|
|
89
|
+
RRD::Wrapper.respond_to?(method).should be_true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should list them" do
|
94
|
+
(RRD::Wrapper.methods & RRD::Wrapper::BANG_METHODS).should == RRD::Wrapper::BANG_METHODS
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return the normal method result" do
|
98
|
+
RRD::Wrapper.restore!(XML_FILE, RRD_FILE).should be_true
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should raise error if the normal method is not bangable" do
|
102
|
+
RRD::Wrapper.should_not_receive(:bang)
|
103
|
+
lambda{RRD::Wrapper.not_bangable}.should raise_error(NoMethodError)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should raise error if the normal method result is false" do
|
107
|
+
RRD::Wrapper.should_receive(:info).and_return(false)
|
108
|
+
RRD::Wrapper.should_receive(:error).and_return("error message")
|
109
|
+
lambda{RRD::Wrapper.bang(:info)}.should raise_error("error message")
|
110
|
+
end
|
52
111
|
end
|
53
112
|
|
54
113
|
end
|
data/spec/rrd_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -3,9 +3,11 @@ require "spec"
|
|
3
3
|
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
|
4
4
|
require "rrd"
|
5
5
|
|
6
|
+
$VERBOSE = nil
|
6
7
|
RRD_FILE = File.expand_path(File.dirname(__FILE__) + "/vm.rrd")
|
7
8
|
IMG_FILE = File.expand_path(File.dirname(__FILE__) + "/vm.png")
|
8
9
|
XML_FILE = File.expand_path(File.dirname(__FILE__) + "/vm.xml")
|
10
|
+
$VERBOSE = false
|
9
11
|
|
10
12
|
Spec::Runner.configure do |config|
|
11
13
|
config.append_before :each do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rrd-ffi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- morellon
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2010-
|
15
|
+
date: 2010-03-01 00:00:00 -03:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|