GrowthForecast
view release on metacpan or search on metacpan
lib/GrowthForecast/Data.pm view on Meta::CPAN
$subtract = 0;
}
}
$dbh->commit;
$data->{subtract} = $subtract;
}
$self->inflate_row($data);
}
sub update {
my ($self, $service, $section, $graph, $number, $mode, $color, $timestamp ) = @_;
my $dbh = $self->dbh;
$dbh->begin_work;
my $for_update = ( $dbh->connect_info->[0] =~ /^(?i:dbi):mysql:/ ) ? ' FOR UPDATE' : '';
my $data = $self->dbh->select_row(
'SELECT * FROM graphs WHERE service_name = ? AND section_name = ? AND graph_name = ?' . $for_update,
$service, $section, $graph
);
lib/GrowthForecast/Data.pm view on Meta::CPAN
my $row = $self->dbh->select_row(
'SELECT * FROM graphs WHERE service_name = ? AND section_name = ? AND graph_name = ?',
$service, $section, $graph
);
$dbh->commit;
$self->inflate_row($row);
}
sub update_graph {
my ($self, $id, $args) = @_;
my @update = map { delete $args->{$_} } qw/service_name section_name graph_name description sort gmode color type stype llimit ulimit sllimit sulimit/;
my $meta = encode_json($args);
my $dbh = $self->dbh;
$dbh->query(
'UPDATE graphs SET service_name=?, section_name=?, graph_name=?, description=?, sort=?, gmode=?, color=?, type=?, stype=?,
llimit=?, ulimit=?, sllimit=?, sulimit=?, meta=? WHERE id = ?',
@update, $meta, $id
);
return 1;
}
sub update_graph_description {
my ($self, $id, $description) = @_;
my $dbh = $self->dbh;
$dbh->query(
'UPDATE graphs SET description=? WHERE id = ?',
$description, $id
);
return 1;
}
sub get_services {
lib/GrowthForecast/Data.pm view on Meta::CPAN
my @update = map { delete $args->{$_} } qw/description sort/;
my $meta = encode_json($args);
$self->dbh->query(
'INSERT INTO complex_graphs (service_name, section_name, graph_name, description, sort, meta, created_at, updated_at)
VALUES (?,?,?,?,?,?,?,?)',
$service, $section, $graph, @update, $meta, time, time
);
$self->get_complex($service, $section, $graph);
}
sub update_complex {
my ($self, $id, $args) = @_;
my @update = map { delete $args->{$_} } qw/service_name section_name graph_name description sort/;
my $meta = encode_json($args);
$self->dbh->query(
'UPDATE complex_graphs SET service_name = ?, section_name = ?, graph_name = ? ,
description = ?, sort = ?, meta = ?, updated_at = ?
WHERE id=?',
@update, $meta, time, $id
);
$self->get_complex_by_id($id);
lib/GrowthForecast/Data.pm view on Meta::CPAN
sub get_all_complex_graph_all {
my $self = shift;
my $list = $self->dbh->select_all(
'SELECT * FROM complex_graphs ORDER BY service_name, section_name, graph_name DESC',
);
return [] unless $list;
my @ret = map { $self->inflate_complex_row($_) } @$list;
\@ret;
}
sub update_vrule {
my ($self, $graph_path, $time, $color, $desc, $dashes) = @_;
$self->dbh->query(
'INSERT INTO vrules (graph_path,time,color,description,dashes) values (?,?,?,?,?)',
$graph_path, $time, $color, $desc, $dashes,
);
my $row = $self->dbh->select_row(
'SELECT * FROM vrules WHERE graph_path = ? AND time = ? AND color = ? AND description = ? AND dashes = ?',
$graph_path, $time, $color, $desc, $dashes,
lib/GrowthForecast/RRD.pm view on Meta::CPAN
my @param = $self->path_short_param($data);
RRDs::create($file, @param);
my $ERR=RRDs::error;
die $ERR if $ERR;
};
die "init failed: $@" if $@;
}
$file;
}
sub update_param {
my $self = shift;
my $data = shift;
my @param;
my $timestamp = $data->{timestamp} || 'N';
if ( $self->{disable_subtract} ) {
@param = (
'-t', 'num',
'--', join(':',$timestamp,$data->{number}),
);
lib/GrowthForecast/RRD.pm view on Meta::CPAN
);
}
if ( $self->{rrdcached} ) {
# The caching daemon cannot be used together with templates (-t) yet.
splice(@param, 0, 2); # delete -t option
unshift(@param, '-d', $self->{rrdcached});
}
return @param;
}
sub update {
my $self = shift;
my $data = shift;
my $file = $self->path($data);
eval {
my @param = $self->update_param($data);
RRDs::update($file, @param);
my $ERR=RRDs::error;
if ( $ERR ) {
if ( $ERR =~ /illegal attempt to update using time.*when last update time is.*minimum one second step/ ) {
debugf "update rrdfile failed: $ERR";
}
else {
die $ERR;
}
}
};
die "udpate rrdfile failed: $@" if $@;
}
sub update_short_param {
my $self = shift;
my $data = shift;
my @param;
my $timestamp = $data->{timestamp} || 'N';
if ( $self->{disable_subtract} ) {
@param = (
'-t', 'num',
'--', join(':',$timestamp,$data->{number}),
);
lib/GrowthForecast/RRD.pm view on Meta::CPAN
);
}
if ( $self->{rrdcached} ) {
# The caching daemon cannot be used together with templates (-t) yet.
splice(@param, 0, 2); # delete -t option
unshift(@param, '-d', $self->{rrdcached});
}
return @param;
}
sub update_short {
my $self = shift;
my $data = shift;
my $file = $self->path_short($data);
eval {
my @param = $self->update_short_param($data);
RRDs::update($file, @param);
my $ERR=RRDs::error;
if ( $ERR ) {
if ( $ERR =~ /illegal attempt to update using time.*when last update time is.*minimum one second step/ ) {
( run in 0.251 second using v1.01-cache-2.11-cpan-4d4bc49f3ae )