my $parent_pid = $$;
my $interrupt = 0;
my $tmp_last_parsed = '';
-my @SQL_ACTION = ('SELECT', 'INSERT', 'UPDATE', 'DELETE');
+my @SQL_ACTION = ('SELECT', 'INSERT', 'UPDATE', 'DELETE');
+my $graphid = 1;
####
# method used to fork as many child as wanted
.sql .nu0 {color: #cc66cc;}
.sql span.xtra { display:block; }
-#queriespersecond_graph, #connectionspersecond_graph, #checkpointwritebuffers_graph, #checkpointfiles_graph, #restartpointwritebuffers_graph, #temporaryfile_graph, #autovacuum_graph, #selectqueries_graph, #writequeries_graph {
+#queriespersecond_graph, #connectionspersecond_graph, #queriesduration_graph, #checkpointwritebuffers_graph, #checkpointfiles_graph, #restartpointwritebuffers_graph, #temporaryfile_graph, #autovacuum_graph, #selectqueries_graph, #writequeries_graph {
width : 1025px;
height: 400px;
background:#F3F2ED;
# Mini queries per minute
$graph_data{query3} .= "[$t, " . ($q_dataavg{min}{"$rd"} || 0) . "],";
# Average duration per minute
- $graph_data{query4} .= "[$t, " . sprintf("%.2f", (($q_dataavg{duration}{"$rd"} || 0) / ($q_dataavg{count}{"$rd"} || 1)) / 1000) . "],";
+ $graph_data{query4} .= "[$t, " . sprintf("%.3f", ($q_dataavg{duration}{"$rd"} || 0) / ($q_dataavg{count}{"$rd"} || 1)) . "],";
if (scalar keys %c_dataavg) {
# Average connections per minute
$graph_data{conn2} .= "[$t, " . int(($c_dataavg{average}{"$rd"} || 0) / (60 * $avg_minutes)) . "],";
# Average per minute
$graph_data{"$action"} .= "[$t, " . ($a_dataavg{$action}{count}{"$rd"} || 0) . "],";
if ($action eq 'SELECT') {
- $graph_data{"$action-2"} .= "[$t, " . sprintf("%.2f", (($a_dataavg{$action}{duration}{"$rd"} || 0) / ($a_dataavg{$action}{count}{"$rd"} || 1)) / 1000) . "]," if ($action eq 'SELECT');
+ $graph_data{"$action-2"} .= "[$t, " . sprintf("%.3f", ($a_dataavg{$action}{duration}{"$rd"} || 0) / ($a_dataavg{$action}{count}{"$rd"} || 1)) . "]," if ($action eq 'SELECT');
} else {
- $graph_data{"write"} .= "[$t, " . sprintf("%.2f", (($a_dataavg{write}{duration}{"$rd"} || 0) / ($a_dataavg{write}{count}{"$rd"} || 1)) / 1000) . "],";
+ $graph_data{"write"} .= "[$t, " . sprintf("%.3f", ($a_dataavg{write}{duration}{"$rd"} || 0) / ($a_dataavg{write}{count}{"$rd"} || 1)) . "],";
}
}
}
foreach (keys %graph_data) {
$graph_data{$_} =~ s/,$//;
}
- &flotr2_graph(
- 1, 'queriespersecond_graph', $graph_data{query1}, $graph_data{query2}, $graph_data{query3}, 'Queries per second (' . $avg_minutes . ' minutes average)',
- 'Queries per second', 'Maximum', 'Average', 'Minimum', 'Duration', $graph_data{query4}, 'Average duration (s)'
+ &flotr2_graph( $graphid++, 'queriespersecond_graph', $graph_data{query1},
+ $graph_data{query2}, $graph_data{query3}, 'Queries per second (' . $avg_minutes . ' minutes average)',
+ 'Queries per second', 'Maximum', 'Average', 'Minimum'
);
if (exists $graph_data{conn1}) {
- &flotr2_graph(
- 2, 'connectionspersecond_graph', $graph_data{conn1}, $graph_data{conn2}, $graph_data{conn3}, 'Connections per second (' . $avg_minutes . ' minutes average)',
+ &flotr2_graph( $graphid++, 'connectionspersecond_graph', $graph_data{conn1},
+ $graph_data{conn2}, $graph_data{conn3}, 'Connections per second (' . $avg_minutes . ' minutes average)',
'Connections per second', 'Maximum', 'Average', 'Minimum'
);
}
if (!$disable_query) {
- &flotr2_graph(
- 4, 'selectqueries_graph', $graph_data{"SELECT"}, '', '', 'SELECT queries (' . $avg_minutes . ' minutes period)',
- 'Queries', 'Number of queries', '', '', 'Duration', $graph_data{"SELECT-2"}, 'Average duration (s)'
+ &flotr2_graph( $graphid++, 'selectqueries_graph', $graph_data{"SELECT"}, '', '',
+ 'SELECT queries (' . $avg_minutes . ' minutes period)',
+ 'Queries', 'Number of queries', '', ''
) if ($graph_data{"SELECT"});
# Write queries
if (!$select_only && $graph_data{"write"}) {
&flotr2_graph(
- 5, 'writequeries_graph', $graph_data{"DELETE"}, $graph_data{"INSERT"}, $graph_data{"UPDATE"}, 'Write queries (' . $avg_minutes . ' minutes period)',
- 'Queries', 'DELETE queries', 'INSERT queries', 'UPDATE queries', 'Duration', $graph_data{"write"}, 'Average duration (s)'
+ $graphid++, 'writequeries_graph', $graph_data{"DELETE"}, $graph_data{"INSERT"}, $graph_data{"UPDATE"}, 'Write queries (' . $avg_minutes . ' minutes period)',
+ 'Queries', 'DELETE queries', 'INSERT queries', 'UPDATE queries'
);
}
}
+ &flotr2_graph(
+ $graphid++, 'queriesduration_graph', $graph_data{query4}, $graph_data{"SELECT-2"}, $graph_data{write}, 'Average queries duration (' . $avg_minutes . ' minutes average)',
+ 'Duration', 'All queries', 'Select queries', 'Write queries'
+ );
}
}
}
if (exists $graph_data{wbuffer}) {
&flotr2_graph(
- 6, 'checkpointwritebuffers_graph', $graph_data{wbuffer}, '', '', 'Checkpoint write buffers (' . $avg_minutes . ' minutes period)',
+ $graphid++, 'checkpointwritebuffers_graph', $graph_data{wbuffer}, '', '', 'Checkpoint write buffers (' . $avg_minutes . ' minutes period)',
'Buffers', 'Write buffers', '', ''
);
&flotr2_graph(
- 7, 'checkpointfiles_graph', $graph_data{file_added}, $graph_data{file_removed}, $graph_data{file_recycled},
+ $graphid++, 'checkpointfiles_graph', $graph_data{file_added}, $graph_data{file_removed}, $graph_data{file_recycled},
'Checkpoint Wal files usage', 'Number of files', 'Added', 'Removed', 'Recycled'
);
}
# Restart point
if ($restartpoint_info{wbuffer} && $graph_data{rwbuffer}) {
&flotr2_graph(
- 6, 'restartpointwritebuffers_graph', $graph_data{rwbuffer}, '', '', 'Restartpoint write buffers (' . $avg_minutes . ' minutes period)',
+ $graphid++, 'restartpointwritebuffers_graph', $graph_data{rwbuffer}, '', '', 'Restartpoint write buffers (' . $avg_minutes . ' minutes period)',
'Buffers', 'Write buffers', '', ''
);
}
# Temporary file size
if ($tempfile_info{count} && exists $graph_data{size}) {
&flotr2_graph(
- 8, 'temporaryfile_graph', $graph_data{size}, '', '', 'Temporary files (' . $avg_minutes . ' minutes period)',
+ $graphid++, 'temporaryfile_graph', $graph_data{size}, '', '', 'Temporary files (' . $avg_minutes . ' minutes period)',
'Size of files', 'Size of files', '', '', 'Number of files', $graph_data{count}, 'Number of files'
);
}
if ($autovacuum_info{count} || $autoanalyze_info{count}) {
if (exists $graph_data{vcount} || exists $graph_data{acount}) {
&flotr2_graph(
- 9, 'autovacuum_graph', $graph_data{vcount}, $graph_data{acount}, '', 'Autovacuum actions (' . $avg_minutes . ' minutes period)',
+ $graphid++, 'autovacuum_graph', $graph_data{vcount}, $graph_data{acount}, '', 'Autovacuum actions (' . $avg_minutes . ' minutes period)',
'', 'VACUUMs', 'ANALYZEs'
);
}
$data{"Others"} += $autovacuum_info{tables}{$t}{vacuums} || 0;
}
}
- &flotr2_piegraph(18, 'autovacuumbytable_graph', 'Autovacuum per table', %data);
+ &flotr2_piegraph($graphid++, 'autovacuumbytable_graph', 'Autovacuum per table', %data);
%data = ();
if ($total_tuples) {
print $fh "<br />\n";
$data{"Others"} += $autovacuum_info{tables}{$t}{tuples}{removed} || 0;
}
}
- &flotr2_piegraph(19, 'autovacuumtuplesremoved_graph', 'Autovacuum tuples removed per table', %data);
+ &flotr2_piegraph($graphid++, 'autovacuumtuplesremoved_graph', 'Autovacuum tuples removed per table', %data);
}
}
print $fh "</td></tr></table>\n";
} else {
$data{"Sum types < $pie_percentage_limit%"} += $total - $totala;
}
- &flotr2_piegraph(22, 'queriesbytype_graph', 'Type of queries', %data);
+ &flotr2_piegraph($graphid++, 'queriesbytype_graph', 'Type of queries', %data);
}
print $fh "</td></tr></table>\n";
}
$infos{$small[0]} = $infos{"Sum databases < $pie_percentage_limit%"};
delete $infos{"Sum databases < $pie_percentage_limit%"};
}
- &flotr2_piegraph(20, 'requestsdatabases_graph', 'Queries per database', %infos);
+ &flotr2_piegraph($graphid++, 'requestsdatabases_graph', 'Queries per database', %infos);
}
print $fh "</td></tr></table>\n";
}
$infos{$small[0]} = $infos{"Sum applications < $pie_percentage_limit%"};
delete $infos{"Sum applications < $pie_percentage_limit%"};
}
- &flotr2_piegraph(21, 'requestsapplications_graph', 'Queries per application', %infos);
+ &flotr2_piegraph($graphid++, 'requestsapplications_graph', 'Queries per application', %infos);
}
print $fh "</td></tr></table>\n";
}
$locktype{$small[0]} = $locktype{"Sum types < $pie_percentage_limit%"};
delete $locktype{"Sum types < $pie_percentage_limit%"};
}
- &flotr2_piegraph(10, 'lockbytype_graph', 'Type of locks', %locktype);
+ &flotr2_piegraph($graphid++, 'lockbytype_graph', 'Type of locks', %locktype);
}
print $fh "</td></tr></table>\n";
}
$infos{$small[0]} = $infos{"Sum sessions < $pie_percentage_limit%"};
delete $infos{"Sum sessions < $pie_percentage_limit%"};
}
- &flotr2_piegraph(11, 'databasesessions_graph', 'Sessions per database', %infos);
+ &flotr2_piegraph($graphid++, 'databasesessions_graph', 'Sessions per database', %infos);
}
print $fh "</td></tr></table>\n";
}
$infos{$small[0]} = $infos{"Sum sessions < $pie_percentage_limit%"};
delete $infos{"Sum sessions < $pie_percentage_limit%"};
}
- &flotr2_piegraph(12, 'usersessions_graph', 'Sessions per user', %infos);
+ &flotr2_piegraph($graphid++, 'usersessions_graph', 'Sessions per user', %infos);
}
print $fh "</td></tr></table>\n";
}
$infos{$small[0]} = $infos{"Sum sessions < $pie_percentage_limit%"};
delete $infos{"Sum sessions < $pie_percentage_limit%"};
}
- &flotr2_piegraph(13, 'hostsessions_graph', 'Sessions per host', %infos);
+ &flotr2_piegraph($graphid++, 'hostsessions_graph', 'Sessions per host', %infos);
}
print $fh "</td></tr></table>\n";
}
$infos{$small[0]} = $infos{"Sum connections < $pie_percentage_limit%"};
delete $infos{"Sum connections < $pie_percentage_limit%"};
}
- &flotr2_piegraph(14, 'databaseconnections_graph', 'Connections per database', %infos);
+ &flotr2_piegraph($graphid++, 'databaseconnections_graph', 'Connections per database', %infos);
}
print $fh "</td></tr></table>\n";
}
$infos{$small[0]} = $infos{"Sum connections < $pie_percentage_limit%"};
delete $infos{"Sum connections < $pie_percentage_limit%"};
}
- &flotr2_piegraph(15, 'userconnections_graph', 'Connections per user', %infos);
+ &flotr2_piegraph($graphid++, 'userconnections_graph', 'Connections per user', %infos);
}
print $fh "</td></tr></table>\n";
}
$infos{$small[0]} = $infos{"Sum connections < $pie_percentage_limit%"};
delete $infos{"Sum connections < $pie_percentage_limit%"};
}
- &flotr2_piegraph(16, 'hostconnections_graph', 'Connections per host', %infos);
+ &flotr2_piegraph($graphid++, 'hostconnections_graph', 'Connections per host', %infos);
}
print $fh "</td></tr></table>\n";
}
$infos{$small[0]} = $infos{"Sum log types < $pie_percentage_limit%"};
delete $infos{"Sum log types < $pie_percentage_limit%"};
}
- &flotr2_piegraph(17, 'logstype_graph', 'Logs per type', %infos);
+ &flotr2_piegraph($graphid++, 'logstype_graph', 'Logs per type', %infos);
}
print $fh "</td></tr></table>\n";
}
$legend1 = "{ data: d1, label: \"$legend1\", mouse:{track:true}}," if ($legend1);
$legend2 = "{ data: d2, label: \"$legend2\", mouse:{track:true}}," if ($legend2);
$legend3 = "{ data: d3, label: \"$legend3\", mouse:{track:true}}," if ($legend3);
- $legend4 = "{ data: d4, label: \"$legend4\",yaxis: 2, mouse:{track:true}}," if ($legend4);
+ $legend4 = "{ data: d4, label: \"$legend4\",yaxis: 2}," if ($legend4);
my $yaxis2 = '';
if ($ytitle2) {
my $type = '';
if ($ytitle eq 'Size of files') {
$type = 'size';
+ } elsif ($ytitle eq 'Duration') {
+ $type = 'duration';
}
print $fh <<EOF;
track: true,
trackFormatter: function(obj){ return dateTracker(obj) },
relative: true,
- sensibility: 10,
+ sensibility: 5,
trackDecimals: 2,
lineColor: 'purple',
},
} else {
val = val + " B";
}
+ } else if (type == 'duration') {
+ if (val >= 1000) {
+ val = (val / 1000);
+ val = val.toFixed(3) + " sec";
+ } else {
+ val = val + " ms";
+ }
} else {
if (val >= 1000000000000000) {
val = (val / 1000000000000000);