From 85201f7de2d131aba3c4e10852aed3e11f39fa0a Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 20 Mar 2018 11:28:28 +0100 Subject: web-scripts/statistics.php: take info from database --- web-scripts/statistics.php | 100 ++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 55 deletions(-) (limited to 'web-scripts/statistics.php') diff --git a/web-scripts/statistics.php b/web-scripts/statistics.php index 279aa39..1e4d89b 100644 --- a/web-scripts/statistics.php +++ b/web-scripts/statistics.php @@ -1,54 +1,44 @@ connect_error) { + die("Connection failed: " . $mysql->connect_error); +} +if (! $result = $mysql -> query( + "SELECT DISTINCT ". + "UNIX_TIMESTAMP(`statistics`.`date`) AS `date`," . + "`statistics`.`pending_tasks_count`," . + "`statistics`.`pending_packages_count`," . + "`statistics`.`staging_packages_count`," . + "`statistics`.`testing_packages_count`," . + "`statistics`.`tested_packages_count`," . + "`statistics`.`broken_tasks_count`," . + "`statistics`.`dependency_loops_count`," . + "`statistics`.`dependency_looped_tasks_count`," . + "`statistics`.`locked_tasks_count`," . + "`statistics`.`blocked_tasks_count`," . + "`statistics`.`next_tasks_count`" . + "FROM `statistics` " . + "WHERE `statistics`.`date`>=ADDTIME(NOW(),\"-7 00:00:00\") " . + "ORDER BY `statistics`.`date`" + )) + die($mysql->error); $t_min = -1; $t_max = -1; $val_max = -1; -foreach (explode("\n",trim(file_get_contents('/srv/http/statistics'))) as $val) { - $val = explode(" ",$val); - if (($t_min == -1) || ($t_min > $val[0])) - $t_min = $val[0]; - if (($t_max == -1) || ($t_max < $val[0])) - $t_max = $val[0]; - foreach ($columns as $id => $column) { - if (count($val) > $id+1) - $values[$column][$val[0]] = $val[$id+1]; - }; - foreach ($print_columns as $column) { - if (array_key_exists($column,$values)) - if (($val_max == -1) || ($val_max < $values[$column][$val[0]])) - $val_max = $values[$column][$val[0]]; - } +while($vals = $result->fetch_assoc()) { + if ($t_min == -1) + $t_min = $vals["date"]; + $t_max = $vals["date"]; + foreach ($vals as $column => $val) + if ($column != "date") { + $values[$column][$vals["date"]] = $val; + $val_max = max($val_max,$val); + } }; +$print_columns = array_keys($values); $max_len = 0; foreach ($print_columns as $column) { @@ -69,18 +59,18 @@ $im = @ImageCreate ($width + $legend_line_length + $max_len * ImageFontWidth(5), $background_color = ImageColorAllocate ($im, 255, 255, 255); $foreground_color = ImageColorAllocate ($im, 0, 0, 0); -$colors['stable'] = ImageColorAllocate ($im, 0, 0, 0); -$colors['tasks'] = ImageColorAllocate ($im, 0, 0, 128); -$colors['pending_packages'] = ImageColorAllocate ($im, 0, 0, 255); -$colors['staging'] = ImageColorAllocate ($im, 0, 100, 0); -$colors['testing'] = ImageColorAllocate ($im, 0, 200, 0); -$colors['tested'] = ImageColorAllocate ($im, 100, 255, 0); -$colors['broken'] = ImageColorAllocate ($im, 255, 0, 0); -$colors['loops'] = ImageColorAllocate ($im, 128, 128, 0); -$colors['looped_packages'] = ImageColorAllocate ($im, 255, 128, 128); -$colors['locked'] = ImageColorAllocate ($im, 128, 128, 128); -$colors['blocked'] = ImageColorAllocate ($im, 128, 0, 0); -$colors['next_pending'] = ImageColorAllocate ($im, 0, 255, 255); +$colors['stable_packages_count'] = ImageColorAllocate ($im, 0, 0, 0); +$colors['pending_tasks_count'] = ImageColorAllocate ($im, 0, 0, 128); +$colors['pending_packages_count'] = ImageColorAllocate ($im, 0, 0, 255); +$colors['staging_packages_count'] = ImageColorAllocate ($im, 0, 100, 0); +$colors['testing_packages_count'] = ImageColorAllocate ($im, 0, 200, 0); +$colors['tested_packages_count'] = ImageColorAllocate ($im, 100, 255, 0); +$colors['broken_tasks_count'] = ImageColorAllocate ($im, 255, 0, 0); +$colors['dependency_loops_count'] = ImageColorAllocate ($im, 128, 128, 0); +$colors['dependency_looped_tasks_count'] = ImageColorAllocate ($im, 255, 128, 128); +$colors['locked_tasks_count'] = ImageColorAllocate ($im, 128, 128, 128); +$colors['blocked_tasks_count'] = ImageColorAllocate ($im, 128, 0, 0); +$colors['next_tasks_count'] = ImageColorAllocate ($im, 0, 255, 255); function scale($x, $x_min, $x_max, $scale, $log) { if ($log) { -- cgit v1.2.3-54-g00ecf From e955c7d36c794056fd777398ac37c466cde8ddc3 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 20 Mar 2018 11:52:06 +0100 Subject: web-scripts/statistics.php: make legend nice(r) again --- web-scripts/statistics.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'web-scripts/statistics.php') diff --git a/web-scripts/statistics.php b/web-scripts/statistics.php index 1e4d89b..41b205f 100644 --- a/web-scripts/statistics.php +++ b/web-scripts/statistics.php @@ -51,7 +51,7 @@ $width = 1600; $height = 600; $border = 5; $legend_line_length = 10; -$legend_height = 3 * ImageFontHeight(5) + $legend_line_length; +$legend_height = 4 * ImageFontHeight(5) + $legend_line_length; $im = @ImageCreate ($width + $legend_line_length + $max_len * ImageFontWidth(5), $height + $legend_height) or die ("Cannot create new gd-image-stream"); @@ -118,13 +118,13 @@ function print_graph($data, $color) { ImageRectangle($im, $legend_line_length, 0, $width-1+$legend_line_length, $height-1, $foreground_color); -ImageString($im, 5, $legend_line_length, $height + $legend_line_length + 2*ImageFontHeight(5), "( ".trim(shell_exec("uptime | sed 's|^.*\\s\\(load\\)|\\1|'"))." )", $foreground_color); +ImageString($im, 5, $legend_line_length, $height + 2*$legend_line_length + 2*ImageFontHeight(5), "( ".trim(shell_exec("uptime | sed 's|^.*\\s\\(load\\)|\\1|'"))." )", $foreground_color); $xpos = $legend_line_length; foreach ($print_columns as $column) { print_graph($values[$column], $colors[$column]); - ImageString($im, 5, $xpos, $height + $legend_line_length + ImageFontHeight(5), $column, $colors[$column]); - $xpos += (strlen($column) + 1.75) * ImageFontWidth(5); + ImageString($im, 5, $xpos, $height + $legend_line_length + ImageFontHeight(5), substr($column,0,-strlen("_count")), $colors[$column]); + $xpos += (strlen($column) - strlen("_count") + 1.75) * ImageFontWidth(5); } ImageString($im, 5, $legend_line_length, $height + $legend_line_length, date('Y-m-d H:i', $t_min), $foreground_color); -- cgit v1.2.3-54-g00ecf From 301b04263a7d6343704b35bfd68961d536772daf Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 20 Mar 2018 12:02:57 +0100 Subject: web-scripts/statistics.php: remove obsolete comment --- web-scripts/statistics.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'web-scripts/statistics.php') diff --git a/web-scripts/statistics.php b/web-scripts/statistics.php index 41b205f..01bbb52 100644 --- a/web-scripts/statistics.php +++ b/web-scripts/statistics.php @@ -164,6 +164,4 @@ header ("Content-type: image/png"); ImagePNG ($im); -// passthru('wc -l /srv/http/statistics'); - ?> -- cgit v1.2.3-54-g00ecf From 6f7e155ea0dd7f0e5894ec133be313bbdb4589ba Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Fri, 23 Mar 2018 09:14:32 +0100 Subject: web-scripts/statistics.php: add option to chose time axis differently --- web-scripts/statistics.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'web-scripts/statistics.php') diff --git a/web-scripts/statistics.php b/web-scripts/statistics.php index 01bbb52..c919f93 100644 --- a/web-scripts/statistics.php +++ b/web-scripts/statistics.php @@ -1,5 +1,10 @@ connect_error) { die("Connection failed: " . $mysql->connect_error); @@ -19,7 +24,7 @@ if (! $result = $mysql -> query( "`statistics`.`blocked_tasks_count`," . "`statistics`.`next_tasks_count`" . "FROM `statistics` " . - "WHERE `statistics`.`date`>=ADDTIME(NOW(),\"-7 00:00:00\") " . + "WHERE `statistics`.`date`>=ADDTIME(NOW()," . $min_time . ") " . "ORDER BY `statistics`.`date`" )) die($mysql->error); -- cgit v1.2.3-54-g00ecf