librrd 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,8 +1,12 @@
1
1
  ChangeLog
2
2
  =========
3
3
 
4
+ # 0.2.0
5
+ * Add RRDtool 1.2 bindings.
6
+ * Fix build on OpenBSD.
7
+
4
8
  # 0.1.2
5
- * Fix compilation on 1.9.2 by backporting a fix from the rrdtool svn. (r2132)
9
+ * Fix compilation on 1.9.2 by backporting a fix from the RRDtool svn. (r2132)
6
10
 
7
11
  # 0.1.1
8
12
  * Remove wrong dependency from gemspec.
data/README.md CHANGED
@@ -3,24 +3,22 @@ librrd
3
3
 
4
4
  # Description
5
5
 
6
- This gem includes the [rrdtool](http://www.mrtg.org/rrdtool/) Ruby bindings.
7
- It got created because it's difficult to get the rrdtool bindings if you don't
8
- use the Ruby distribution included in your package system.
6
+ This gem includes the [RRDtool](http://www.mrtg.org/rrdtool/) Ruby bindings from
7
+ the RRDtool sources. It should help people that are unable to use or don't have
8
+ some kind of `librrd-ruby` operating system package.
9
9
 
10
10
  The `extconf.rb` tries to guess the librrd version installed on your system.
11
11
  If it doesn't work, please try to adjust the `ext/librrd/extconf.rb` file
12
12
  and submit a pull request or open an issue.
13
13
 
14
- The following systems have been tested.
14
+ The following systems, RRDtool versions and Ruby versions have been tested.
15
15
 
16
- * Ubuntu 10.04 LTS (librrd-1.3.8)
17
-
18
- The following Ruby versions have been tested with [RVM](http://rvm.beginrescueend.com/).
19
-
20
- * ruby 1.9.2p0
21
- * ruby 1.8.7p302
22
- * rubinius 1.1.0
23
- * ruby-enterpriseedition 1.8.7 2010.02
16
+ * Ubuntu 10.04 LTS (RRDtool 1.3.8)
17
+ * Ruby 1.9.2p0, 1.8.7p302
18
+ * Rubinius 1.1.0
19
+ * ruby-enterpriseedition 1.8.7 2010.02
20
+ * OpenBSD 4.8 (RRDtool 1.2.30)
21
+ * Ruby 1.9.2p0, 1.8.7p302
24
22
 
25
23
  # Installation
26
24
 
@@ -31,8 +29,9 @@ Make sure you have the development package of `librrd` installed.
31
29
 
32
30
  # Contribute
33
31
 
34
- Please test the gem on different systems and report success and/or failure.
35
- Open issues and/or submit pull requests with fixes.
32
+ Please test the gem on different systems with different RRDtool versions
33
+ and report success and/or failure. Open issues and/or submit pull
34
+ requests with fixes.
36
35
 
37
36
  Thank you!
38
37
 
@@ -42,11 +41,11 @@ Thank you!
42
41
 
43
42
  # Maintainer
44
43
 
45
- Bernd Ahlers <bernd@tuneafish.de>
44
+ Bernd Ahlers
46
45
 
47
46
  # Copyright
48
47
 
49
- Since the files have been taken from the [rrdtool](http://www.mrtg.org/rrdtool/)
48
+ Since the files have been taken from the [RRDtool](http://www.mrtg.org/rrdtool/)
50
49
  sources, all files in this project are available under the
51
50
  [GNU General Public License](http://www.gnu.org/copyleft/gpl.html). See the
52
51
  COPYING and COPYRIGHT for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -0,0 +1,259 @@
1
+ /* $Id: main.c 1212 2007-11-08 10:13:48Z oetiker $
2
+ * Substantial penalty for early withdrawal.
3
+ */
4
+
5
+ #include <unistd.h>
6
+ #include <ruby.h>
7
+ #include <rrd.h>
8
+ #include "rrd_tool.h"
9
+
10
+ typedef struct string_arr_t {
11
+ int len;
12
+ char **strings;
13
+ } string_arr;
14
+
15
+ VALUE mRRD;
16
+ VALUE rb_eRRDError;
17
+
18
+ typedef int (*RRDFUNC)(int argc, char ** argv);
19
+ #define RRD_CHECK_ERROR \
20
+ if (rrd_test_error()) \
21
+ rb_raise(rb_eRRDError, rrd_get_error()); \
22
+ rrd_clear_error();
23
+
24
+ string_arr string_arr_new(VALUE rb_strings)
25
+ {
26
+ string_arr a;
27
+ char buf[64];
28
+ int i;
29
+
30
+ Check_Type(rb_strings, T_ARRAY);
31
+ a.len = RARRAY_LEN(rb_strings) + 1;
32
+
33
+ a.strings = malloc(a.len * sizeof(char *));
34
+ a.strings[0] = "dummy"; /* first element is a dummy element */
35
+
36
+ for (i = 0; i < a.len - 1; i++) {
37
+ VALUE v = rb_ary_entry(rb_strings, i);
38
+ switch (TYPE(v)) {
39
+ case T_STRING:
40
+ a.strings[i + 1] = strdup(StringValuePtr(v));
41
+ break;
42
+ case T_FIXNUM:
43
+ snprintf(buf, 63, "%d", FIX2INT(v));
44
+ a.strings[i + 1] = strdup(buf);
45
+ break;
46
+ default:
47
+ rb_raise(rb_eTypeError, "invalid argument - %s, expected T_STRING or T_FIXNUM on index %d", rb_class2name(CLASS_OF(v)), i);
48
+ break;
49
+ }
50
+ }
51
+
52
+ return a;
53
+ }
54
+
55
+ void string_arr_delete(string_arr a)
56
+ {
57
+ int i;
58
+
59
+ /* skip dummy first entry */
60
+ for (i = 1; i < a.len; i++) {
61
+ free(a.strings[i]);
62
+ }
63
+
64
+ free(a.strings);
65
+ }
66
+
67
+ void reset_rrd_state()
68
+ {
69
+ optind = 0;
70
+ opterr = 0;
71
+ rrd_clear_error();
72
+ }
73
+
74
+ VALUE rrd_call(RRDFUNC func, VALUE args)
75
+ {
76
+ string_arr a;
77
+
78
+ a = string_arr_new(args);
79
+ reset_rrd_state();
80
+ func(a.len, a.strings);
81
+ string_arr_delete(a);
82
+
83
+ RRD_CHECK_ERROR
84
+
85
+ return Qnil;
86
+ }
87
+
88
+ VALUE rb_rrd_create(VALUE self, VALUE args)
89
+ {
90
+ return rrd_call(rrd_create, args);
91
+ }
92
+
93
+ VALUE rb_rrd_dump(VALUE self, VALUE args)
94
+ {
95
+ return rrd_call(rrd_dump, args);
96
+ }
97
+
98
+ VALUE rb_rrd_fetch(VALUE self, VALUE args)
99
+ {
100
+ string_arr a;
101
+ unsigned long i, j, k, step, ds_cnt;
102
+ rrd_value_t *raw_data;
103
+ char **raw_names;
104
+ VALUE data, names, result;
105
+ time_t start, end;
106
+
107
+ a = string_arr_new(args);
108
+ reset_rrd_state();
109
+ rrd_fetch(a.len, a.strings, &start, &end, &step, &ds_cnt, &raw_names, &raw_data);
110
+ string_arr_delete(a);
111
+
112
+ RRD_CHECK_ERROR
113
+
114
+ names = rb_ary_new();
115
+ for (i = 0; i < ds_cnt; i++) {
116
+ rb_ary_push(names, rb_str_new2(raw_names[i]));
117
+ free(raw_names[i]);
118
+ }
119
+ free(raw_names);
120
+
121
+ k = 0;
122
+ data = rb_ary_new();
123
+ for (i = start; i <= end; i += step) {
124
+ VALUE line = rb_ary_new2(ds_cnt);
125
+ for (j = 0; j < ds_cnt; j++) {
126
+ rb_ary_store(line, j, rb_float_new(raw_data[k]));
127
+ k++;
128
+ }
129
+ rb_ary_push(data, line);
130
+ }
131
+ free(raw_data);
132
+
133
+ result = rb_ary_new2(4);
134
+ rb_ary_store(result, 0, INT2NUM(start));
135
+ rb_ary_store(result, 1, INT2NUM(end));
136
+ rb_ary_store(result, 2, names);
137
+ rb_ary_store(result, 3, data);
138
+ return result;
139
+ }
140
+
141
+ VALUE rb_rrd_graph(VALUE self, VALUE args)
142
+ {
143
+ string_arr a;
144
+ char **calcpr, **p;
145
+ VALUE result, print_results;
146
+ int xsize, ysize;
147
+ double ymin, ymax;
148
+
149
+ a = string_arr_new(args);
150
+ reset_rrd_state();
151
+ rrd_graph(a.len, a.strings, &calcpr, &xsize, &ysize, NULL, &ymin, &ymax);
152
+ string_arr_delete(a);
153
+
154
+ RRD_CHECK_ERROR
155
+
156
+ result = rb_ary_new2(3);
157
+ print_results = rb_ary_new();
158
+ p = calcpr;
159
+ for (p = calcpr; p && *p; p++) {
160
+ rb_ary_push(print_results, rb_str_new2(*p));
161
+ free(*p);
162
+ }
163
+ free(calcpr);
164
+ rb_ary_store(result, 0, print_results);
165
+ rb_ary_store(result, 1, INT2FIX(xsize));
166
+ rb_ary_store(result, 2, INT2FIX(ysize));
167
+ return result;
168
+ }
169
+
170
+ VALUE rb_rrd_info(VALUE self, VALUE args)
171
+ {
172
+ string_arr a;
173
+ info_t *p, *data;
174
+ VALUE result;
175
+
176
+ a = string_arr_new(args);
177
+ data = rrd_info(a.len, a.strings);
178
+ string_arr_delete(a);
179
+
180
+ RRD_CHECK_ERROR
181
+
182
+ result = rb_hash_new();
183
+ while (data) {
184
+ VALUE key = rb_str_new2(data->key);
185
+ switch (data->type) {
186
+ case RD_I_VAL:
187
+ if (isnan(data->value.u_val)) {
188
+ rb_hash_aset(result, key, Qnil);
189
+ }
190
+ else {
191
+ rb_hash_aset(result, key, rb_float_new(data->value.u_val));
192
+ }
193
+ break;
194
+ case RD_I_CNT:
195
+ rb_hash_aset(result, key, INT2FIX(data->value.u_cnt));
196
+ break;
197
+ case RD_I_STR:
198
+ rb_hash_aset(result, key, rb_str_new2(data->value.u_str));
199
+ free(data->value.u_str);
200
+ break;
201
+ }
202
+ p = data;
203
+ data = data->next;
204
+ free(p);
205
+ }
206
+ return result;
207
+ }
208
+
209
+ VALUE rb_rrd_last(VALUE self, VALUE args)
210
+ {
211
+ string_arr a;
212
+ time_t last;
213
+
214
+ a = string_arr_new(args);
215
+ reset_rrd_state();
216
+ last = rrd_last(a.len, a.strings);
217
+ string_arr_delete(a);
218
+
219
+ RRD_CHECK_ERROR
220
+
221
+ return rb_funcall(rb_cTime, rb_intern("at"), 1, INT2FIX(last));
222
+ }
223
+
224
+ VALUE rb_rrd_resize(VALUE self, VALUE args)
225
+ {
226
+ return rrd_call(rrd_resize, args);
227
+ }
228
+
229
+ VALUE rb_rrd_restore(VALUE self, VALUE args)
230
+ {
231
+ return rrd_call(rrd_restore, args);
232
+ }
233
+
234
+ VALUE rb_rrd_tune(VALUE self, VALUE args)
235
+ {
236
+ return rrd_call(rrd_tune, args);
237
+ }
238
+
239
+ VALUE rb_rrd_update(VALUE self, VALUE args)
240
+ {
241
+ return rrd_call(rrd_update, args);
242
+ }
243
+
244
+ void Init_RRD()
245
+ {
246
+ mRRD = rb_define_module("RRD");
247
+ rb_eRRDError = rb_define_class("RRDError", rb_eStandardError);
248
+
249
+ rb_define_module_function(mRRD, "create", rb_rrd_create, -2);
250
+ rb_define_module_function(mRRD, "dump", rb_rrd_dump, -2);
251
+ rb_define_module_function(mRRD, "fetch", rb_rrd_fetch, -2);
252
+ rb_define_module_function(mRRD, "graph", rb_rrd_graph, -2);
253
+ rb_define_module_function(mRRD, "last", rb_rrd_last, -2);
254
+ rb_define_module_function(mRRD, "resize", rb_rrd_resize, -2);
255
+ rb_define_module_function(mRRD, "restore", rb_rrd_restore, -2);
256
+ rb_define_module_function(mRRD, "tune", rb_rrd_tune, -2);
257
+ rb_define_module_function(mRRD, "update", rb_rrd_update, -2);
258
+ rb_define_module_function(mRRD, "info", rb_rrd_info, -2);
259
+ }
@@ -0,0 +1,398 @@
1
+ /*****************************************************************************
2
+ * RRDtool 1.2.30 Copyright by Tobi Oetiker, 1997-2009
3
+ *****************************************************************************
4
+ * rrd_format.h RRD Database Format header
5
+ *****************************************************************************/
6
+
7
+ #ifndef _RRD_FORMAT_H
8
+ #define _RRD_FORMAT_H
9
+
10
+ #include "rrd.h"
11
+
12
+ /*****************************************************************************
13
+ * put this in your /usr/lib/magic file (/etc/magic on HPUX)
14
+ *
15
+ * # rrd database format
16
+ * 0 string RRD\0 rrd file
17
+ * >5 string >\0 version '%s'
18
+ *
19
+ *****************************************************************************/
20
+
21
+ #define RRD_COOKIE "RRD"
22
+ /* #define RRD_VERSION "0002" */
23
+ /* changed because microsecond precision requires another field */
24
+ #define RRD_VERSION "0003"
25
+ #define FLOAT_COOKIE 8.642135E130
26
+
27
+ #include "rrd_nan_inf.h"
28
+
29
+ typedef union unival {
30
+ unsigned long u_cnt;
31
+ rrd_value_t u_val;
32
+ } unival;
33
+
34
+
35
+ /****************************************************************************
36
+ * The RRD Database Structure
37
+ * ---------------------------
38
+ *
39
+ * In oder to properly describe the database structure lets define a few
40
+ * new words:
41
+ *
42
+ * ds - Data Source (ds) providing input to the database. A Data Source (ds)
43
+ * can be a traffic counter, a temperature, the number of users logged
44
+ * into a system. The rrd database format can handle the input of
45
+ * several Data Sources (ds) in a singe database.
46
+ *
47
+ * dst - Data Source Type (dst). The Data Source Type (dst) defines the rules
48
+ * applied to Build Primary Data Points from the input provided by the
49
+ * data sources (ds).
50
+ *
51
+ * pdp - Primary Data Point (pdp). After the database has accepted the
52
+ * input from the data sources (ds). It starts building Primary
53
+ * Data Points (pdp) from the data. Primary Data Points (pdp)
54
+ * are evenly spaced along the time axis (pdp_step). The values
55
+ * of the Primary Data Points are calculated from the values of
56
+ * the data source (ds) and the exact time these values were
57
+ * provided by the data source (ds).
58
+ *
59
+ * pdp_st - PDP Start (pdp_st). The moments (pdp_st) in time where
60
+ * these steps occur are defined by the moments where the
61
+ * number of seconds since 1970-jan-1 modulo pdp_step equals
62
+ * zero (pdp_st).
63
+ *
64
+ * cf - Consolidation Function (cf). An arbitrary Consolidation Function (cf)
65
+ * (averaging, min, max) is applied to the primary data points (pdp) to
66
+ * calculate the consolidated data point.
67
+ *
68
+ * cdp - Consolidated Data Point (cdp) is the long term storage format for data
69
+ * in the rrd database. Consolidated Data Points represent one or
70
+ * several primary data points collected along the time axis. The
71
+ * Consolidated Data Points (cdp) are stored in Round Robin Archives
72
+ * (rra).
73
+ *
74
+ * rra - Round Robin Archive (rra). This is the place where the
75
+ * consolidated data points (cdp) get stored. The data is
76
+ * organized in rows (row) and columns (col). The Round Robin
77
+ * Archive got its name from the method data is stored in
78
+ * there. An RRD database can contain several Round Robin
79
+ * Archives. Each Round Robin Archive can have a different row
80
+ * spacing along the time axis (pdp_cnt) and a different
81
+ * consolidation function (cf) used to build its consolidated
82
+ * data points (cdp).
83
+ *
84
+ * rra_st - RRA Start (rra_st). The moments (rra_st) in time where
85
+ * Consolidated Data Points (cdp) are added to an rra are
86
+ * defined by the moments where the number of seconds since
87
+ * 1970-jan-1 modulo pdp_cnt*pdp_step equals zero (rra_st).
88
+ *
89
+ * row - Row (row). A row represent all consolidated data points (cdp)
90
+ * in a round robin archive who are of the same age.
91
+ *
92
+ * col - Column (col). A column (col) represent all consolidated
93
+ * data points (cdp) in a round robin archive (rra) who
94
+ * originated from the same data source (ds).
95
+ *
96
+ */
97
+
98
+ /****************************************************************************
99
+ * POS 1: stat_head_t static header of the database
100
+ ****************************************************************************/
101
+
102
+ typedef struct stat_head_t {
103
+
104
+ /* Data Base Identification Section ***/
105
+ char cookie[4]; /* RRD */
106
+ char version[5]; /* version of the format */
107
+ double float_cookie; /* is it the correct double
108
+ * representation ? */
109
+
110
+ /* Data Base Structure Definition *****/
111
+ unsigned long ds_cnt; /* how many different ds provide
112
+ * input to the rrd */
113
+ unsigned long rra_cnt; /* how many rras will be maintained
114
+ * in the rrd */
115
+ unsigned long pdp_step; /* pdp interval in seconds */
116
+
117
+ unival par[10]; /* global parameters ... unused
118
+ at the moment */
119
+ } stat_head_t;
120
+
121
+
122
+ /****************************************************************************
123
+ * POS 2: ds_def_t (* ds_cnt) Data Source definitions
124
+ ****************************************************************************/
125
+
126
+ enum dst_en { DST_COUNTER=0, /* data source types available */
127
+ DST_ABSOLUTE,
128
+ DST_GAUGE,
129
+ DST_DERIVE,
130
+ DST_CDEF};
131
+
132
+ enum ds_param_en { DS_mrhb_cnt=0, /* minimum required heartbeat. A
133
+ * data source must provide input at
134
+ * least every ds_mrhb seconds,
135
+ * otherwise it is regarded dead and
136
+ * will be set to UNKNOWN */
137
+ DS_min_val, /* the processed input of a ds must */
138
+ DS_max_val, /* be between max_val and min_val
139
+ * both can be set to UNKNOWN if you
140
+ * do not care. Data outside the limits
141
+ * set to UNKNOWN */
142
+ DS_cdef = DS_mrhb_cnt}; /* pointer to encoded rpn
143
+ * expression only applies to DST_CDEF */
144
+
145
+ /* The magic number here is one less than DS_NAM_SIZE */
146
+ #define DS_NAM_FMT "%19[a-zA-Z0-9_-]"
147
+ #define DS_NAM_SIZE 20
148
+
149
+ #define DST_FMT "%19[A-Z]"
150
+ #define DST_SIZE 20
151
+
152
+ typedef struct ds_def_t {
153
+ char ds_nam[DS_NAM_SIZE]; /* Name of the data source (null terminated)*/
154
+ char dst[DST_SIZE]; /* Type of data source (null terminated)*/
155
+ unival par[10]; /* index of this array see ds_param_en */
156
+ } ds_def_t;
157
+
158
+ /****************************************************************************
159
+ * POS 3: rra_def_t ( * rra_cnt) one for each store to be maintained
160
+ ****************************************************************************/
161
+ enum cf_en { CF_AVERAGE=0, /* data consolidation functions */
162
+ CF_MINIMUM,
163
+ CF_MAXIMUM,
164
+ CF_LAST,
165
+ CF_HWPREDICT,
166
+ /* An array of predictions using the seasonal
167
+ * Holt-Winters algorithm. Requires an RRA of type
168
+ * CF_SEASONAL for this data source. */
169
+ CF_SEASONAL,
170
+ /* An array of seasonal effects. Requires an RRA of
171
+ * type CF_HWPREDICT for this data source. */
172
+ CF_DEVPREDICT,
173
+ /* An array of deviation predictions based upon
174
+ * smoothed seasonal deviations. Requires an RRA of
175
+ * type CF_DEVSEASONAL for this data source. */
176
+ CF_DEVSEASONAL,
177
+ /* An array of smoothed seasonal deviations. Requires
178
+ * an RRA of type CF_HWPREDICT for this data source.
179
+ * */
180
+ CF_FAILURES};
181
+ /* A binary array of failure indicators: 1 indicates
182
+ * that the number of violations in the prescribed
183
+ * window exceeded the prescribed threshold. */
184
+
185
+ #define MAX_RRA_PAR_EN 10
186
+ enum rra_par_en { RRA_cdp_xff_val=0, /* what part of the consolidated
187
+ * datapoint must be known, to produce a
188
+ * valid entry in the rra */
189
+ RRA_hw_alpha,
190
+ /* exponential smoothing parameter for the intercept in
191
+ * the Holt-Winters prediction algorithm. */
192
+ RRA_hw_beta,
193
+ /* exponential smoothing parameter for the slope in
194
+ * the Holt-Winters prediction algorithm. */
195
+ RRA_dependent_rra_idx,
196
+ /* For CF_HWPREDICT: index of the RRA with the seasonal
197
+ * effects of the Holt-Winters algorithm (of type
198
+ * CF_SEASONAL).
199
+ * For CF_DEVPREDICT: index of the RRA with the seasonal
200
+ * deviation predictions (of type CF_DEVSEASONAL).
201
+ * For CF_SEASONAL: index of the RRA with the Holt-Winters
202
+ * intercept and slope coefficient (of type CF_HWPREDICT).
203
+ * For CF_DEVSEASONAL: index of the RRA with the
204
+ * Holt-Winters prediction (of type CF_HWPREDICT).
205
+ * For CF_FAILURES: index of the CF_DEVSEASONAL array.
206
+ * */
207
+ RRA_seasonal_smooth_idx,
208
+ /* For CF_SEASONAL and CF_DEVSEASONAL:
209
+ * an integer between 0 and row_count - 1 which
210
+ * is index in the seasonal cycle for applying
211
+ * the period smoother. */
212
+ RRA_failure_threshold,
213
+ /* For CF_FAILURES, number of violations within the last
214
+ * window required to mark a failure. */
215
+ RRA_seasonal_gamma = RRA_hw_alpha,
216
+ /* exponential smoothing parameter for seasonal effects.
217
+ * */
218
+ RRA_delta_pos = RRA_hw_alpha,
219
+ RRA_delta_neg = RRA_hw_beta,
220
+ /* confidence bound scaling parameters for the
221
+ * the FAILURES RRA. */
222
+ RRA_window_len = RRA_seasonal_smooth_idx};
223
+ /* For CF_FAILURES, the length of the window for measuring
224
+ * failures. */
225
+
226
+ #define CF_NAM_FMT "%19[A-Z]"
227
+ #define CF_NAM_SIZE 20
228
+
229
+ typedef struct rra_def_t {
230
+ char cf_nam[CF_NAM_SIZE];/* consolidation function (null term) */
231
+ unsigned long row_cnt; /* number of entries in the store */
232
+ unsigned long pdp_cnt; /* how many primary data points are
233
+ * required for a consolidated data
234
+ * point?*/
235
+ unival par[MAX_RRA_PAR_EN]; /* index see rra_param_en */
236
+
237
+ } rra_def_t;
238
+
239
+
240
+ /****************************************************************************
241
+ ****************************************************************************
242
+ ****************************************************************************
243
+ * LIVE PART OF THE HEADER. THIS WILL BE WRITTEN ON EVERY UPDATE *
244
+ ****************************************************************************
245
+ ****************************************************************************
246
+ ****************************************************************************/
247
+ /****************************************************************************
248
+ * POS 4: live_head_t
249
+ ****************************************************************************/
250
+
251
+ typedef struct live_head_t {
252
+ time_t last_up; /* when was rrd last updated */
253
+ long last_up_usec; /* micro seconds part of the
254
+ update timestamp. Always >= 0 */
255
+ } live_head_t;
256
+
257
+
258
+ /****************************************************************************
259
+ * POS 5: pdp_prep_t (* ds_cnt) here we prepare the pdps
260
+ ****************************************************************************/
261
+ #define LAST_DS_LEN 30 /* DO NOT CHANGE THIS ... */
262
+
263
+ enum pdp_par_en { PDP_unkn_sec_cnt=0, /* how many seconds of the current
264
+ * pdp value is unknown data? */
265
+
266
+ PDP_val}; /* current value of the pdp.
267
+ this depends on dst */
268
+
269
+ typedef struct pdp_prep_t{
270
+ char last_ds[LAST_DS_LEN]; /* the last reading from the data
271
+ * source. this is stored in ASCII
272
+ * to cater for very large counters
273
+ * we might encounter in connection
274
+ * with SNMP. */
275
+ unival scratch[10]; /* contents according to pdp_par_en */
276
+ } pdp_prep_t;
277
+
278
+ /* data is passed from pdp to cdp when seconds since epoch modulo pdp_step == 0
279
+ obviously the updates do not occur at these times only. Especially does the
280
+ format allow for updates to occur at different times for each data source.
281
+ The rules which makes this work is as follows:
282
+
283
+ * DS updates may only occur at ever increasing points in time
284
+ * When any DS update arrives after a cdp update time, the *previous*
285
+ update cycle gets executed. All pdps are transfered to cdps and the
286
+ cdps feed the rras where necessary. Only then the new DS value
287
+ is loaded into the PDP. */
288
+
289
+
290
+ /****************************************************************************
291
+ * POS 6: cdp_prep_t (* rra_cnt * ds_cnt ) data prep area for cdp values
292
+ ****************************************************************************/
293
+ #define MAX_CDP_PAR_EN 10
294
+ #define MAX_CDP_FAILURES_IDX 8
295
+ /* max CDP scratch entries avail to record violations for a FAILURES RRA */
296
+ #define MAX_FAILURES_WINDOW_LEN 28
297
+ enum cdp_par_en { CDP_val=0,
298
+ /* the base_interval is always an
299
+ * average */
300
+ CDP_unkn_pdp_cnt,
301
+ /* how many unknown pdp were
302
+ * integrated. This and the cdp_xff
303
+ * will decide if this is going to
304
+ * be a UNKNOWN or a valid value */
305
+ CDP_hw_intercept,
306
+ /* Current intercept coefficient for the Holt-Winters
307
+ * prediction algorithm. */
308
+ CDP_hw_last_intercept,
309
+ /* Last iteration intercept coefficient for the Holt-Winters
310
+ * prediction algorihtm. */
311
+ CDP_hw_slope,
312
+ /* Current slope coefficient for the Holt-Winters
313
+ * prediction algorithm. */
314
+ CDP_hw_last_slope,
315
+ /* Last iteration slope coeffient. */
316
+ CDP_null_count,
317
+ /* Number of sequential Unknown (DNAN) values + 1 preceding
318
+ * the current prediction.
319
+ * */
320
+ CDP_last_null_count,
321
+ /* Last iteration count of Unknown (DNAN) values. */
322
+ CDP_primary_val = 8,
323
+ /* optimization for bulk updates: the value of the first CDP
324
+ * value to be written in the bulk update. */
325
+ CDP_secondary_val = 9,
326
+ /* optimization for bulk updates: the value of subsequent
327
+ * CDP values to be written in the bulk update. */
328
+ CDP_hw_seasonal = CDP_hw_intercept,
329
+ /* Current seasonal coefficient for the Holt-Winters
330
+ * prediction algorithm. This is stored in CDP prep to avoid
331
+ * redundant seek operations. */
332
+ CDP_hw_last_seasonal = CDP_hw_last_intercept,
333
+ /* Last iteration seasonal coeffient. */
334
+ CDP_seasonal_deviation = CDP_hw_intercept,
335
+ CDP_last_seasonal_deviation = CDP_hw_last_intercept,
336
+ CDP_init_seasonal = CDP_null_count};
337
+ /* init_seasonal is a flag which when > 0, forces smoothing updates
338
+ * to occur when rra_ptr.cur_row == 0 */
339
+
340
+ typedef struct cdp_prep_t{
341
+ unival scratch[MAX_CDP_PAR_EN];
342
+ /* contents according to cdp_par_en *
343
+ * init state should be NAN */
344
+
345
+ } cdp_prep_t;
346
+
347
+ /****************************************************************************
348
+ * POS 7: rra_ptr_t (* rra_cnt) pointers to the current row in each rra
349
+ ****************************************************************************/
350
+
351
+ typedef struct rra_ptr_t {
352
+ unsigned long cur_row; /* current row in the rra*/
353
+ } rra_ptr_t;
354
+
355
+
356
+ /****************************************************************************
357
+ ****************************************************************************
358
+ * One single struct to hold all the others. For convenience.
359
+ ****************************************************************************
360
+ ****************************************************************************/
361
+ typedef struct rrd_t {
362
+ stat_head_t *stat_head; /* the static header */
363
+ ds_def_t *ds_def; /* list of data source definitions */
364
+ rra_def_t *rra_def; /* list of round robin archive def */
365
+ live_head_t *live_head;
366
+ pdp_prep_t *pdp_prep; /* pdp data prep area */
367
+ cdp_prep_t *cdp_prep; /* cdp prep area */
368
+ rra_ptr_t *rra_ptr; /* list of rra pointers */
369
+ rrd_value_t *rrd_value; /* list of rrd values */
370
+ } rrd_t;
371
+
372
+ /****************************************************************************
373
+ ****************************************************************************
374
+ * AFTER the header section we have the DATA STORAGE AREA it is made up from
375
+ * Consolidated Data Points organized in Round Robin Archives.
376
+ ****************************************************************************
377
+ ****************************************************************************
378
+
379
+ *RRA 0
380
+ (0,0) .................... ( ds_cnt -1 , 0)
381
+ .
382
+ .
383
+ .
384
+ (0, row_cnt -1) ... (ds_cnt -1, row_cnt -1)
385
+
386
+ *RRA 1
387
+ *RRA 2
388
+
389
+ *RRA rra_cnt -1
390
+
391
+ ****************************************************************************/
392
+
393
+
394
+ #endif
395
+
396
+
397
+
398
+
@@ -0,0 +1,133 @@
1
+ /* Declarations for getopt.
2
+ Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
3
+
4
+ This file is part of the GNU C Library. Its master source is NOT part of
5
+ the C library, however. The master source lives in /gd/gnu/lib.
6
+
7
+ The GNU C Library is free software; you can redistribute it and/or
8
+ modify it under the terms of the GNU Library General Public License as
9
+ published by the Free Software Foundation; either version 2 of the
10
+ License, or (at your option) any later version.
11
+
12
+ The GNU C Library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Library General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Library General Public
18
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
19
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
+ Boston, MA 02111-1307, USA. */
21
+
22
+ #ifndef _GETOPT_H
23
+ #define _GETOPT_H 1
24
+
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ /* For communication from `getopt' to the caller.
30
+ When `getopt' finds an option that takes an argument,
31
+ the argument value is returned here.
32
+ Also, when `ordering' is RETURN_IN_ORDER,
33
+ each non-option ARGV-element is returned here. */
34
+
35
+ extern char *optarg;
36
+
37
+ /* Index in ARGV of the next element to be scanned.
38
+ This is used for communication to and from the caller
39
+ and for communication between successive calls to `getopt'.
40
+
41
+ On entry to `getopt', zero means this is the first call; initialize.
42
+
43
+ When `getopt' returns -1, this is the index of the first of the
44
+ non-option elements that the caller should itself scan.
45
+
46
+ Otherwise, `optind' communicates from one call to the next
47
+ how much of ARGV has been scanned so far. */
48
+
49
+ extern int optind;
50
+
51
+ /* Callers store zero here to inhibit the error message `getopt' prints
52
+ for unrecognized options. */
53
+
54
+ extern int opterr;
55
+
56
+ /* Set to an option character which was unrecognized. */
57
+
58
+ extern int optopt;
59
+
60
+ /* Describe the long-named options requested by the application.
61
+ The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
62
+ of `struct option' terminated by an element containing a name which is
63
+ zero.
64
+
65
+ The field `has_arg' is:
66
+ no_argument (or 0) if the option does not take an argument,
67
+ required_argument (or 1) if the option requires an argument,
68
+ optional_argument (or 2) if the option takes an optional argument.
69
+
70
+ If the field `flag' is not NULL, it points to a variable that is set
71
+ to the value given in the field `val' when the option is found, but
72
+ left unchanged if the option is not found.
73
+
74
+ To have a long-named option do something other than set an `int' to
75
+ a compiled-in constant, such as set a value from `optarg', set the
76
+ option's `flag' field to zero and its `val' field to a nonzero
77
+ value (the equivalent single-letter option character, if there is
78
+ one). For long options that have a zero `flag' field, `getopt'
79
+ returns the contents of the `val' field. */
80
+
81
+ struct option
82
+ {
83
+ #if defined (__STDC__) && __STDC__
84
+ const char *name;
85
+ #else
86
+ char *name;
87
+ #endif
88
+ /* has_arg can't be an enum because some compilers complain about
89
+ type mismatches in all the code that assumes it is an int. */
90
+ int has_arg;
91
+ int *flag;
92
+ int val;
93
+ };
94
+
95
+ /* Names for the values of the `has_arg' field of `struct option'. */
96
+
97
+ #define no_argument 0
98
+ #define required_argument 1
99
+ #define optional_argument 2
100
+
101
+ #if defined (__STDC__) && __STDC__
102
+ #ifdef __GNU_LIBRARY__
103
+ /* Many other libraries have conflicting prototypes for getopt, with
104
+ differences in the consts, in stdlib.h. To avoid compilation
105
+ errors, only prototype getopt for the GNU C library. */
106
+ extern int getopt (int argc, char *const *argv, const char *shortopts);
107
+ #else /* not __GNU_LIBRARY__ */
108
+ extern int getopt ();
109
+ #endif /* __GNU_LIBRARY__ */
110
+ extern int getopt_long (int argc, char *const *argv, const char *shortopts,
111
+ const struct option *longopts, int *longind);
112
+ extern int getopt_long_only (int argc, char *const *argv,
113
+ const char *shortopts,
114
+ const struct option *longopts, int *longind);
115
+
116
+ /* Internal only. Users should not call this directly. */
117
+ extern int _getopt_internal (int argc, char *const *argv,
118
+ const char *shortopts,
119
+ const struct option *longopts, int *longind,
120
+ int long_only);
121
+ #else /* not __STDC__ */
122
+ extern int getopt ();
123
+ extern int getopt_long ();
124
+ extern int getopt_long_only ();
125
+
126
+ extern int _getopt_internal ();
127
+ #endif /* __STDC__ */
128
+
129
+ #ifdef __cplusplus
130
+ }
131
+ #endif
132
+
133
+ #endif /* _GETOPT_H */
@@ -0,0 +1,5 @@
1
+ #define DNAN set_to_DNAN()
2
+ #define DINF set_to_DINF()
3
+
4
+ double set_to_DNAN(void);
5
+ double set_to_DINF(void);
@@ -0,0 +1,182 @@
1
+ /*****************************************************************************
2
+ * RRDtool 1.2.30 Copyright by Tobi Oetiker, 1997-2009
3
+ *****************************************************************************
4
+ * rrd_tool.h Common Header File
5
+ *****************************************************************************/
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+
11
+ #ifndef _RRD_TOOL_H
12
+ #define _RRD_TOOL_H
13
+
14
+ #ifdef HAVE_CONFIG_H
15
+ #include "../rrd_config.h"
16
+ #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
17
+ #include "../win32/config.h"
18
+ #endif
19
+
20
+ #ifdef MUST_DISABLE_SIGFPE
21
+ #include <signal.h>
22
+ #endif
23
+
24
+ #ifdef MUST_DISABLE_FPMASK
25
+ #include <floatingpoint.h>
26
+ #endif
27
+
28
+ #include <stdio.h>
29
+ #include <stdlib.h>
30
+ #include <errno.h>
31
+ #include <string.h>
32
+ #include <ctype.h>
33
+
34
+ #if HAVE_SYS_PARAM_H
35
+ # include <sys/param.h>
36
+ #endif
37
+
38
+ #ifndef MAXPATH
39
+ # define MAXPATH 1024
40
+ #endif
41
+
42
+ #if HAVE_MATH_H
43
+ # include <math.h>
44
+ #endif
45
+ /* Sorry: don't know autoconf as well how to check the exist of
46
+ dirent.h ans sys/stat.h
47
+ */
48
+
49
+ #if HAVE_DIRENT_H
50
+ # include <dirent.h>
51
+ # define NAMLEN(dirent) strlen((dirent)->d_name)
52
+ #else
53
+ # define dirent direct
54
+ # define NAMLEN(dirent) (dirent)->d_namlen
55
+ # if HAVE_SYS_NDIR_H
56
+ # include <sys/ndir.h>
57
+ # endif
58
+ # if HAVE_SYS_DIR_H
59
+ # include <sys/dir.h>
60
+ # endif
61
+ # if HAVE_NDIR_H
62
+ # include <ndir.h>
63
+ # endif
64
+ #endif
65
+
66
+ #if HAVE_SYS_TYPES_H
67
+ # include <sys/types.h>
68
+ #endif
69
+
70
+ #if HAVE_SYS_STAT_H
71
+ # include <sys/stat.h>
72
+ #endif
73
+
74
+ #if HAVE_STRINGS_H
75
+ # include <strings.h>
76
+ #endif
77
+
78
+ #include "rrd.h"
79
+
80
+ #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
81
+
82
+ /* Win32 only includes */
83
+
84
+ #include <float.h> /* for _isnan */
85
+ #include <io.h> /* for chdir */
86
+ #include <process.h> /* for getpid */
87
+
88
+ #define random rand
89
+ #define srandom srand
90
+
91
+ struct tm* localtime_r(const time_t *timep, struct tm* result);
92
+ char* ctime_r(const time_t *timep, char* result);
93
+ struct tm* gmtime_r(const time_t *timep, struct tm* result);
94
+ char *strtok_r(char *str, const char *sep, char **last);
95
+
96
+ #else
97
+
98
+ /* unix-only includes */
99
+ #if !defined isnan && !defined HAVE_ISNAN
100
+ int isnan(double value);
101
+ #endif
102
+
103
+ #endif
104
+
105
+ /* local include files -- need to be after the system ones */
106
+ #include "rrd_getopt.h"
107
+ #include "rrd_format.h"
108
+
109
+ #ifndef max
110
+ #define max(a,b) ((a) > (b) ? (a) : (b))
111
+ #endif
112
+
113
+ #ifndef min
114
+ #define min(a,b) ((a) < (b) ? (a) : (b))
115
+ #endif
116
+
117
+ #define DIM(x) (sizeof(x)/sizeof(x[0]))
118
+
119
+ /* rrd info interface */
120
+ enum info_type { RD_I_VAL=0,
121
+ RD_I_CNT,
122
+ RD_I_STR,
123
+ RD_I_INT };
124
+
125
+ typedef union infoval {
126
+ unsigned long u_cnt;
127
+ rrd_value_t u_val;
128
+ char *u_str;
129
+ int u_int;
130
+ } infoval;
131
+
132
+ typedef struct info_t {
133
+ char *key;
134
+ enum info_type type;
135
+ union infoval value;
136
+ struct info_t *next;
137
+ } info_t;
138
+
139
+ info_t *rrd_info(int, char **);
140
+ int rrd_lastupdate(int argc, char **argv, time_t *last_update,
141
+ unsigned long *ds_cnt, char ***ds_namv, char ***last_ds);
142
+ info_t *rrd_update_v(int, char **);
143
+ char * sprintf_alloc(char *, ...);
144
+ info_t *info_push(info_t *, char *, enum info_type, infoval);
145
+
146
+ /* HELPER FUNCTIONS */
147
+
148
+ int PngSize(FILE *, long *, long *);
149
+
150
+ int rrd_create_fn(const char *file_name, rrd_t *rrd);
151
+ int rrd_fetch_fn(const char *filename, enum cf_en cf_idx,
152
+ time_t *start,time_t *end,
153
+ unsigned long *step,
154
+ unsigned long *ds_cnt,
155
+ char ***ds_namv,
156
+ rrd_value_t **data);
157
+
158
+ void rrd_free(rrd_t *rrd);
159
+ void rrd_freemem(void *mem);
160
+ void rrd_init(rrd_t *rrd);
161
+
162
+ int rrd_open(const char *file_name, FILE **in_file, rrd_t *rrd, int rdwr);
163
+ int readfile(const char *file, char **buffer, int skipfirst);
164
+
165
+ #define RRD_READONLY 0
166
+ #define RRD_READWRITE 1
167
+
168
+ enum cf_en cf_conv(const char *string);
169
+ enum dst_en dst_conv(char *string);
170
+ long ds_match(rrd_t *rrd,char *ds_nam);
171
+ double rrd_diff(char *a, char *b);
172
+
173
+ /* rrd_strerror is thread safe, but still it uses a global buffer
174
+ (but one per thread), thus subsequent calls within a single
175
+ thread overwrite the same buffer */
176
+ const char *rrd_strerror(int err);
177
+
178
+ #endif
179
+
180
+ #ifdef __cplusplus
181
+ }
182
+ #endif
@@ -1,5 +1,13 @@
1
1
  require 'mkmf'
2
2
 
3
+ case RUBY_PLATFORM
4
+ when /openbsd/i
5
+ puts "Using OpenBSD hacks"
6
+ $LDFLAGS += ' -L/usr/X11R6/lib'
7
+ find_library('z', nil)
8
+ find_library('freetype', nil)
9
+ end
10
+
3
11
  dir_config("rrd")
4
12
 
5
13
  # Try to detect the librrd version.
@@ -7,8 +15,10 @@ dir_config("rrd")
7
15
  # or submit a pull request. Thanks!
8
16
  if have_library("rrd", "rrd_flushcached")
9
17
  src_prefix = '1.4'
10
- elsif have_library("rrd", "rrd_create")
18
+ elsif have_type("rrd_info_t", "rrd.h") and have_library("rrd", "rrd_create")
11
19
  src_prefix = '1.3'
20
+ elsif have_library("rrd", "rrd_create")
21
+ src_prefix = '1.2'
12
22
  else
13
23
  puts "Unsupported librrd version, abort."
14
24
  exit 1
data/librrd.gemspec CHANGED
@@ -7,11 +7,11 @@ Gem::Specification.new do |s|
7
7
  ## If your rubyforge_project name is different, then edit it and comment out
8
8
  ## the sub! line in the Rakefile
9
9
  s.name = 'librrd'
10
- s.version = '0.1.2'
11
- s.date = '2010-10-05'
10
+ s.version = '0.2.0'
11
+ s.date = '2010-10-06'
12
12
 
13
13
  s.summary = "Ruby bindings for librrd"
14
- s.description = "Ruby bindings for librrd. Extracted from the rrdtool source."
14
+ s.description = "Ruby bindings for librrd. Extracted from the RRDtool source."
15
15
 
16
16
  s.authors = ["Bernd Ahlers"]
17
17
  s.email = 'bernd@tuneafish.de'
@@ -33,6 +33,11 @@ Gem::Specification.new do |s|
33
33
  README.md
34
34
  Rakefile
35
35
  VERSION
36
+ ext/librrd/1.2/main.c
37
+ ext/librrd/1.2/rrd_format.h
38
+ ext/librrd/1.2/rrd_getopt.h
39
+ ext/librrd/1.2/rrd_nan_inf.h
40
+ ext/librrd/1.2/rrd_tool.h
36
41
  ext/librrd/1.3/main.c
37
42
  ext/librrd/1.4/main.c
38
43
  ext/librrd/extconf.rb
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librrd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bernd Ahlers
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-05 00:00:00 +02:00
18
+ date: 2010-10-06 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: Ruby bindings for librrd. Extracted from the rrdtool source.
22
+ description: Ruby bindings for librrd. Extracted from the RRDtool source.
23
23
  email: bernd@tuneafish.de
24
24
  executables: []
25
25
 
@@ -35,6 +35,11 @@ files:
35
35
  - README.md
36
36
  - Rakefile
37
37
  - VERSION
38
+ - ext/librrd/1.2/main.c
39
+ - ext/librrd/1.2/rrd_format.h
40
+ - ext/librrd/1.2/rrd_getopt.h
41
+ - ext/librrd/1.2/rrd_nan_inf.h
42
+ - ext/librrd/1.2/rrd_tool.h
38
43
  - ext/librrd/1.3/main.c
39
44
  - ext/librrd/1.4/main.c
40
45
  - ext/librrd/extconf.rb