_render_jsonp( $self, Mojo::JSON->new->encode({ status => $status }) );
};
+get '/gnuplot' => sub {
+ my $self = shift;
+
+ my $sql = $self->param('sql') || die "sql required";
+
+ my $ret = $gearman->req( 'SUBMIT_JOB', 'Store_sql', '', $sql );
+ die "no result for $sql" unless $ret;
+
+ $ret = Mojo::JSON->new->decode( $ret );
+
+ my $dir = $self->app->home->rel_dir('public');
+
+ my $name = $sql;
+ $name =~ s/\W+//gs;
+ $name .= '.png';
+
+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|
+set terminal png
+set output '$png'
+
+set xdata time
+set timefmt "%Y-%m-%d %H:%M:%S"
+set format x "%H%M%S"
+
+plot '-' using 1:3 title "$c[0]"
+|;
+ foreach my $row ( @{ $ret->{rows} } ) {
+ print $gnuplot join("\t", @$row),"\n";
+ }
+ print $gnuplot "e\n";
+ close($gnuplot);
+
+ $self->redirect_to("/gnuplot/$name");
+};
+
app->start;
__DATA__
<li><%= link_to 'CRM' => 'CRM.html' %> search with tabular output
</ul>
+Gnuplot graphs:
+
+<ul>
+<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>
+
Low-level API tests:
<%= link_to 'HTTP ping' => 'ping_http' %>