Plugin Directory

Changeset 3492583


Ignore:
Timestamp:
03/27/2026 11:17:42 AM (22 hours ago)
Author:
bastho
Message:

Add CPU utilization

Location:
ressources/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ressources/trunk/ressources.css

    r3492522 r3492583  
    2727}
    2828
     29#ressources_cpu .cpu-ships{
     30    display: inline-flex;
     31    flex-wrap: wrap;
     32    gap: 2px;
     33}
     34#ressources_cpu .cpu-ship{
     35    background: linear-gradient(90deg, var(--wp-admin-theme-color), var(--wp-admin-theme-color-darker-10) 100%);
     36    width: 10px;
     37    height: 10px;
     38    cursor: progress;
     39}
     40
    2941#ressources_memory .inside,
    3042#ressources_disk .inside,
  • ressources/trunk/ressources.php

    r3492532 r3492583  
    175175                <th><?php esc_attr_e('TIME', 'ressources') ?></th>
    176176                <th><?php esc_attr_e('CPU Load average', 'ressources') ?></th>
     177                <th><?php esc_attr_e('Utilization', 'ressources') ?></th>
    177178            </tr>
    178179            </thead>
    179             <tbody class="ressources-widget-content" data-id="cpu" data-refresh="20">
     180            <tbody class="ressources-widget-content" data-id="cpu" data-refresh="5">
    180181            </tbody>
    181182        </table>
     
    284285        // PHPCS:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec
    285286        exec('cat /proc/loadavg', $cpuloadavg);
     287        // PHPCS:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec
     288        exec('grep "^model name" /proc/cpuinfo', $model);
     289        $count = count($model);
     290        // get load of each CPU core
     291        $cpus_load = array();
     292        for($i=0; $i<$count; $i++){
     293            // PHPCS:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec
     294            exec('cat /proc/stat | grep "^cpu'.$i.'"', $cpus_load[$i]);
     295        }
    286296        if($cpuloadavg){
    287297            $load = explode(' ',$cpuloadavg[0]);
    288298            ?>
    289299            <tr>
    290             <td>1 MIN</td>
    291             <td><?php echo esc_html( $load[0] ) ?></td>
    292             </tr>
    293             <tr>
    294             <td>5 MIN</td>
    295             <td><?php echo esc_html( $load[1] ) ?></td>
    296             </tr>
    297             <tr>
    298             <td>15 MIN</td>
    299             <td><?php echo esc_html( $load[2] ) ?></td>
     300                <td>1 MIN</td>
     301                <td><?php echo esc_html( $load[0] ) ?></td>
     302                <td>
     303                    <div class="cpu-ships">
     304                        <?php foreach($cpus_load as $cpu => $cpu_load): ?>
     305                            <?php
     306                                $data = explode(' ',$cpu_load[0]);
     307                                $total = array_sum(array_slice($data, 1));
     308                                $idle = $data[4];
     309                                $usage = 100 - round($idle / $total * 100);
     310                            // translators: %1$d is the CPU index, %2$d is the CPU usage percentage ?>
     311                        <div class="cpu-ship" style="opacity:<?php echo esc_attr( $usage/100 ) ?>;" title="<?php echo esc_attr( sprintf('CPU %1$d: %2$d%% load', $cpu+1, $usage) ) ?>">
     312                        </div>
     313                    <?php endforeach; ?>
     314                    </div>
     315                </td>
     316            </tr>
     317            <tr>
     318                <td>5 MIN</td>
     319                <td><?php echo esc_html( $load[1] ) ?></td>
     320            </tr>
     321            <tr>
     322                <td>15 MIN</td>
     323                <td><?php echo esc_html( $load[2] ) ?></td>
    300324            </tr>
    301325            <?php
    302326        }
    303327    }
     328
    304329    function getMySQLVersion() {
    305330        // PHPCS:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec
Note: See TracChangeset for help on using the changeset viewer.