errand 0.7.0 → 0.7.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/README.md +9 -3
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/lib/errand.rb +26 -3
- metadata +4 -8
- data/extconf.rb +0 -30
- data/lib/graph.rb +0 -75
- data/rrd_info.h +0 -47
- data/rrdtool_main.c +0 -260
data/README.md
CHANGED
@@ -47,10 +47,16 @@ Otherwise, simply run:
|
|
47
47
|
This should build a library named `rrd.so` in the current directory. If it
|
48
48
|
doesn't, please report bugs at [http://github.com/eric/rubyrrdtool/issues](http://github.com/eric/rubyrrdtool/issues)!
|
49
49
|
|
50
|
-
Building gem
|
51
|
-
|
50
|
+
Building the gem
|
51
|
+
================
|
52
|
+
|
53
|
+
Errand is managed by Jeweller, which generates the gemspec for you:
|
54
|
+
|
55
|
+
rake gemspec
|
56
|
+
|
57
|
+
Once the gemspec is generated, build the gem:
|
52
58
|
|
53
|
-
gem build errand.gemspec
|
59
|
+
gem build errand.gemspec
|
54
60
|
|
55
61
|
Testing
|
56
62
|
=======
|
data/Rakefile
CHANGED
@@ -9,7 +9,6 @@ begin
|
|
9
9
|
gemspec.email = "lindsay@holmwood.id.au"
|
10
10
|
gemspec.homepage = "http://auxesis.github.com/errand"
|
11
11
|
gemspec.authors = ["Lindsay Holmwood"]
|
12
|
-
gemspec.extensions = ["extconf.rb"]
|
13
12
|
end
|
14
13
|
rescue LoadError
|
15
14
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.1
|
data/lib/errand.rb
CHANGED
@@ -1,13 +1,36 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# Attempt to load the native RRD library provided by the operating system.
|
4
|
+
begin
|
5
|
+
# Ruby Enterprise Edition will try to load everything from /usr/local/lib/ruby.
|
6
|
+
# As the distribution generally installs the RRD bindings in /usr/lib/ruby, we
|
7
|
+
# have to explicitly hack the load path so REE knows where to find the Ruby
|
8
|
+
# RRD bindings.
|
9
|
+
case RUBY_VERSION[/^1\.\d/]
|
10
|
+
when /^1\.8/
|
11
|
+
version = "1.8"
|
12
|
+
when /^1\.9/
|
13
|
+
version = RUBY_VERSION
|
14
|
+
end
|
15
|
+
|
16
|
+
%w(i386 i486).each do |arch|
|
17
|
+
$: << "/usr/lib/ruby/#{version}/#{arch}-linux"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'RRD'
|
21
|
+
rescue LoadError
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
# Errand:
|
26
|
+
# Wraps the RRD Ruby library provided by your distribution's package manager,
|
27
|
+
# exposing a more Ruby-like and accessible interface.
|
5
28
|
|
6
29
|
class Errand
|
7
30
|
def initialize(opts={})
|
8
31
|
raise ArgumentError unless opts[:filename]
|
9
32
|
@filename = opts[:filename]
|
10
|
-
@backend = ::
|
33
|
+
@backend = ::RRD
|
11
34
|
end
|
12
35
|
|
13
36
|
def dump(opts={})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: errand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lindsay Holmwood
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-22 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -17,8 +17,8 @@ description: Errand provides Ruby bindings for RRD functions (via librrd), and a
|
|
17
17
|
email: lindsay@holmwood.id.au
|
18
18
|
executables: []
|
19
19
|
|
20
|
-
extensions:
|
21
|
-
|
20
|
+
extensions: []
|
21
|
+
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README.md
|
24
24
|
files:
|
@@ -28,11 +28,7 @@ files:
|
|
28
28
|
- README.md
|
29
29
|
- Rakefile
|
30
30
|
- VERSION
|
31
|
-
- extconf.rb
|
32
31
|
- lib/errand.rb
|
33
|
-
- lib/graph.rb
|
34
|
-
- rrd_info.h
|
35
|
-
- rrdtool_main.c
|
36
32
|
- spec/errand_spec.rb
|
37
33
|
- spec/spec.opts
|
38
34
|
- test/test_rrdtool.rb
|
data/extconf.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# $Id: extconf.rb,v 1.4 2008/03/11 22:47:06 dbach Exp $
|
2
|
-
|
3
|
-
require 'mkmf'
|
4
|
-
|
5
|
-
# If there are build errors, be sure to say where your rrdtool lives:
|
6
|
-
#
|
7
|
-
# ruby ./extconf.rb --with-rrd-dir=/usr/local/rrdtool-1.2.12
|
8
|
-
|
9
|
-
libpaths=%w(/lib /usr/lib /usr/local/lib /sw/lib /opt/local/lib)
|
10
|
-
%w(art_lgpl_2 freetype png z).sort.reverse.each do |lib|
|
11
|
-
find_library(lib, nil, *libpaths)
|
12
|
-
end
|
13
|
-
|
14
|
-
dir_config("rrd")
|
15
|
-
# rrd_first is only defined rrdtool >= 1.2.x
|
16
|
-
have_library("rrd", "rrd_first")
|
17
|
-
|
18
|
-
# rrd_dump_r has 2nd arg in rrdtool >= 1.2.14
|
19
|
-
if try_link(<<EOF)
|
20
|
-
#include <rrd.h>
|
21
|
-
main()
|
22
|
-
{
|
23
|
-
rrd_dump_r("/dev/null", NULL);
|
24
|
-
}
|
25
|
-
EOF
|
26
|
-
$CFLAGS += " -DHAVE_RRD_DUMP_R_2"
|
27
|
-
end
|
28
|
-
|
29
|
-
create_makefile("errand_backend")
|
30
|
-
|
data/lib/graph.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ideas for a graphing DSL
|
3
|
-
#
|
4
|
-
|
5
|
-
module RRDtool
|
6
|
-
|
7
|
-
# Simple Ruby object to generate the RRD graph parameters
|
8
|
-
#
|
9
|
-
class Graph
|
10
|
-
|
11
|
-
# Graph attributes can appear in any order
|
12
|
-
attr :image_file, :image_format
|
13
|
-
attr :title
|
14
|
-
attr :vertical_label
|
15
|
-
|
16
|
-
attr :width, :height
|
17
|
-
attr :start, :duration, :step
|
18
|
-
attr :upper_limit, :lower_limit
|
19
|
-
|
20
|
-
# LATER: there are lots of other RRDtool graph attributes
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
@graph_command = []
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# The graph commands must be preserved in order
|
28
|
-
#
|
29
|
-
|
30
|
-
# Create a DEF
|
31
|
-
def fetch(name, rrd_file, value, type)
|
32
|
-
# format: DEF:name=rrd_file:value:type
|
33
|
-
@graph_command << "DEF:#{name}=#{rrd_file}:#{value}:#{type}"
|
34
|
-
end
|
35
|
-
|
36
|
-
# Create a CDEF
|
37
|
-
def compute(name, expr)
|
38
|
-
# format: CDEF:name=expr
|
39
|
-
@graph_command << "CDEF:#{name}=#{expr}"
|
40
|
-
end
|
41
|
-
|
42
|
-
# Create GPRINT
|
43
|
-
def gprint(name, type, print_expr)
|
44
|
-
# format: GPRINTF:name:type:print_expr
|
45
|
-
@graph_command << "GPRINTF:#{name}:#{type}:#{print_expr}"
|
46
|
-
end
|
47
|
-
|
48
|
-
# Create a LINE(1,2,...)
|
49
|
-
def line(name, width, color, label)
|
50
|
-
# format: LINEwidth:name#color:label
|
51
|
-
@graph_command << "LINE#{width}:#{name}##{color}:#{label}"
|
52
|
-
end
|
53
|
-
|
54
|
-
# Create a AREA
|
55
|
-
def area(name, color)
|
56
|
-
# format: AREA:name#color
|
57
|
-
@graph_command << "AREA:#{name}##{color}"
|
58
|
-
end
|
59
|
-
|
60
|
-
# Create a STACK
|
61
|
-
def stack(name, color)
|
62
|
-
# format: STACK:name#color
|
63
|
-
@graph_command << "STACK:#{name}##{color}"
|
64
|
-
end
|
65
|
-
|
66
|
-
# Turn the graph definition into a real image
|
67
|
-
def publish
|
68
|
-
# LATER: add in the graph attributes --
|
69
|
-
# i.e., turn the graph attribute hash into an array of [ '--key', 'value', ...]
|
70
|
-
RRDtool.graph @graph_command
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
data/rrd_info.h
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
/* -*- C -*-
|
2
|
-
* file: rrd_info.h
|
3
|
-
* date: $Date: 2008/03/11 22:47:06 $
|
4
|
-
* init: 2005-07-26
|
5
|
-
* vers: $Version$
|
6
|
-
* auth: $Author: dbach $
|
7
|
-
* -----
|
8
|
-
*
|
9
|
-
* Support file to add rrd_info() to rrd.h
|
10
|
-
*
|
11
|
-
*/
|
12
|
-
#ifndef __RRD_INFO_H
|
13
|
-
#define __RRD_INFO_H
|
14
|
-
|
15
|
-
#if defined(__cplusplus) || defined(c_plusplus)
|
16
|
-
extern "C" {
|
17
|
-
#endif
|
18
|
-
|
19
|
-
/* rrd info interface
|
20
|
-
enum info_type { RD_I_VAL=0,
|
21
|
-
RD_I_CNT,
|
22
|
-
RD_I_STR,
|
23
|
-
RD_I_INT };
|
24
|
-
*/
|
25
|
-
|
26
|
-
typedef union infoval {
|
27
|
-
unsigned long u_cnt;
|
28
|
-
rrd_value_t u_val;
|
29
|
-
char *u_str;
|
30
|
-
int u_int;
|
31
|
-
} infoval;
|
32
|
-
|
33
|
-
typedef struct info_t {
|
34
|
-
char *key;
|
35
|
-
rrd_info_type_t type;
|
36
|
-
union infoval value;
|
37
|
-
struct info_t *next;
|
38
|
-
} info_t;
|
39
|
-
|
40
|
-
//info_t *rrd_info(int, char **);
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
#if defined(__cplusplus) || defined(c_plusplus)
|
45
|
-
}
|
46
|
-
#endif
|
47
|
-
#endif /* __RRD_INFO_H */
|
data/rrdtool_main.c
DELETED
@@ -1,260 +0,0 @@
|
|
1
|
-
/* $Id: rrdtool_main.c,v 1.1 2008/03/11 22:47:06 dbach Exp $
|
2
|
-
* Substantial penalty for early withdrawal.
|
3
|
-
*/
|
4
|
-
|
5
|
-
#include <unistd.h>
|
6
|
-
#include <math.h> /* for isnan */
|
7
|
-
#include <ruby.h>
|
8
|
-
#include <rrd.h>
|
9
|
-
#include "rrd_info.h"
|
10
|
-
|
11
|
-
typedef struct string_arr_t {
|
12
|
-
int len;
|
13
|
-
char **strings;
|
14
|
-
} string_arr;
|
15
|
-
|
16
|
-
VALUE mRRD;
|
17
|
-
VALUE rb_eRRDError;
|
18
|
-
|
19
|
-
typedef int (*RRDFUNC)(int argc, char ** argv);
|
20
|
-
#define RRD_CHECK_ERROR \
|
21
|
-
if (rrd_test_error()) \
|
22
|
-
rb_raise(rb_eRRDError, rrd_get_error()); \
|
23
|
-
rrd_clear_error();
|
24
|
-
|
25
|
-
string_arr string_arr_new(VALUE rb_strings)
|
26
|
-
{
|
27
|
-
string_arr a;
|
28
|
-
char buf[64];
|
29
|
-
int i;
|
30
|
-
|
31
|
-
Check_Type(rb_strings, T_ARRAY);
|
32
|
-
a.len = RARRAY_LEN(rb_strings) + 1;
|
33
|
-
|
34
|
-
a.strings = malloc(a.len * sizeof(char *));
|
35
|
-
a.strings[0] = "dummy"; /* first element is a dummy element */
|
36
|
-
|
37
|
-
for (i = 0; i < a.len - 1; i++) {
|
38
|
-
VALUE v = rb_ary_entry(rb_strings, i);
|
39
|
-
switch (TYPE(v)) {
|
40
|
-
case T_STRING:
|
41
|
-
a.strings[i + 1] = strdup(STR2CSTR(v));
|
42
|
-
break;
|
43
|
-
case T_FIXNUM:
|
44
|
-
snprintf(buf, 63, "%d", FIX2INT(v));
|
45
|
-
a.strings[i + 1] = strdup(buf);
|
46
|
-
break;
|
47
|
-
default:
|
48
|
-
rb_raise(rb_eTypeError, "invalid argument - %s, expected T_STRING or T_FIXNUM on index %d", rb_class2name(CLASS_OF(v)), i);
|
49
|
-
break;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
return a;
|
54
|
-
}
|
55
|
-
|
56
|
-
void string_arr_delete(string_arr a)
|
57
|
-
{
|
58
|
-
int i;
|
59
|
-
|
60
|
-
/* skip dummy first entry */
|
61
|
-
for (i = 1; i < a.len; i++) {
|
62
|
-
free(a.strings[i]);
|
63
|
-
}
|
64
|
-
|
65
|
-
free(a.strings);
|
66
|
-
}
|
67
|
-
|
68
|
-
void reset_rrd_state()
|
69
|
-
{
|
70
|
-
optind = 0;
|
71
|
-
opterr = 0;
|
72
|
-
rrd_clear_error();
|
73
|
-
}
|
74
|
-
|
75
|
-
VALUE rrd_call(RRDFUNC func, VALUE args)
|
76
|
-
{
|
77
|
-
string_arr a;
|
78
|
-
|
79
|
-
a = string_arr_new(args);
|
80
|
-
reset_rrd_state();
|
81
|
-
func(a.len, a.strings);
|
82
|
-
string_arr_delete(a);
|
83
|
-
|
84
|
-
RRD_CHECK_ERROR
|
85
|
-
|
86
|
-
return Qnil;
|
87
|
-
}
|
88
|
-
|
89
|
-
VALUE rb_rrd_create(VALUE self, VALUE args)
|
90
|
-
{
|
91
|
-
return rrd_call(rrd_create, args);
|
92
|
-
}
|
93
|
-
|
94
|
-
VALUE rb_rrd_dump(VALUE self, VALUE args)
|
95
|
-
{
|
96
|
-
return rrd_call(rrd_dump, args);
|
97
|
-
}
|
98
|
-
|
99
|
-
VALUE rb_rrd_fetch(VALUE self, VALUE args)
|
100
|
-
{
|
101
|
-
string_arr a;
|
102
|
-
unsigned long i, j, k, step, ds_cnt;
|
103
|
-
rrd_value_t *raw_data;
|
104
|
-
char **raw_names;
|
105
|
-
VALUE data, names, result;
|
106
|
-
time_t start, end;
|
107
|
-
|
108
|
-
a = string_arr_new(args);
|
109
|
-
reset_rrd_state();
|
110
|
-
rrd_fetch(a.len, a.strings, &start, &end, &step, &ds_cnt, &raw_names, &raw_data);
|
111
|
-
string_arr_delete(a);
|
112
|
-
|
113
|
-
RRD_CHECK_ERROR
|
114
|
-
|
115
|
-
names = rb_ary_new();
|
116
|
-
for (i = 0; i < ds_cnt; i++) {
|
117
|
-
rb_ary_push(names, rb_str_new2(raw_names[i]));
|
118
|
-
free(raw_names[i]);
|
119
|
-
}
|
120
|
-
free(raw_names);
|
121
|
-
|
122
|
-
k = 0;
|
123
|
-
data = rb_ary_new();
|
124
|
-
for (i = start; i < end; i += step) {
|
125
|
-
VALUE line = rb_ary_new2(ds_cnt);
|
126
|
-
for (j = 0; j < ds_cnt; j++) {
|
127
|
-
rb_ary_store(line, j, rb_float_new(raw_data[k]));
|
128
|
-
k++;
|
129
|
-
}
|
130
|
-
rb_ary_push(data, line);
|
131
|
-
}
|
132
|
-
free(raw_data);
|
133
|
-
|
134
|
-
result = rb_ary_new2(4);
|
135
|
-
rb_ary_store(result, 0, INT2NUM(start));
|
136
|
-
rb_ary_store(result, 1, INT2NUM(end));
|
137
|
-
rb_ary_store(result, 2, names);
|
138
|
-
rb_ary_store(result, 3, data);
|
139
|
-
return result;
|
140
|
-
}
|
141
|
-
|
142
|
-
VALUE rb_rrd_graph(VALUE self, VALUE args)
|
143
|
-
{
|
144
|
-
string_arr a;
|
145
|
-
char **calcpr, **p;
|
146
|
-
VALUE result, print_results;
|
147
|
-
int xsize, ysize;
|
148
|
-
double ymin, ymax;
|
149
|
-
|
150
|
-
a = string_arr_new(args);
|
151
|
-
reset_rrd_state();
|
152
|
-
rrd_graph(a.len, a.strings, &calcpr, &xsize, &ysize, NULL, &ymin, &ymax);
|
153
|
-
string_arr_delete(a);
|
154
|
-
|
155
|
-
RRD_CHECK_ERROR
|
156
|
-
|
157
|
-
result = rb_ary_new2(3);
|
158
|
-
print_results = rb_ary_new();
|
159
|
-
p = calcpr;
|
160
|
-
for (p = calcpr; p && *p; p++) {
|
161
|
-
rb_ary_push(print_results, rb_str_new2(*p));
|
162
|
-
free(*p);
|
163
|
-
}
|
164
|
-
free(calcpr);
|
165
|
-
rb_ary_store(result, 0, print_results);
|
166
|
-
rb_ary_store(result, 1, INT2FIX(xsize));
|
167
|
-
rb_ary_store(result, 2, INT2FIX(ysize));
|
168
|
-
return result;
|
169
|
-
}
|
170
|
-
|
171
|
-
VALUE rb_rrd_info(VALUE self, VALUE args)
|
172
|
-
{
|
173
|
-
string_arr a;
|
174
|
-
info_t *p, *data;
|
175
|
-
VALUE result;
|
176
|
-
|
177
|
-
a = string_arr_new(args);
|
178
|
-
data = rrd_info(a.len, a.strings);
|
179
|
-
string_arr_delete(a);
|
180
|
-
|
181
|
-
RRD_CHECK_ERROR
|
182
|
-
|
183
|
-
result = rb_hash_new();
|
184
|
-
while (data) {
|
185
|
-
VALUE key = rb_str_new2(data->key);
|
186
|
-
switch (data->type) {
|
187
|
-
case RD_I_VAL:
|
188
|
-
if (isnan(data->value.u_val)) {
|
189
|
-
rb_hash_aset(result, key, Qnil);
|
190
|
-
}
|
191
|
-
else {
|
192
|
-
rb_hash_aset(result, key, rb_float_new(data->value.u_val));
|
193
|
-
}
|
194
|
-
break;
|
195
|
-
case RD_I_CNT:
|
196
|
-
rb_hash_aset(result, key, INT2FIX(data->value.u_cnt));
|
197
|
-
break;
|
198
|
-
case RD_I_STR:
|
199
|
-
rb_hash_aset(result, key, rb_str_new2(data->value.u_str));
|
200
|
-
free(data->value.u_str);
|
201
|
-
break;
|
202
|
-
}
|
203
|
-
p = data;
|
204
|
-
data = data->next;
|
205
|
-
free(p);
|
206
|
-
}
|
207
|
-
return result;
|
208
|
-
}
|
209
|
-
|
210
|
-
VALUE rb_rrd_last(VALUE self, VALUE args)
|
211
|
-
{
|
212
|
-
string_arr a;
|
213
|
-
time_t last;
|
214
|
-
|
215
|
-
a = string_arr_new(args);
|
216
|
-
reset_rrd_state();
|
217
|
-
last = rrd_last(a.len, a.strings);
|
218
|
-
string_arr_delete(a);
|
219
|
-
|
220
|
-
RRD_CHECK_ERROR
|
221
|
-
|
222
|
-
return rb_funcall(rb_cTime, rb_intern("at"), 1, INT2FIX(last));
|
223
|
-
}
|
224
|
-
|
225
|
-
VALUE rb_rrd_resize(VALUE self, VALUE args)
|
226
|
-
{
|
227
|
-
return rrd_call(rrd_resize, args);
|
228
|
-
}
|
229
|
-
|
230
|
-
VALUE rb_rrd_restore(VALUE self, VALUE args)
|
231
|
-
{
|
232
|
-
return rrd_call(rrd_restore, args);
|
233
|
-
}
|
234
|
-
|
235
|
-
VALUE rb_rrd_tune(VALUE self, VALUE args)
|
236
|
-
{
|
237
|
-
return rrd_call(rrd_tune, args);
|
238
|
-
}
|
239
|
-
|
240
|
-
VALUE rb_rrd_update(VALUE self, VALUE args)
|
241
|
-
{
|
242
|
-
return rrd_call(rrd_update, args);
|
243
|
-
}
|
244
|
-
|
245
|
-
void Init_errand_backend()
|
246
|
-
{
|
247
|
-
mRRD = rb_define_module("ErrandBackend");
|
248
|
-
rb_eRRDError = rb_define_class("ErrandError", rb_eStandardError);
|
249
|
-
|
250
|
-
rb_define_module_function(mRRD, "create", rb_rrd_create, -2);
|
251
|
-
rb_define_module_function(mRRD, "dump", rb_rrd_dump, -2);
|
252
|
-
rb_define_module_function(mRRD, "fetch", rb_rrd_fetch, -2);
|
253
|
-
rb_define_module_function(mRRD, "graph", rb_rrd_graph, -2);
|
254
|
-
rb_define_module_function(mRRD, "last", rb_rrd_last, -2);
|
255
|
-
rb_define_module_function(mRRD, "resize", rb_rrd_resize, -2);
|
256
|
-
rb_define_module_function(mRRD, "restore", rb_rrd_restore, -2);
|
257
|
-
rb_define_module_function(mRRD, "tune", rb_rrd_tune, -2);
|
258
|
-
rb_define_module_function(mRRD, "update", rb_rrd_update, -2);
|
259
|
-
rb_define_module_function(mRRD, "info", rb_rrd_info, -2);
|
260
|
-
}
|