index 408994f18bf6b3215093c02232e309950e976059..21f6c0de54b255e67e34ae4271ef03ff62faa787 100644 (file)
int i;
Check_Type(rb_strings, T_ARRAY);
- a.len = RARRAY(rb_strings)->len + 1;
+ a.len = RARRAY_LEN(rb_strings) + 1;
a.strings = malloc(a.len * sizeof(char *));
a.strings[0] = "dummy"; /* first element is a dummy element */
switch (TYPE(v)) {
case T_STRING:
- a.strings[i + 1] = strdup(STR2CSTR(v));
+ a.strings[i + 1] = strdup(StringValuePtr(v));
break;
case T_FIXNUM:
- snprintf(buf, 63, "%d", FIX2INT(v));
+ snprintf(buf, 63, "%ld", FIX2INT(v));
a.strings[i + 1] = strdup(buf);
break;
default:
rb_raise(rb_eTypeError,
- "invalid argument - %s, expected T_STRING or T_FIXNUM on index %d",
+ "invalid argument - %s, expected T_STRING or T_FIXNUM on index %ld",
rb_class2name(CLASS_OF(v)), i);
break;
}
return rrd_call(rrd_update, args);
}
-VALUE rb_rrd_flush(
+VALUE rb_rrd_flushcached(
VALUE self,
VALUE args)
{
- return rrd_call(rrd_cmd_flush, args);
+ return rrd_call(rrd_flushcached, args);
}
VALUE result;
a = string_arr_new(args);
+ reset_rrd_state();
data = func(a.len, a.strings);
string_arr_delete(a);
return rb_funcall(rb_cTime, rb_intern("at"), 1, UINT2NUM(last));
}
+VALUE rb_rrd_xport(
+ VALUE self,
+ VALUE args)
+{
+ string_arr a;
+ unsigned long i, j, k, step, col_cnt;
+ int xxsize;
+ rrd_value_t *data;
+ char **legend_v;
+ VALUE legend, result, rdata;
+ time_t start, end;
+
+ a = string_arr_new(args);
+ reset_rrd_state();
+ rrd_xport(a.len, a.strings, &xxsize, &start, &end, &step, &col_cnt, &legend_v, &data);
+ string_arr_delete(a);
+
+ RRD_CHECK_ERROR;
+
+ legend = rb_ary_new();
+ for (i = 0; i < col_cnt; i++) {
+ rb_ary_push(legend, rb_str_new2(legend_v[i]));
+ free(legend_v[i]);
+ }
+ free(legend_v);
+
+ k = 0;
+ rdata = rb_ary_new();
+ for (i = start; i <= end; i += step) {
+ VALUE line = rb_ary_new2(col_cnt);
+ for (j = 0; j < col_cnt; j++) {
+ rb_ary_store(line, j, rb_float_new(data[k]));
+ k++;
+ }
+ rb_ary_push(rdata, line);
+ }
+ free(data);
+
+ result = rb_ary_new2(6);
+ rb_ary_store(result, 0, INT2FIX(start));
+ rb_ary_store(result, 1, INT2FIX(end));
+ rb_ary_store(result, 2, INT2FIX(step));
+ rb_ary_store(result, 3, INT2FIX(col_cnt));
+ rb_ary_store(result, 4, legend);
+ rb_ary_store(result, 5, rdata);
+ return result;
+}
+
void Init_RRD(
)
{
rb_define_module_function(mRRD, "restore", rb_rrd_restore, -2);
rb_define_module_function(mRRD, "tune", rb_rrd_tune, -2);
rb_define_module_function(mRRD, "update", rb_rrd_update, -2);
- rb_define_module_function(mRRD, "flush", rb_rrd_flush, -2);
+ rb_define_module_function(mRRD, "flushcached", rb_rrd_flushcached, -2);
rb_define_module_function(mRRD, "info", rb_rrd_info, -2);
rb_define_module_function(mRRD, "updatev", rb_rrd_updatev, -2);
rb_define_module_function(mRRD, "graphv", rb_rrd_graphv, -2);
+ rb_define_module_function(mRRD, "xport", rb_rrd_xport, -2);
}