<?php

$rv = $this->runtimeVariables()->create($this->runtimevariables);
$cp = $this->checkPerformance()->create($this->checkperformance);

?>
<div class="controls">
    <?= $this->tabs ?>
</div>

<div class="content processinfo">
    <div class="boxview">

        <div class="box left">
            <h2><?= $this->translate('Feature Commands') ?></h2>
            <?= $this->toggleFeaturesForm ?>
        </div>

        <div class="box left">
            <h2><?= $this->translate('Process Info') ?></h2>
            <table class="avp">
                <tbody>
                <tr>
                    <th><?= $this->translate('Program Start Time') ?></th>
                    <td><?= $this->dateFormat()->formatDateTime($this->programStatus->program_start_time) ?></td>
                </tr>
                <tr>
                    <th><?= $this->translate('Last Status Update'); ?></th>
                    <td><?= $this->timeSince($this->programStatus->status_update_time) ?> ago</td>
                </tr>
                <tr>
                    <th><?= $this->translate('Last External Command Check'); ?></th>
                    <td><?= $this->timeSince($this->programStatus->last_command_check) ?> ago</td>
                </tr>
                <tr>
                    <th><?= $this->translate('Last Log File Rotation'); ?></th>
                    <td><?= $this->programStatus->last_log_rotation
                            ? $this->timeSince($this->programStatus->last_log_rotation)
                            : $this->translate('N/A') ?></td>
                </tr>
                <tr>
                    <th><?= $this->translate('Global Service Event Handler'); ?></th>
                    <td><?= $this->programStatus->global_service_event_handler
                            ? $this->programStatus->global_service_event_handler
                            : $this->translate('N/A'); ?></td>
                </tr>
                <tr>
                    <th><?= $this->translate('Global Host Event Handler'); ?></th>
                    <td><?= $this->programStatus->global_host_event_handler
                            ? $this->programStatus->global_host_event_handler
                            : $this->translate('N/A'); ?></td>
                </tr>
                </tbody>
            </table>
            <?php if ((bool) $this->programStatus->is_currently_running === true): ?>
                <div class="backend-running">
                    <?= sprintf(
                        $this->translate('%s has been up and running with PID %d since %s'),
                        $this->backendName,
                        $this->programStatus->process_id,
                        $this->timeSince($this->programStatus->program_start_time)) ?>
                </div>
            <?php else: ?>
                <div class="backend-not-running">
                    <?= sprintf($this->translate('%s is not running'), $this->backendName) ?>
                </div>
            <?php endif ?>
        </div>

        <div class="box left">
            <h2><?= $this->translate('Performance Info') ?></h2>

            <h3><?= $this->translate('Object summaries') ?></h3>
            <table class="avp">
                <thead>
                <tr>
                    <th></th>
                    <th><?= $this->translate('overall') ?></th>
                    <th><?= $this->translate('scheduled') ?></th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>
                        <strong><?= $this->translate('Hosts') ?></strong>
                    </td>
                    <td>
                        <?= $rv->total_hosts; ?>
                    </td>
                    <td>
                        <?= $rv->total_scheduled_hosts; ?>
                    </td>
                </tr>

                <tr>
                    <td>
                        <strong><?= $this->translate('Services') ?></strong>
                    </td>
                    <td>
                        <?= $rv->total_services; ?>
                    </td>
                    <td>
                        <?= $rv->total_scheduled_services; ?>
                    </td>
                </tr>

                <tr>
                    <td>
                        <strong><?= $this->translate('Average services per host') ?></strong>
                    </td>
                    <td>
                        <?= sprintf('%.2f', $rv->average_services_per_host); ?>
                    </td>
                    <td>
                        <?= sprintf('%.2f', $rv->average_scheduled_services_per_host); ?>
                    </td>
                </tr>
                </tbody>
            </table>

            <h3><?= $this->translate('Active checks') ?></h3>
            <table class="avp">
                <thead>
                <tr>
                    <th></th>
                    <th></th>
                    <th><?= $this->translate('Latency') ?></th>
                    <th><?= $this->translate('Execution time') ?></th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>
                        <strong><?= $this->translate('Host Checks') ?></strong>
                    </td>
                    <td><?= $cp->host_active_count; ?></td>
                    <td><?= sprintf('%.3f', $cp->host_active_latency_avg); ?>s</td>
                    <td><?= sprintf('%.3f', $cp->host_active_execution_avg); ?>s</td>
                </tr>
                <tr>
                    <td>
                        <strong><?= $this->translate('Service Checks') ?></strong>
                    </td>
                    <td><?= $cp->service_active_count; ?></td>
                    <td><?= sprintf('%.3f', $cp->service_active_latency_avg); ?>s</td>
                    <td><?= sprintf('%.3f', $cp->service_active_execution_avg); ?>s</td>
                </tr>
                </tbody>
            </table>

            <h3><?= $this->translate('Passive checks') ?></h3>
            <table class="avp">
                <tbody>
                <tr>
                    <td>
                        <strong><?= $this->translate('Host Checks') ?></strong>
                    </td>
                    <td><?= $cp->host_passive_count; ?></td>
                </tr>
                <tr>
                    <td>
                        <strong><?= $this->translate('Service Checks') ?></strong>
                    </td>
                    <td><?= $cp->service_passive_count; ?></td>
                </tr>
                </tbody>
            </table>
        </div>

    </div>
</div>
