reformat timestamps for gnuplot
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 21 Mar 2011 09:25:08 +0000 (09:25 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 21 Mar 2011 09:25:08 +0000 (09:25 +0000)
web_ui.pl

index 0a2c977..d2a957f 100755 (executable)
--- a/web_ui.pl
+++ b/web_ui.pl
@@ -96,29 +96,32 @@ warn "# $sql -> $name";
        mkdir "$dir/gnuplot" unless -e "$dir/gnuplot";
        my $png = "$dir/gnuplot/$name"; # FIXME
 
-       open(my $gnuplot, '|-', 'gnuplot') || die "gnuplot: $!";
-       open($gnuplot, '>', '/tmp/gnuplot') if $self->param('debug');
-
        my @c = @{ $ret->{columns} };
        warn "first column not timestamp" unless shift @c eq 'timestamp';
 
-       print $gnuplot qq|
+       my $gnuplot = qq|
 set terminal png
 set output '$png'
 
 set xdata time
-set timefmt "%Y-%m-%d %H:%M:%S"
-set format x "%H%M%S"
+set timefmt "%Y-%m-%dT%H:%M:%S"
+set format x "%H:%M\\n%d"
 
-plot '-' using 1:3 title "$c[0]"
+plot '-' using 1:2 title "$c[0]"
 |;
        foreach my $row ( @{ $ret->{rows} } ) {
-               print $gnuplot join("\t", @$row),"\n";
+               my $date = shift @$row;
+               $date =~ s/ /T/g;
+               $date =~ s/\.\d+//;
+               $gnuplot .= join(" ", $date, @$row)."\n";
        }
-       print $gnuplot "e\n";
-       close($gnuplot);
+       $gnuplot .= "e\n";
+
+       open(my $fd, '|-', 'gnuplot') || die "gnuplot: $!";
+       print $fd $gnuplot;
+       close($fd);
 
-       $self->render('gnuplot', sql => $sql, img => "/gnuplot/$name");
+       $self->render('gnuplot', sql => $sql, img => "/gnuplot/$name", gnuplot => $gnuplot);
 };
 
 get '/_redis' => sub {
@@ -148,6 +151,7 @@ __DATA__
 Gnuplot graphs:
 
 <ul>
+<li><a href="/gnuplot?sql=select start,ping_ok,ping_error from poll">poll stats</a>
 <li><a href="/gnuplot?sql=select timestamp,rtt from ping where ip << inet '10.17/16' order by timestamp desc limit 1000">ttl from 10.17 network</a>
 </ul>
 
@@ -167,6 +171,7 @@ pong: <tt><%= $pong %>
  <%= submit_button %>
 <% end %>
 <img src="<%= $img %>">
+<pre><%= $gnuplot %></pre>
 
 @@ layouts/default.html.ep
 <!doctype html><html>