[Jifty-commit] r5193 - in jifty/trunk: lib/Jifty/Plugin
Jifty commits
jifty-commit at lists.jifty.org
Tue Mar 4 13:41:01 EST 2008
Author: alexmv
Date: Tue Mar 4 13:41:00 2008
New Revision: 5193
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Plugin/Monitoring.pm
Log:
r28248 at zoq-fot-pik: chmrr | 2008-03-04 13:37:34 -0500
* previous() method for doing diffs to the last value
Modified: jifty/trunk/lib/Jifty/Plugin/Monitoring.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Monitoring.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Monitoring.pm Tue Mar 4 13:41:00 2008
@@ -62,7 +62,7 @@
month months
year years
- data_point timer/;
+ data_point timer previous/;
BEGIN {
for my $time (qw/minute hour day week month year/) {
@@ -113,7 +113,7 @@
$self->add_monitor(@_);
}
-=head2 data_point NAME, VALUE [, CATEGORY]
+=head2 data_point [CATEGORY,] NAME, VALUE
Records a data point, associating C<NAME> to C<VALUE> at the current
time. C<CATEGORY> defaults to the name of the monitor that the data
@@ -137,6 +137,31 @@
);
}
+=head2 previous [CATEGORY,] NAME
+
+Returns the most recent valeu for the data point of the given C<NAME>
+and C<CATEGORY>. C<CATEGORY> defaults to the name of the current
+monitor.
+
+=cut
+
+sub previous {
+ my ($self) = Jifty->find_plugin("Jifty::Plugin::Monitoring");
+ $self ||= $Jifty::Plugin::Monitoring::self;
+
+ my $category = @_ == 2 ? shift : $self->current_monitor->{name};
+ my ($name) = @_;
+
+ my $data = Jifty::Plugin::Monitoring::Model::MonitoredDataPointCollection->new();
+ $data->limit( column => 'category', value => $category );
+ $data->limit( column => 'sample_name', value => $name );
+ $data->limit( column => 'sampled_at', operator => '<', value => $self->now );
+ $data->set_page_info(per_page => 1);
+ $data->order_by(column => 'sampled_at', order => 'DESC');
+ my $row = $data->first;
+ return $row ? $row->value : undef;
+}
+
=head2 timer MECH, URL
Uses L<Time::HiRes> to time how long it takes the given
More information about the Jifty-commit
mailing list