make stats timezone-aware

3.3
Christian Veigl 14 years ago
parent 233d00ff25
commit 50f46d2b1d

@ -5,6 +5,7 @@ use warnings;
use Time::Local;
use HTML::Entities;
use POSIX;
use DateTime::TimeZone::OffsetOnly;
# Takes a search result total count, an offset and a limit and returns
# an array containing offset values for a pagination link list
@ -544,9 +545,16 @@ sub addel_iplist {
return 1;
}
# returns the offset in localhost's timezone to GMT
=head2 tz_offset
Returns localhost's offset to GMT in seconds
=cut
sub tz_offset {
return strftime ("%z", localtime(time));
use DateTime::TimeZone::OffsetOnly;
my $tz_offset = DateTime::TimeZone::OffsetOnly->new ( offset => strftime("%z", localtime(time())) );
return $tz_offset->{offset} ;
}
1;

@ -32,7 +32,7 @@ function rrdFlot(html_id, rrd_file, graph_options, ds_graph_options, si_suffix,
else
this.si_suffix = si_suffix;
// tz_offset: offset of timezone in hours
// tz_offset: offset of timezone in seconds
if(tz_offset==null)
this.tz_offset = 0;
else
@ -187,7 +187,7 @@ rrdFlot.prototype.drawFlotGraph = function() {
}
ds_colors[ds_name]=i;
}
var flot_obj=rrdRRAStackFlotObj(this.rrd_file,rra_idx,
ds_positive_stack_list,ds_negative_stack_list,ds_single_list,
this.tz_offset);

@ -99,9 +99,8 @@ function rrdRRA2FlotObj(rrd_file,rra_idx,ds_list,want_ds_labels,want_rounding) {
// of the stack is invalid
function rrdRRAStackFlotObj(rrd_file,rra_idx,
ds_positive_stack_list,ds_negative_stack_list,ds_single_list,
want_ds_labels,want_rounding,one_undefined_enough,tz_offset)
var timestamp_shift = 3600 * tz_offset;
tz_offset,
want_ds_labels,want_rounding,one_undefined_enough) {
var rra=rrd_file.getRRA(rra_idx);
var rra_rows=rra.getNrRows();
@ -117,7 +116,7 @@ function rrdRRAStackFlotObj(rrd_file,rra_idx,
}
var first_el=last_update-(rra_rows-1)*step;
var out_el={data:[], min:(first_el+timestamp_shift)*1000.0, max:(last_update+timestamp_shift)*1000.0};
var out_el={data:[], min:(first_el+tz_offset)*1000.0, max:(last_update+tz_offset)*1000.0};
// first the stacks stack
var stack_els=[ds_positive_stack_list,ds_negative_stack_list];
@ -166,7 +165,7 @@ function rrdRRAStackFlotObj(rrd_file,rra_idx,
}
// fill the flot data
for (var id=0; id<tmp_nr_ids; id++) {
tmp_flot_els[id].data.push([(timestamp+timestamp_shift)*1000.0,ds_vals[id]]);
tmp_flot_els[id].data.push([(timestamp+tz_offset)*1000.0,ds_vals[id]]);
}
}
} // end if
@ -192,7 +191,7 @@ function rrdRRAStackFlotObj(rrd_file,rra_idx,
for (var i=0;i<rra_rows;i++) {
var el=rra.getEl(i,ds_idx);
if (el!=undefined) {
flot_series.push([(timestamp+timestamp_shift)*1000.0,el]);
flot_series.push([(timestamp+tz_offset)*1000.0,el]);
}
timestamp+=step;
} // end for

@ -33,6 +33,7 @@
var graph_opts = {};
var ds_graph_opts = {};
var tz_offset = [% tz_offset %];
if (rrd_data_arr.length == 1)
var f = new rrdFlot(args['plot_id'],rrd_data_arr[0],graph_opts,ds_graph_opts,args['si_suffix'],tz_offset);
else {

Loading…
Cancel
Save