Skip to content

Commit

Permalink
Restore and refresh monitor.php
Browse files Browse the repository at this point in the history
  • Loading branch information
zackgalbreath committed May 18, 2023
1 parent 06d5d0c commit 3af0ba7
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 278 deletions.
283 changes: 10 additions & 273 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AdminController extends AbstractController
{
public function viewUpdate(): View
{
return view("build.update");
return view('build.update');
}

public function viewUpdatePageContent(): JsonResponse
Expand Down Expand Up @@ -1426,16 +1426,15 @@ public function monitor(): View
{
$user = Auth::user();
if ($user->admin) {
$content = $this->monitor_currently_processing_submissions();
$content .= $this->monitor_pending_submissions();
$content .= $this->monitor_average_wait_times();
$content .= $this->monitor_submissionprocessor_table();
$content .= $this->monitor_submission_table();
return view('cdash', [
'xsl' => true,
'xsl_content' => $content,
'title' => 'System Monitor'
]);
if (config('queue.default') === 'database') {
return view('admin.monitor');
} else {
return view('cdash', [
'xsl' => true,
'xsl_content' => 'System Monitor only available when QUEUE_CONNECTION=database',
'title' => 'System Monitor'
]);
}
} else {
return view('cdash', [
'xsl' => true,
Expand All @@ -1445,268 +1444,6 @@ public function monitor(): View
}
}

// TODO: (williamjallen) Convert this function into a Blade template and move extra logic to monitor()
private function monitor_currently_processing_submissions(): string
{
$db = Database::getInstance();

if (config('database.default') == 'pgsql') {
$sql_query = "SELECT now() AT TIME ZONE 'UTC'";
} else {
$sql_query = 'SELECT UTC_TIMESTAMP()';
}
$current_time = $db->executePreparedSingleRow($sql_query);

$sql_query = 'SELECT project.name, submission.*, ';
if (config('database.default') == 'pgsql') {
$sql_query .= 'round((extract(EPOCH FROM now() - created)/3600)::numeric, 2) AS hours_ago ';
} else {
$sql_query .= 'ROUND(TIMESTAMPDIFF(SECOND, created, UTC_TIMESTAMP)/3600, 2) AS hours_ago ';
}

$sql_query .= 'FROM project, submission WHERE project.id = submission.projectid AND status = 1';
$rows = $db->executePrepared($sql_query);

$sep = ', ';

$html = '<h1>Currently Processing Submissions as of ' . $current_time[0] . ' UTC</h1>';
$html .= '<pre>';
if (count($rows) > 0) {
$html .= 'project name, backlog in hours' . "\n";
$html .= ' submission.id, filename, projectid, status, attempts, filesize, filemd5sum, lastupdated, created, started, finished' . "\n";
$html .= "\n";
foreach ($rows as $row) {
$html .= $row['name'] . $sep . $row['hours_ago'] . ' hours behind' . "\n";
$html .= ' ' . $row['id'] .
$sep . $row['filename'] .
$sep . $row['projectid'] .
$sep . $row['status'] .
$sep . $row['attempts'] .
$sep . $row['filesize'] .
$sep . $row['filemd5sum'] .
$sep . $row['lastupdated'] .
$sep . $row['created'] .
$sep . $row['started'] .
$sep . $row['finished'] .
"\n";
$html .= "\n";
}
} else {
$html .= 'Nothing is currently processing...' . "\n";
}
$html .= '</pre>';
$html .= '<br/>';

return $html;
}

// TODO: (williamjallen) Convert this function into a Blade template and move extra logic to monitor()
private function monitor_pending_submissions(): string
{
$db = Database::getInstance();
$rows = $db->executePrepared('
SELECT project.name, project.id, COUNT(submission.id) AS c
FROM project, submission
WHERE
project.id = submission.projectid
AND status = 0
GROUP BY project.name, project.id
');

$sep = ', ';

$html = '<h1>Pending Submissions</h1>';
$html .= '<pre>';
if (count($rows) > 0) {
$html .= 'project.name, project.id, count of pending queued submissions' . "\n";
$html .= "\n";
foreach ($rows as $row) {
$html .= $row['name'] .
$sep . $row['id'] .
$sep . $row['c'] .
"\n";
}
} else {
$html .= 'Nothing queued...' . "\n";
}
$html .= '</pre>';
$html .= '<br/>';

return $html;
}

// TODO: (williamjallen) Convert this function into a Blade template and move extra logic to monitor()
private function monitor_average_wait_time(int $projectid): string
{
$project_name = get_project_name($projectid);
if (config('database.default') == 'pgsql') {
$sql_query = "SELECT extract(EPOCH FROM now() - created)/3600 as hours_ago,
current_time AS time_local,
count(created) AS num_files,
round(avg((extract(EPOCH FROM started - created)/3600)::numeric), 1) AS avg_hours_delay,
avg(extract(EPOCH FROM finished - started)) AS mean,
min(extract(EPOCH FROM finished - started)) AS shortest,
max(extract(EPOCH FROM finished - started)) AS longest
FROM submission WHERE status = 2 AND projectid = ?
GROUP BY hours_ago ORDER BY hours_ago ASC LIMIT 48";
} else {
$sql_query = "SELECT TIMESTAMPDIFF(HOUR, created, UTC_TIMESTAMP) as hours_ago,
TIME_FORMAT(CONVERT_TZ(created, '+00:00', 'SYSTEM'), '%l:00 %p') AS time_local,
COUNT(created) AS num_files,
ROUND(AVG(TIMESTAMPDIFF(SECOND, created, started))/3600, 1) AS avg_hours_delay,
AVG(TIMESTAMPDIFF(SECOND, started, finished)) AS mean,
MIN(TIMESTAMPDIFF(SECOND, started, finished)) AS shortest,
MAX(TIMESTAMPDIFF(SECOND, started, finished)) AS longest
FROM submission WHERE status = 2 AND projectid = ?
GROUP BY hours_ago ORDER BY hours_ago ASC LIMIT 48";
}

$db = Database::getInstance();
$rows = $db->executePrepared($sql_query, [intval($projectid)]);

$html = '';
if (count($rows) > 0) {
$html .= "<h2>Wait times for $project_name</h2>\n";
$html .= "<table border=1>\n";
$html .= "<tr>\n";
$html .= "<th>Hours Ago</th>\n";
$html .= "<th>Local Time</th>\n";
$html .= "<th>Files Processed Successfully</th>\n";
$html .= "<th>Avg Hours Spent Queued Before Processing</th>\n";
$html .= "<th>Avg Seconds Spent Processing a File</th>\n";
$html .= "<th>Min Seconds Spent Processing a File</th>\n";
$html .= "<th>Max Seconds Spent Processing a File</th>\n";
$html .= "</tr>\n";
foreach ($rows as $row) {
$html .= "<tr>\n";
$html .= "<td style='text-align:center'>{$row['hours_ago']}</td>\n";
$html .= "<td style='text-align:center'>{$row['time_local']}</td>\n";
$html .= "<td style='text-align:center'>{$row['num_files']}</td>\n";
$html .= "<td style='text-align:center'>{$row['avg_hours_delay']}</td>\n";
$html .= "<td style='text-align:center'>{$row['mean']}</td>\n";
$html .= "<td style='text-align:center'>{$row['shortest']}</td>\n";
$html .= "<td style='text-align:center'>{$row['longest']}</td>\n";
$html .= "</tr>\n";
}
$html .= "</table>\n";
} else {
$html .= "<h2>No average wait time data for $project_name</h2>\n";
}

return $html;
}

// TODO: (williamjallen) Convert this function into a Blade template and move extra logic to monitor()
private function monitor_average_wait_times(): string
{
$db = Database::getInstance();
$rows = $db->executePrepared('
SELECT projectid, COUNT(*) AS c
FROM submission
WHERE status=2
GROUP BY projectid
');

$html = '<h1>Average Wait Times per Project</h1>';
if (count($rows) > 0) {
foreach ($rows as $row) {
if ($row['c'] > 0) {
$this->monitor_average_wait_time(intval($row['projectid']));
}
}
} else {
$html .= 'No finished submissions for average wait time measurement...' . "\n";
}
$html .= '<br/>';

return $html;
}

// TODO: (williamjallen) Convert this function into a Blade template and move extra logic to monitor()
private function monitor_submissionprocessor_table(): string
{
$db = Database::getInstance();
$rows = $db->executePrepared('
SELECT project.name, submissionprocessor.*
FROM project, submissionprocessor
WHERE project.id = submissionprocessor.projectid
');

$html = '<h1>Table `submissionprocessor` (one row per project)</h1>';
$html .= "<table border=1>\n";
$html .= "<tr>\n";
$html .= "<th>Project Name</th>\n";
$html .= "<th>Project ID</th>\n";
$html .= "<th>Process ID</th>\n";
$html .= "<th>Last Updated</th>\n";
$html .= "<th>Locked</th>\n";
$html .= "</tr>\n";
foreach ($rows as $row) {
$html .= "<tr>\n";
$html .= "<td style='text-align:center'>{$row['name']}</td>\n";
$html .= "<td style='text-align:center'>{$row['projectid']}</td>\n";
$html .= "<td style='text-align:center'>{$row['pid']}</td>\n";
$html .= "<td style='text-align:center'>{$row['lastupdated']}</td>\n";
$html .= "<td style='text-align:center'>{$row['locked']}</td>\n";
$html .= "</tr>\n";
}
$html .= "</table>\n";
$html .= '<br/>';

return $html;
}

// TODO: (williamjallen) Convert this function into a Blade template and move extra logic to monitor()
private function monitor_submission_table(): string
{
@$limit = $_REQUEST['limit'];
if (!isset($limit)) {
$limit = 25;
} else {
$limit = intval($limit);
}

$html = "<h1>Table `submission` (most recently queued $limit)</h1>";
$html .= "<table border=1>\n";
$html .= "<tr>\n";
$html .= "<th>id</th>\n";
$html .= "<th>filename</th>\n";
$html .= "<th>projectid</th>\n";
$html .= "<th>status</th>\n";
$html .= "<th>attempts</th>\n";
$html .= "<th>filesize</th>\n";
$html .= "<th>filemd5sum</th>\n";
$html .= "<th>lastupdated</th>\n";
$html .= "<th>created</th>\n";
$html .= "<th>started</th>\n";
$html .= "<th>finished</th>\n";
$html .= "</tr>\n";

$db = Database::getInstance();
$rows = $db->executePrepared('SELECT * FROM submission ORDER BY id DESC LIMIT ?', [$limit]);


foreach ($rows as $row) {
$html .= "<tr>\n";
$html .= "<td style='text-align:center'>{$row['id']}</td>\n";
$html .= "<td style='text-align:center'>{$row['filename']}</td>\n";
$html .= "<td style='text-align:center'>{$row['projectid']}</td>\n";
$html .= "<td style='text-align:center'>{$row['status']}</td>\n";
$html .= "<td style='text-align:center'>{$row['attempts']}</td>\n";
$html .= "<td style='text-align:center'>{$row['filesize']}</td>\n";
$html .= "<td style='text-align:center'>{$row['filemd5sum']}</td>\n";
$html .= "<td style='text-align:center'>{$row['lastupdated']}</td>\n";
$html .= "<td style='text-align:center'>{$row['created']}</td>\n";
$html .= "<td style='text-align:center'>{$row['started']}</td>\n";
$html .= "<td style='text-align:center'>{$row['finished']}</td>\n";
$html .= "</tr>\n";
}
$html .= "</table>\n";
$html .= "<br/>\n";

return $html;
}

public function gitinfo(): View
{
$user = Auth::user();
Expand Down
Loading

0 comments on commit 3af0ba7

Please sign in to comment.