From: Marcin Haba Date: Mon, 6 Feb 2023 14:53:44 +0000 (+0100) Subject: baculum: Add to estimated job values endpoint average number of backed up objects X-Git-Tag: Release-13.0.3~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a57f62d5a7df3c943b35d0f3639c65dbb53608b;p=thirdparty%2Fbacula.git baculum: Add to estimated job values endpoint average number of backed up objects --- diff --git a/gui/baculum/protected/API/Modules/JobManager.php b/gui/baculum/protected/API/Modules/JobManager.php index a624d8898..271527a0d 100644 --- a/gui/baculum/protected/API/Modules/JobManager.php +++ b/gui/baculum/protected/API/Modules/JobManager.php @@ -539,6 +539,7 @@ WHERE Client.ClientId='$clientid' $wh"; $result = $sth->fetch(PDO::FETCH_ASSOC); $duration = $this->getJobHistoryDuration($job, $level); $success = $this->getJobHistorySuccessPercent($job); + $objects = $this->getJobHistoryAverageObjects($job, $level); return [ 'bytes_est' => (int) ($result['jobbytes'] ?? '0'), 'bytes_corr' => (float) $result['corr_jobbytes'], @@ -546,6 +547,7 @@ WHERE Client.ClientId='$clientid' $wh"; 'files_corr' => (float) $result['corr_jobfiles'], 'job_count' => (int) $result['nb_jobs'], 'avg_duration' => (int) ($duration['duration'] ?? '0'), + 'avg_objects' => (int) ($objects['objects'] ?? '0'), 'success_perc' => (int) ($success['success'] ?? '0') ]; } @@ -556,6 +558,7 @@ WHERE Client.ClientId='$clientid' $wh"; * all job statuses. * * @param string $job job name + * @param string $level backup job level * @return array|bool average job duration or false if no job found */ public function getJobHistoryDuration($job, $level) { @@ -597,5 +600,29 @@ WHERE Client.ClientId='$clientid' $wh"; $sth = $pdo->query($sql); return $sth->fetch(PDO::FETCH_ASSOC); } + + /** + * Get average value of objects backed up by job. + * + * @param string $job job name + * @param string $level backup job level + * @return array|bool average backed up by job object number or false + * if no job found + */ + public function getJobHistoryAverageObjects($job, $level) { + $sql = 'SELECT AVG(f.counter) AS objects FROM ( + SELECT Object.JobId AS jobid, + COUNT(1) AS counter + FROM Object + LEFT JOIN Job USING (JobId) + WHERE Job.Name=\'' . $job . '\' AND Job.Level=\'' . $level . '\' AND Job.JobStatus=\'T\' + GROUP BY Object.JobId + ) AS f'; + $connection = JobRecord::finder()->getDbConnection(); + $connection->setActive(true); + $pdo = $connection->getPdoInstance(); + $sth = $pdo->query($sql); + return $sth->fetch(PDO::FETCH_ASSOC); + } } ?> diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 5ed14e62c..75858b712 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -1766,7 +1766,11 @@ }, "avg_duration": { "type": "integer", - "description": "Average job duration based on historical job time values. NOTE: it takes into account all finished jobs for given job name and level." + "description": "Average job duration in seconds based on historical job time values. NOTE: it takes into account all finished jobs for given job name and level." + }, + "avg_objects": { + "type": "integer", + "description": "Average number of objects for job based on historical job values. NOTE: it takes into account all successfully finished jobs for given job name and level." }, "success_perc": { "type": "integer",