From cd989f9c3aff968e19a3aeabc4eb9085787a6673 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:43:12 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- .../Web/Widget/BackgroundDaemonDetails.php | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 library/Director/Web/Widget/BackgroundDaemonDetails.php (limited to 'library/Director/Web/Widget/BackgroundDaemonDetails.php') diff --git a/library/Director/Web/Widget/BackgroundDaemonDetails.php b/library/Director/Web/Widget/BackgroundDaemonDetails.php new file mode 100644 index 0000000..b4c33dd --- /dev/null +++ b/library/Director/Web/Widget/BackgroundDaemonDetails.php @@ -0,0 +1,131 @@ +info = $info; + $this->daemon = $daemon; + } + + protected function assemble() + { + $info = $this->info; + if ($info->hasBeenStopped()) { + $this->add(Hint::error(Html::sprintf( + $this->translate( + 'Daemon has been stopped %s, was running with PID %s as %s@%s' + ), + // $info->getHexUuid(), + $this->timeAgo($info->getTimestampStopped() / 1000), + Html::tag('strong', (string) $info->getPid()), + Html::tag('strong', $info->getUsername()), + Html::tag('strong', $info->getFqdn()) + ))); + } elseif ($info->isOutdated()) { + $this->add(Hint::error(Html::sprintf( + $this->translate( + 'Daemon keep-alive is outdated, was last seen running with PID %s as %s@%s %s' + ), + // $info->getHexUuid(), + Html::tag('strong', (string) $info->getPid()), + Html::tag('strong', $info->getUsername()), + Html::tag('strong', $info->getFqdn()), + $this->timeAgo($info->getLastUpdate() / 1000) + ))); + } else { + $this->add(Hint::ok(Html::sprintf( + $this->translate( + 'Daemon is running with PID %s as %s@%s, last refresh happened %s' + ), + // $info->getHexUuid(), + Html::tag('strong', (string)$info->getPid()), + Html::tag('strong', $info->getUsername()), + Html::tag('strong', $info->getFqdn()), + $this->timeAgo($info->getLastUpdate() / 1000) + ))); + $details = new NameValueTable(); + $details->addNameValuePairs([ + $this->translate('Startup Time') => DateFormatter::formatDateTime($info->getTimestampStarted() / 1000), + $this->translate('PID') => $info->getPid(), + $this->translate('Username') => $info->getUsername(), + $this->translate('FQDN') => $info->getFqdn(), + $this->translate('Running with systemd') => $info->isRunningWithSystemd() + ? $this->translate('yes') + : $this->translate('no'), + $this->translate('Binary') => $info->getBinaryPath() + . ($info->binaryRealpathDiffers() ? ' -> ' . $info->getBinaryRealpath() : ''), + $this->translate('PHP Binary') => $info->getPhpBinaryPath() + . ($info->phpBinaryRealpathDiffers() ? ' -> ' . $info->getPhpBinaryRealpath() : ''), + $this->translate('PHP Version') => $info->getPhpVersion(), + $this->translate('PHP Integer') => $info->has64bitIntegers() + ? '64bit' + : Html::sprintf( + '%sbit (%s)', + $info->getPhpIntegerSize() * 8, + Html::tag('span', ['class' => 'error'], $this->translate('unsupported')) + ), + ]); + $this->add($details); + + $this->add(Html::tag('h2', $this->translate('Process List'))); + if (\is_string($this->daemon->process_info)) { + // from DB: + $processes = \json_decode($this->daemon->process_info); + } else { + // via RPC: + $processes = $this->daemon->process_info; + } + $table = new Table(); + $table->add(Html::tag('thead', Html::tag('tr', Html::wrapEach([ + 'PID', + 'Command', + 'Memory' + ], 'th')))); + $table->setAttribute('class', 'common-table'); + foreach ($processes as $pid => $process) { + $table->add($table::row([ + [ + Icon::create($process->running ? 'ok' : 'warning-empty'), + ' ', + $pid + ], + Html::tag('pre', $process->command), + $process->memory === false ? 'n/a' : Format::bytes($process->memory->rss) + ])); + } + $this->add($table); + } + } + + protected function timeAgo($time) + { + return Html::tag('span', [ + 'class' => 'time-ago', + 'title' => DateFormatter::formatDateTime($time) + ], DateFormatter::timeAgo($time)); + } +} -- cgit v1.2.3