|
7 | 7 | use App\Entity\Judgehost;
|
8 | 8 | use App\Entity\JudgeTask;
|
9 | 9 | use App\Entity\Judging;
|
| 10 | +use App\Entity\JudgingRun; |
10 | 11 | use App\Form\Type\JudgehostsType;
|
11 | 12 | use App\Service\ConfigurationService;
|
12 | 13 | use App\Service\DOMJudgeService;
|
@@ -57,6 +58,7 @@ public function indexAction(Request $request): Response
|
57 | 58 | 'hostname' => ['title' => 'hostname'],
|
58 | 59 | 'enabled' => ['title' => 'enabled'],
|
59 | 60 | 'status' => ['title' => 'status'],
|
| 61 | + 'load' => ['title' => 'load (1m/5m/15m/60m)'], |
60 | 62 | 'last_judgingid' => ['title' => 'last judging'],
|
61 | 63 | ];
|
62 | 64 |
|
@@ -117,6 +119,44 @@ public function indexAction(Request $request): Response
|
117 | 119 | 'value' => 'j' . $lastJobId['jobid'],
|
118 | 120 | ];
|
119 | 121 |
|
| 122 | + $now = Utils::now(); |
| 123 | + $timings = $this->em->createQueryBuilder() |
| 124 | + ->from(JudgeTask::class, 'jt') |
| 125 | + ->join(JudgingRun::class, 'jr', 'WITH', 'jr.judgetask = jt') |
| 126 | + ->join('jr.judging', 'j') |
| 127 | + ->join('jt.judgehost', 'jh') |
| 128 | + ->select('jr.endtime, jr.startTime') |
| 129 | + ->andWhere('jt.judgehost = :judgehost') |
| 130 | + ->andWhere('jr.startTime IS NOT NULL') |
| 131 | + ->andWhere('jr.endtime IS NOT NULL') |
| 132 | + ->andWhere('jr.endtime >= :one_hour_ago') |
| 133 | + ->setParameter('one_hour_ago', $now - 3600) |
| 134 | + ->setParameter('judgehost', $judgehost) |
| 135 | + ->getQuery() |
| 136 | + ->getResult(); |
| 137 | + $loads = [0.0, 0.0, 0.0, 0.0]; |
| 138 | + $loadMinutes = [$now - 60*1, $now - 60*5, $now - 60*15, $now - 60*60]; |
| 139 | + foreach ($timings as $timing) { |
| 140 | + for ($i = 0; $i < 4; $i++) { |
| 141 | + $start_time = $timing['startTime']; |
| 142 | + $end_time = $timing['endtime']; |
| 143 | + $start_time = max($start_time, $loadMinutes[$i]); |
| 144 | + if ($start_time < $end_time) { |
| 145 | + $loads[$i] += ($end_time - $start_time); |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + // Normalize to [0,1] range. |
| 150 | + $loads[0] = min(1.0, $loads[0] / (60.0 * 1.0)); |
| 151 | + $loads[1] = min(1.0, $loads[1] / (60.0 * 5.0)); |
| 152 | + $loads[2] = min(1.0, $loads[2] / (60.0 * 15.0)); |
| 153 | + $loads[3] = min(1.0, $loads[3] / (60.0 * 60.0)); |
| 154 | + $judgehostdata['load'] = [ |
| 155 | + 'value' => sprintf('%.2f / %.2f / %.2f / %.2f', $loads[0], $loads[1], $loads[2], $loads[3]), |
| 156 | + 'title' => 'estimated load (1m/5m/15m/60m)', |
| 157 | + 'cssclass' => 'text-monospace', |
| 158 | + ]; |
| 159 | + |
120 | 160 | $judgehostdata = array_merge($judgehostdata, [
|
121 | 161 | 'status' => [
|
122 | 162 | 'value' => $status,
|
|
0 commit comments